angular - 请求体必须包含以下参数 : 'client_assertion' or 'client_secret

标签 angular azure-active-directory msal

对于用户身份验证,我使用最新的@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);
      }
    });

一些博客说,将应用程序类型更改为公共(public)类型。是否有任何其他选项可以解决此问题?

最佳答案

你的错误应该是这样的:

enter image description here

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

  • >
    1. 发送login request before请求 token 。
  • >
    1. 使用Implicit grant and hybrid flows直接在浏览器中执行动态登录请求,可以直接获取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

关于angular - 请求体必须包含以下参数 : 'client_assertion' or 'client_secret,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67534008/

相关文章:

angular - HTTP 错误处理如何与可观察对象一起工作?

javascript - 在 Angular 4 中使用 select 更改(输入的)字体系列?

azure - 删除 Azure Active Directory 返回删除所有应用程序注册,尽管没有应用程序

azure - 您可以为 Function App 中的各个函数分配用户托管身份吗?

javascript - 如何在 Angular 8 中添加冰沙图表

angular - nrwl/nx 8.8.0 的 license-webpack-plugin 错误

azure - 如何使用 Terraform 创建客户端 key ?

azure-active-directory - Azure Active Directory v2.0守护程序和服务器端应用程序支持

angular - 使用 msal.js 对 Angular SPA 进行身份验证

msal.js 使用没有 secret 的授权代码授予