- Expo Version: 4.4.4
- React Native + Expo
I’m facing this issue, I can retrieve the authorization code from Azure AD, but then I can’t get the ACCESS TOKEN…
const discovery = useAutoDiscovery('https://login.microsoftonline.com/MY_TENANT/v2.0');
const [request, response, promptAsync] = useAuthRequest(
{
clientId: 'MY_CLIENT_ID',
scopes: ['openid', 'profile', 'email', 'offline_access'], //
redirectUri: makeRedirectUri({
scheme: 'your.app'
}),
},
discovery
);
useEffect(() => {
if (response !== null && response.type === 'success') {
if (response.type && response.type === 'success') {
(async () => {
console.log(response.params.code) //<-- this works
const { accessToken } = await exchangeCodeAsync(
{
clientId: request?.clientId as string,
code: response.params.code,
redirectUri: makeRedirectUri({
scheme: "your.app"
}),
extraParams: {
client_secret: "MY_SECRET", //<-- should I send the secret??
},
},
{ tokenEndpoint: 'https://login.microsoftonline.com/MY_TENTANT/oauth2/token' }
);
console.log(accessToken) //<-- NOTHING
})();
}
else if (response.error && response.error !== "") {
//do stuff
}
}
The response in the console is that I can obtain the authorization code but the second call to get the access token returns this:
[Unhandled promise rejection: Error: The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.]
Please can someone help me?