对于用户身份验证,我使用最新的@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)类型。是否有任何其他选项可以解决此问题?
最佳答案
你的错误应该是这样的:
这个错误的原因是你发送的是静默请求,但是你没有先登录用户。有两种方法可以解决这个问题:
- >
- 发送login request before请求 token 。
- >
- 使用Implicit grant and hybrid flows直接在浏览器中执行动态登录请求,可以直接获取id token和access 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/