Hi, I am calling the /oauth/token endpoint and successfully being returned an access token and I have verified it on jwt.io. I immediately then use that token in a GET request for user data but that request returns an invalid token error. Below is my implementation:
async function getAuthToken() {
try {
const res = await fetch(
`${process.env.AUTH0_ISSUER_BASE_URL}/oauth/token`,
{
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
client_id: process.env.AUTH0_CLIENT_ID,
client_secret: process.env.AUTH0_CLIENT_SECRET,
audience: process.env.AUTH0_AUDIENCE,
grant_type: 'client_credentials',
}),
}
);
return await res.json();
} catch (e) {
console.error(e);
}
}
export async function getUserAppMeta(auth0UserId) {
const { access_token } = await getAuthToken();
try {
const res = await fetch(
`${process.env.AUTH0_DEV_ENDPOINT}/users/${auth0UserId}`,
{
method: 'GET',
headers: {
Authorization: `Bearer ${access_token}`,
'Content-Type': 'application/json',
},
}
);
return await res.json();
} catch (e) {
console.error(e);
}
}
Am I doing something obviously incorrect? Any advise is appreciated.