Get authenticated user with client credentials
This example demonstrates how to get the authenticated user using the client credentials flow with different libraries and languages.
How it works
- The application sends a request to obtain an access token using its client ID and client secret.
- Once the token is received, it is included in the request headers for authentication.
- The API responds with the authenticated user data.
Examples
- Axios (JavaScript)
- Requests (Python)
- cURL (Bash)
import axios from 'axios';
const clientId = 'YOUR_CLIENT_ID';
const clientSecret = 'YOUR_CLIENT_SECRET';
axios.post('https://miwa.lol/api/oauth2/token', {
grant_type: 'client_credentials',
client_id: clientId,
client_secret: clientSecret,
}).then((response) => {
const accessToken = response.data.access_token;
axios.get('https://miwa.lol/api/user', {
headers: { Authorization: `Bearer ${accessToken}` },
}).then((response) => {
console.log(response.data);
});
});
import requests
client_id = 'YOUR_CLIENT_ID'
client_secret = 'YOUR_CLIENT_SECRET'
response = requests.post('https://miwa.lol/api/oauth2/token', json={
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
})
response.raise_for_status()
access_token = response.json()['access_token']
response = requests.get('https://miwa.lol/api/user', headers={
'Authorization': f'Bearer {access_token}',
})
response.raise_for_status()
print(response.json())
note
Ensure you have jq
installed to parse the JSON response.
CLIENT_ID='YOUR_CLIENT_ID'
CLIENT_SECRET='YOUR_CLIENT_SECRET'
ACCESS_TOKEN=$(curl -s -X POST https://miwa.lol/api/oauth2/token \
-d "grant_type=client_credentials" \
-d "client_id=$CLIENT_ID" \
-d "client_secret=$CLIENT_SECRET" | jq -r '.access_token')
curl -s -X GET https://miwa.lol/api/user \
-H "Authorization: Bearer $ACCESS_TOKEN" | jq