无法使用MSALjs使用访问令牌获取图API用户组

时间:2020-06-16 12:55:19

标签: asp.net azure angular8 msal

我正在与.net一起使用msaljs。我能够获得v2 oauth令牌,但是在.net中,GetMyMemberOfGroupsAsyncmethod返回带有无效紧凑令牌错误的401。我尝试更改应用程序的范围,但无济于事。

这是角度配置文件

{
"msalConfig": {
    "clientId": "CLIENT_ID",
     "authority": "https://login.microsoftonline.com/TENANT_ID/",
     "validateAuthority": true,
     "redirectUri": "http://localhost:3000/",
    "postLogoutRedirectUri": "http://localhost:3000/"
  },
  "angular": {
    "popUp": false,
    "consentScopes": [
      "user.read.all",
      "directory.Read.all"
    ]
  }
}

以下是通过JWT.io解析的令牌

{
  "aud": "AUD",
  "iss": "https://login.microsoftonline.com/TENANT_ID/v2.0",
  "iat": 1592242137,
  "nbf": 1592242137,
  "exp": 1592246037,
  "aio": "",
  "email": "",
  "family_name": "",
  "given_name": "",
  "name": "",
  "nonce": "",
  "oid": "",
  "preferred_username": "USERNAME",
  "sub": "",
  "tid": "",
  "uti": "",
  "ver": "2.0"
}

该异常发生在以下代码段的最后一行:

        public async Task<List<Group>> GetMyMemberOfGroupsAsync(string accessToken)
        {
            List<Group> groups = new List<Group>();
            PrepareAuthenticatedClient(accessToken);
            // Get groups the current user is a direct member of.
            IUserMemberOfCollectionWithReferencesPage memberOfGroups = await graphServiceClient.Me.MemberOf.Request().GetAsync();

.net后端出现以下异常

失败:Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware [1] 执行请求时发生未处理的异常。 状态码:未经授权 Microsoft.Graph.ServiceException:代码:InvalidAuthenticationToken 消息:CompactToken解析失败,错误代码:80049217 内部错误: 附加数据: 日期:2020-06-16T12:44:50 要求编号:ce0a83bf-3e33-4510-b4f6-9840dfb85a8a ClientRequestId:ce0a83bf-3e33-4510-b4f6-9840dfb85a8a

端点使用v2.0。另外,我尝试在配置文件中添加如下所示的受保护资源映射,但令牌似乎不受影响:

    protectedResourceMap: [
        ['https://graph.microsoft.com/v1.0/me', ['user.read']]
    ];

0 个答案:

没有答案