Working off this question
How did you actually get the access token of the user in an action? I am running into the same issue, and the code I’m using with the management API isn’t working.
Here it is.
try {
const auth0Domain = 'MY AUTH0 DOMAIN';
const auth0ManagementApiClientId = event.secrets.CLIENT_ID
const auth0ManagementApiClientSecret = event.secrets.CLIENT_SECRET
const userId = event.user.user_id;
const response = await axios.post(
`https://${auth0Domain}/oauth/token`,
{
grant_type: 'client_credentials',
client_id: auth0ManagementApiClientId,
client_secret: auth0ManagementApiClientSecret,
audience: `https://${auth0Domain}/api/v2/`,
}
);
const managementToken = response.data.access_token;
let domain = `https://${auth0Domain}/api/v2/users/${userId}`
const userResponse = await axios.get(
domain,
{
headers: {
Authorization: `Bearer ${managementToken}`,
},
}
);
let userAccessToken = userResponse.data.identities[0].access_token
console.log('user response: ', userResponse.data)
} catch (error) {
// Handle error response
console.error('Error retrieving access token:', error);
}
This code is succesful in getting A access token, but it’s not the same as the users, which I’ve verified by manually printing out the access token from this request and a valid request on the backend. So whos accces token is it, I don’t know??
Any help?