FormidableLabs / FormidableLabs/react-native-app-auth
Azure AD B2B Access Token getting a 401 response when used as a bearer token to a REST API call
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 473
- PR merge metrics
- No merged PRs in 30d
Description
I am using this library for an authentication in Azure AD of a mobile app in react native. It is returning an access token and able to authenticate as expected.
When I use the access token as bearer token to an API to retrieve data, I get an error saying Authorization is denied. We have setup the app reg/client id to have the permission on the backend/API prior as well. If we switch to B2C configuration on the same code, the token generated is accepted by the API and no error was thrown.
I have also tested the the previous library(react-native-azure-auth) we are using and the call to the API is successful as expected. When I compared the token being generated by both libraries, that is where I saw differences.
With this library, I get a decoded info using jwt.io like below
Header
{
"typ": "JWT",
"nonce": "Fl69avbnPyRtvARNqeyhFkn2zgLG8hosgrCmj6N67ag",
"alg": "RS256",
"x5t": "2ZQpJ3UpbjAYXYGaXEJl8lV0TOI",
"kid": "2ZQpJ3UpbjAYXYGaXEJl8lV0TOI"
}
Payload
{
"aud": "00000003-0000-0000-c000-000000000000",
"iss": "https://sts.windows.net/sometenantid/",
"iat": 1658366837,
"nbf": 1658366837,
"ver": "1.0"
...
}
On the React-Native-Azure-Auth token, I get something like below and no issue being used as bearer token on the API call. It has fewer fields and the version is different.
Header
{
"typ": "JWT",
"alg": "RS256",
"kid": "2ZQpJ3UpbjAYXYGaXEJl8lV0TOI"
}
Payload
{
"aud": "a17a5c4a-31af-4e98-b1a3-495c6386b6ab",
"iss": "https://login.microsoftonline.com/sometenantid/v2.0",
"iat": 1658307242,
"nbf": 1658307242,
"ver":"2.0"
...
}
Here is what I have for the configuration.
` const b2bConfig = {`
`issuer : https://login.microsoftonline.com/${b2bTenantId}/v2.0/,`
`clientId: b2bClientId,`
`redirectUrl: b2bRedirectURI,`
`scopes: ['openid', 'profile', 'offline_access'],`
`additionalParameters: {`
` prompt: 'login'`
` }`
`};`
I also tried adding service configuration as below but still got the same issue.
serviceConfiguration: {
authorizationEndpoint: "https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize",
tokenEndpoint: "https://login.microsoftonline.com/organizations/oauth2/v2.0/token"
}
Perhaps I am just missing something in the configuration that causes the access token not to be recognized or cause it to be denied? The versions are different and the number of fields is not the same as well.
Let me know if you need more information.
Any Help is appreciated.
Environment :
Your Identity Provider: Azure AD
Platform that you're experiencing the issue on: iOS (not yet tested on Android)
Are you using Expo? No
React Native Version : 0.68.2
React-Native-App-Auth : 6.4.3
Contributor guide
Assessment
This issue has not been assessed yet.