You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ionic应用调用acquireTokenSilentAsync刷新Azure AD令牌失败求助

Fixing AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED in Azure AD Cordova Plugin

I’ve run into this exact issue before—let’s break down what’s happening and how to fix it. This error pops up when acquireTokenSilentAsync fails to refresh your access token, and the plugin is blocked from triggering an interactive login prompt to recover, usually because your refresh token is expired or invalid.

1. Validate Your Refresh Token’s Lifespan & Validity

Azure AD refresh tokens don’t last forever (default max is 90 days, but shorter for public client apps like Cordova). They can also get revoked if the user changes their password, revokes app permissions, or if your app’s configuration changes.

  • Check your Azure AD app registration’s token lifetime settings to ensure they align with your app’s needs.
  • Verify if the refresh token stored locally is still valid (you can decode it using tools like jwt.io to check the expiration claim exp).

2. Add a Fallback to Interactive Login When Silent Refresh Fails

The simplest fix is to catch this specific error and explicitly trigger an interactive login with acquireTokenAsync. Here’s how to implement it in your code:

try {
  const tokenResponse = await adal.acquireTokenSilentAsync(yourResourceId, yourClientId);
  // Use the fresh access token
} catch (error) {
  if (error.code === 'AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED') {
    // Silent refresh failed—fall back to interactive login
    try {
      const interactiveToken = await adal.acquireTokenAsync(yourResourceId, yourClientId, yourRedirectUri);
      // Update your local token storage with the new tokens
    } catch (interactiveError) {
      console.error('Interactive login failed:', interactiveError);
      // Handle cases where the user cancels the login prompt
    }
  } else {
    console.error('Unexpected token error:', error);
  }
}

3. Double-Check Your Plugin Configuration

Make sure your plugin initialization isn’t forcing silent-only mode:

  • Avoid setting prompt: 'none' in your config—this parameter blocks interactive prompts entirely, which is why you’re seeing this error.
  • Confirm your redirectUri matches exactly what’s registered in your Azure AD app (Cordova apps typically use URIs like msal{YOUR_CLIENT_ID}://auth—don’t forget to add this to your Azure portal’s redirect URIs list).

4. Verify App Permissions & Resource Scope

  • Ensure the resourceId you’re passing to acquireTokenSilentAsync is correct (e.g., https://graph.microsoft.com for Microsoft Graph).
  • Check that your Azure AD app has the necessary permissions granted, and that the user has consented to those permissions (for delegated permissions).

5. Clear Corrupted Token Cache

Sometimes stale or corrupted token cache data can cause refresh failures. Try clearing the cache and re-authenticating:

await adal.clearCache();
// Then trigger interactive login to get fresh tokens
const freshToken = await adal.acquireTokenAsync(yourResourceId, yourClientId, yourRedirectUri);

内容的提问来源于stack exchange,提问作者Danny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:38:25