1

我有一个应用程序可以在使用 Microsoft 进行 sso 登录后获取令牌。我想创建使用该令牌的事件。但是当我使用该令牌创建事件时它会出错。由图形资源管理器生成的令牌工作正常,但从 sso 登录生成的令牌不起作用。

我正在使用角度。sso 的包是 @azure/msal-angular

 this.authService.loginPopup({redirectUri: 'http://localhost:4200',scopes: [ 'openid' ,'profile' ,'email' ,'Calendars.ReadWrite', 'Calendars.Read' ,'User.Read']})
    .subscribe({
      next: (result) => {
        console.log(result.accessToken); // using this access token 
       }
}
)
        




 url - https://graph.microsoft.com/v1.0/me/calendar/events
 
 body- {
    "subject": "Let's go for lunch",
    "body": {
        "contentType": "HTML",
        "content": "Does noon work for you?"
    },
    "start": {
        "dateTime": "2022-01-15T12:00:00",
        "timeZone": "India Standard Time"
    },
    "end": {
        "dateTime": "202-01-15T14:00:00",
        "timeZone": "India Standard Time"
    },
    "location": {
        "displayName": "Harry's Bar"
    },
    "attendees": [
        {
            "emailAddress": {
                "address": "ankitgupyta8768@gmail.com",
                "name": "Ankit Gupta"
            },
            "type": "required"
        }
    ],
    "allowNewTimeProposals": true,
    "transactionId": "7E163156-7762-4BEB-A8C6-729EA81755A8"
}


response- 
{"error":{"code":"NoPermissionsInAccessToken","message":"The token contains no permissions, or permissions can not be
understood.","innerError":{"oAuthEventOperationId":"7e74af78-358d-4f90-9b8d-b2656365592b","oAuthEventcV":"FyQYtJaGIm6+7397Aa/oLw.1.1","errorUrl":"https://aka.ms/autherrors#error-InvalidGrant","requestId":"3fb81b0a-42a8-47a0-995b-06d1301a3e0a","date":"2022-01-21T08:02:04"}}}
4

1 回答 1

1

您应该配置MsalInterceptor

https://graph.Microsoft.com/v1.0/me/calendar/events/*在这种情况下,它将自动为对特定受保护资源的所有请求添加一个令牌。

如果当前请求需要额外的同意,它甚至会请求额外的同意。

文档通常非常完整。如果你跟着你,你应该最终得到一个为你完成大部分令牌工作的 Angular 应用程序。无需担心令牌。

于 2022-02-14T22:03:25.933 回答