Hi everyone,
I am trying to protect an API after using authentication in may React Application
The authentication is Ok, but the settings seems to me very difficult to understand with the different settings like ‘audience’
So I need a JwToken to access my I Solved it with the this code
So now I have a token and I don’t understand how to use it to access my API
I have defined an API and I am confused how to use it I always have a 401 code
what I try to access it
What parameter should I put instead of xxx the domain
https://dev-123.eu.auth0.com or the name of the API
Thanks
Didier
The first part is sending me a 401 code
const userDetailsByIdUrl = xxx/api/v2/users/${user.sub}/roles
;
const metadataResponse = axios(userDetailsByIdUrl, {
headers: {
“Authorization”: Bearer ${accessToken}
,
},
});
// The first part is Ok( obtain a token but
useEffect(() => {
const getUserMetadata = async () => {
const domain = “xxx”;
const accessToken = await getAccessTokenSilently({
audience: `https://${domain}`,
scope: "read:current_user",
});
const userDetailsByIdUrl = `https://xxx/api/v2/users/${user.sub}/roles`;
const metadataResponse = axios(userDetailsByIdUrl, {
headers: {
"Authorization": `Bearer ${accessToken}`,
},
});
const { user_metadata } = metadataResponse.json();
console.log('user_metadata',user_metadata);
setUserMetadata(user_metadata);
};
getUserMetadata();
}, [getAccessTokenSilently, user]);