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
- 主要言語
- Java
- スター
- 2.3k
- フォーク
- 473
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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
コントリビューションガイド
調査の方向性
issue にある b2bConfig、serviceConfiguration、デコード済みトークンの例から始め、設定されたスコープとエンドポイントを、各ライブラリから返される audience、issuer、version と比較します。React Native 0.68.2 と react-native-app-auth 6.4.3 を使用して iOS のフローを再現し、その後、B2B トークンが REST API に受け入れられることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- azure, react-native
- 領域
- authentication, mobile
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 20/100