MSAL: InteractionRequiredAuthError: no_tokens_found: No refresh token found in the cache. Please sign-in

MSAL: InteractionRequiredAuthError: no_tokens_found: No refresh token found in the cache. Please sign-in

这是我正在处理的代码。我在同一个 domain 上为两个 SSO 应用程序使用 MSAL,例如 https://some-domain.com/app1https://some-domain.com/app2,请参阅下面的代码片段。

应用程序 1 似乎没问题,它允许用户登录 correctly.However,在应用程序 2 上,当我重新加载页面时它抛出 error

MSAL: InteractionRequiredAuthError: no_tokens_found: No refresh token found in the cache. Please sign-in.

我用过 instance.acquireTokenRedirectacquireTokenSilentidentityInstance.loginRedirect(),但似乎没有任何效果。任何想法请分享。谢谢。

const [userName, setUsername] = useState<string | undefined>()

useEffect(() => {
const fetchDetaiils = async () => {
      if (inProgress === InteractionStatus.None) {
        try {
          const signedInUser = identityInstance.getAllAccounts()[0]
          const resp = await identityInstance.acquireTokenSilent({
            scopes: ['user.read'],
            account,
          })
          const token: Token = resp?.idTokenClaims
          setUsername(token.email)
        } catch (err: unknown) {
          if (err instanceof Error) {
            console.log(err)
            if (err?.name === 'InteractionRequiredAuthError') {
              // await instance.acquireTokenRedirect(loginRequest)
            }
          }
        }
      }
    }

    fetchDetaiils()

如这些 Microsoft Docs 中所述,应用程序之间的 SSO 需要在静默请求中使用 login_hint 或 sid(会话 ID)参数。

login_hint和sid的值可以从App 1中获取的ID Token中提取出来,更多信息请参考MSAL Browser Login Docs