MsalUiRequiredException 错误代码:user_null 角度 11

时间:2021-04-26 15:05:36

标签: angular azure

我正在使用 angular 11 构建 SPA 应用程序。该应用程序应连接到 Azure 安全 Web api 以获取数据。

当我连接到 web api 时,我收到此错误

<块引用>

"Microsoft.Identity.Web.MicrosoftIdentityWebChallengeUserException: IDW10502: 由于对用户的挑战,引发了 MsalUiRequiredException。请参阅 https://aka.ms/ms-id-web/ca_incremental-consent。 ---> MSAL.NetCore.4.29.0.0.MsalUiRequiredException: 错误代码:user_null

我可以从另一个 ASP.net Web 应用程序连接到我的 Web api,但不能从我的 Angular 应用程序连接。 我认为问题在于 Angular 和 web api 中的 azure 配置不同,我的 angular 应用程序生成的令牌与 api 除外的令牌不同。

有什么建议可以解决这个问题吗?

这是我的角度天蓝色配置

export const environment = {
  apiURL:'https://localhost:44382',
  clientId: 'my-client-id',
  authority: 'https://login.microsoftonline.com/tenant-id',
  redirectUri: 'authorize/signin',
  scopes: ['User.Read']
};

应用组件

import { Component } from '@angular/core';
import { MsalProvider, Providers } from '@microsoft/mgt';
import { environment } from 'src/environments/environment';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
  ngOnInit(){
     Providers.globalProvider = new MsalProvider({
        clientId: environment.clientId,
        authority: environment.authority,
        redirectUri: environment.redirectUri,
        scopes: environment.scopes,      
           });       
    Providers.globalProvider.getAccessToken().then(accessToken=>{console.log(accessToken);});

  }
}

这是我在 web api 中的 Azure 配置

"AzureAd": {
   "ClientId": "my-client-id",
   "Scopes": [ "User.Read" ],
   "ClientSecret": "client-secret",
   "Instance": "https://login.microsoftonline.com/",
   "TenantId": "tenant-id"
 }

谢谢

0 个答案:

没有答案
相关问题