我有一个Web API,需要代表用户调用Microsoft。我正在使用这里描述的OBO流。
为了获得访问令牌,我将发帖到
POST - https://login.microsoftonline.com/<my-tenant-id>/oauth2/v2.0/token
grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer
&client_id=<my-client-id>
&client_secret=<my-client-secret>
&assertion=<user's access token>
&scope=https://graph.microsoft.com/files.readwrite.all
&requested_token_use=on_behalf_of
调用失败的消息如下:
{
"error": "invalid_grant",
"error_description": "AADSTS50013: Assertion failed signature validation. [Reason - The key was not found.]\r\nTrace ID: fb813f8e-ce15-4d09-bbae-9db5e5195a00\r\nCorrelation ID: ecb4e087-5506-4224-8f11-72fbf574beac\r\nTimestamp: 2020-10-22 02:18:57Z",
"error_codes": [
50013
],
"timestamp": "2020-10-22 02:18:57Z",
"trace_id": "fb813f8e-ce15-4d09-bbae-9db5e5195a00",
"correlation_id": "ecb4e087-5506-4224-8f11-72fbf574beac",
"error_uri": "https://login.microsoftonline.com/error?code=50013"
}
知道我可能做错了什么吗?
对周昌西的回应,
我有一个有角度的应用程序:
@azure/msal-角形“:"^1.0.0","msal":"1.3.3”
在app.module中,MSAL配置如下:
MsalModule.forRoot(
{
auth: {
clientId: environment.msClientId, // app1-client-id
authority: environment.msAuthorithy, // https://login.microsoftonline.com/<tenant-id>
redirectUri: environment.msRedirectUri // https://localhost:4200/callback
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: false
},
},
{
consentScopes: ['user.read', 'openid'],
protectedResourceMap: [
['https://app-2', ['api://app-2-id/scope-name']],
]
}
)
在测试组件中:
import { Component, OnInit } from '@angular/core';
import { MsalService } from '@azure/msal-angular';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss']
})
export class TestComponent implements OnInit {
constructor(private msal: MsalService) {}
ngOnInit(): void {
this.msal.acquireTokenSilent({ scopes: ['api://app-2/scope-name'] }).then(response => {
console.log(response);
});
}
}
从控制台获取访问令牌,并在postman中为OBO写一篇文章。
发布于 2020-10-22 04:02:53
错误是&assertion
。
您需要创建两个应用程序,一个是客户端应用程序(Test_1),另一个是web应用程序(Test_2)。
在test_2应用程序中,您需要公开一个api。
在test_1应用程序中,您需要授予test_1访问test_2的权限。
测试会议。首先,使用ROPC授权流为test_ 2应用程序请求访问令牌。
ropc赠款流动
注意,这里的作用域是api://{test_2 application id}/.default
。
其次,使用OBO流为microsoft图形api端点请求访问令牌。
代表flow
https://stackoverflow.com/questions/64474484
复制相似问题