【问题标题】:The request body must contain the following parameter: 'client_assertion' or 'client_secret请求正文必须包含以下参数:“client_assertion”或“client_secret”
【发布时间】:2021-08-04 14:37:29
【问题描述】:

对于用户身份验证,我使用的是最新的 @azure/msal-angular 包。这个 Angular 库基于用于 AD 身份验证的最新 MSAL 库。但是库会抛出下面给出的错误:

ServerError: invalid_client: 7000218 - [2021-05-14 07:42:54Z]: AADSTS7000218:请求正文必须包含以下参数:“client_assertion”或“client_secret”。

"@angular/core": "~10.2.4",
"@azure/msal-angular": "^2.0.0",
"@azure/msal-browser": "^2.14.1"

应用模块中的配置。

{
    auth: {
      authority: 'https://login.microsoftonline.com/<tenant>/',
      clientId: 'my client id',
      redirectUri: 'http://localhost:4200',
      postLogoutRedirectUri: 'http://localhost:4200/',
      navigateToLoginRequestUrl: false
    },
    cache:{
      cacheLocation: BrowserCacheLocation.LocalStorage
    },
    system: {
      loggerOptions: {
        loggerCallback,
        logLevel: LogLevel.Info,
        piiLoggingEnabled: false
      }
    }
  }

在 OnInit(应用程序组件)中执行以下代码时出现此错误

this.msalService.instance.handleRedirectPromise().then(response => {
      console.log('response', response);
      if (response !== null && response.account !== null) {
        this.msalService.instance.setActiveAccount(response.account);
      }
    });

一些博客说,将应用类型更改为公共类型。有没有其他方法可以解决这个问题?

【问题讨论】:

  • 您使用的是哪种身份验证流程?
  • 你关注这个tutorial吗?如果是这样,您需要将应用中使用的重定向 URI 设置为 Azure 门户中的“单页应用程序”类型。
  • 您使用的是用户名/密码流吗?
  • @CarlZhao 隐式授权流程
  • @PamelaPeng 我已经实现了与教程中相同的实现。但是,当我调用 aquaaireTokenSilent 方法时,收到错误“AADSTS50058:已发送静默登录请求,但没有用户登录。用于表示用户会话的 cookie 未在请求中发送到 Azure AD。这可能发生如果用户使用的是 Internet Explorer 或 Edge,并且发送静默登录请求的 Web 应用与 Azure AD 端点 (login.microsoftonline.com) 位于不同的 IE 安全区域中。”在 chrome 隐身窗口中。

标签: angular azure-active-directory msal


【解决方案1】:

你的错误应该是这样的:

这个错误的原因是你正在发送一个静默请求,但你没有先登录到用户。有两种方法可以解决这个问题:

    1. 发送login request before 请求令牌。
    1. 使用隐式授权和混合流直接在浏览器中执行动态登录请求,可以直接获取id tokenaccess token 在浏览器中。
https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/authorize?
client_id={client_id}
&response_type=id_token token
&redirect_uri={redirect_uri}
&scope=openid {api resource scope}
&response_mode=fragment
&state=12345
&nonce=678910

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    • 2021-11-22
    • 1970-01-01
    相关资源
    最近更新 更多