代码之家  ›  专栏  ›  技术社区  ›  Alexandre Blecich

Azure Graph API:Azure AD B2C禁止出现错误403

  •  3
  • Alexandre Blecich  · 技术社区  · 7 年前

    我有一个Azure广告B2C。由于Azure Active Directory已迁移到新门户,我在使用Azure Graph API读取和写入租户用户数据时遇到了问题。以前,我有一个应用程序是从旧门户创建的,现在无法使用。

    因此,我从新门户创建了一个新的应用程序,如下所示:

    下面是我从Azure Graph API访问用户数据的C代码:

          _authContext = new AuthenticationContext("https://login.microsoftonline.com/myTenant.onmicrosoft.com");
          _credential = new ClientCredential("<Application Client Guid>", "<Client secret which I created in "Keys" tab");
          var result = await _authContext.AcquireTokenAsync("https://graph.windows.net/", _credential);          
          var http = new HttpClient();
          var graphUrl = "https://graph.windows.net/myTenant.onmicrosoft.com/users/<My User Guid>?api-version=1.6";    
          var request = new HttpRequestMessage(new HttpMethod("GET"), graphUrl);
          request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);      
          var response = await http.SendAsync(request);
          return response;
    

    我总是得到一个403错误禁止。程序集“Microsoft.IdentityModel.Clients.ActiveDirectory”的版本为3.13.8.99。

    谢谢你的帮助!

    亚历克斯

    1 回复  |  直到 7 年前
        1
  •  3
  •   Nan Yu    7 年前

    您正在使用获取访问令牌 client credential flow . 这意味着您需要添加相关 应用程序权限 Required permissions 刀身

    Grant Permissions