【问题标题】:msal.js: different AuthenticationResults for different environmentsmsal.js:不同环境的不同AuthenticationResults
【发布时间】:2022-01-09 09:33:47
【问题描述】:

使用基本登录用户流策略。 acquireTokenSilent 的响应在我的开发环境中与我的 QA 环境不同,即使代码相同(已升级)并且 ADB2C 中的配置相同。我注意到的主要区别是我没有收到来自 AuthenticationResult 响应对象的 expiresOn 属性。

我可以看到SessionStorage 中的idTokenClaims 也略有不同。开发环境有一个at_hash 属性,而QA 没有。

响应对象有什么不同吗?

我检查了所有设置,但两个环境上的“令牌生命周期设置”是相同的:

Access & ID token lifetimes (minutes):  60
Refresh token lifetime (days):  14
Refresh token sliding window lifetime: Bounded
Lifetime length (days): 90

检查QA/token 端点的网络响应我收到了这个:

client_info: "ey..."
id_token: "ey..."
not_before: 1638467851
refresh_token: "ey..."
refresh_token_expires_in: 86398
scope: ""
token_type: "Bearer"

检查DEV/token 端点的网络响应我收到了这个:

access_token: "ey.."
client_info: "ey.."
expires_in: 3600
expires_on: 1638485366
id_token: "ey.."
not_before: 1638481766
refresh_token: "ey.."
refresh_token_expires_in: 86400
resource: "xxxxxx"
scope: "https://xxxxxx.onmicrosoft.com/demo-api/demo.all.all"
token_type: "Bearer"

一些相关代码:

import { PublicClientApplication } from '@azure/msal-browser'
import { useMsal } from '@azure/msal-react'
const msalInstance = new PublicClientApplication(msalConfig)
...
const { instance, accounts, inProgress } = useMsal()
useEffect(() => {
    if (account) {
      instance
        .acquireTokenSilent({
          scopes: myloginScopes,
          account
        })
        .then(res => {
          if (res) {
            console.log(res.expiresOn) // <-- exists on one environment and not the other
          }
        })
    }
  }, [account, instance, inProgress])

开发环境信息:

Azure ADB2C
@azure/msal-browser 2.17.0
@azure/msal-react: 1.0.2

【问题讨论】:

    标签: azure-ad-b2c msal.js


    【解决方案1】:

    在 QA 中,myloginScopes 为空。将其设置为https://xxxxxx.onmicrosoft.com/demo-api/demo.all.all

    【讨论】:

    • 谢谢!我在配置中将字符串硬编码为https://mydev.onmicrosoft.com/demo-api/demo.all.all 而不是https://${MY_TENANT}.onmicrosoft.com/demo-api/demo.all.all
    • Jas Suri - MSFT。感谢您的评论,但经过进一步测试后我意识到这并没有解决问题。
    • 唯一的其他原因是您没有正确设置权限。 docs.microsoft.com/en-us/azure/active-directory-b2c/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    相关资源
    最近更新 更多