Hi Team,
I am using free account of Auth0 to build Sitecore JSS client side application using NextJS and integrate SSO with Auth0 identity provider.
I am able to call the /authorize api and get the code for my app. And when I am trying get the access token from the code using api oauth/token, I am getting 401 unauthorized issue in my network tab in developer tools.
I tried all the solutions available in the community, but no use.
The below code is the sample code I had written to fetch token.
async function getAccessToken(code: any) {
try{
const token_url = config.baseurl + "/oauth/token?" +
new URLSearchParams({
client_id: config.client_id,
client_secret: config.client_secret,
grant_type: 'implicit',
code: code
});
const response = await fetch(token_url, {
headers: {
'Content-Type' : 'application/json',
},
method: 'POST'
});
const token = await response.json();
console.log(token.access_token);
if(!response.ok){
throw token;
}
return {
accessToken : token.access_token
};
}
catch(error){
return {
error: 'RefreshAccessTokenError',
};
}
};
The below is the error message.
Please help me to resolve this issue.