首页 文章

Azure Graph API:错误403禁止使用Azure AD B2C

提问于
浏览
1

我有一个Azure AD B2C . 由于Azure Active Directory已迁移到新门户,因此使用Azure Graph API读取和写入租户用户数据时出现问题 . 以前,我有一个从旧门户创建的应用程序,现在不起作用 .

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

  • 打开"Azure Active Directory"标签

  • 打开"App registrations"

  • 点击"New application registration"

  • “属性”选项卡包含:

名称:GraphApi App ID URI:https://myTenant.onmicrosoft.com/graphapi主页URL:https://graph.windows.net/winbizdev.onmicrosoft.com

  • “回复网址”标签:

https:// graph.windows.net/winbizdev.onmicrosoft.com

  • “所需权限”标签包含:

Windows Azure Active Directory - >检查3个不需要管理员的元素

  • “键”标签:

永不过期的CLIENT_SECRET

现在,我是用于从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 .

那么,我的配置有什么问题?我需要做什么才能使用Azure Graph API再次读取和写入用户租户用户数据?

谢谢你的帮助!

亚历克斯

1 回答

  • 1

    您正在使用client credential flow获取访问令牌 . 这意味着您需要在 Required permissions 刀片中添加相关的 Application Permissions .

    azure ad graph api的所有应用程序权限都需要管理员同意 . 添加应用程序权限后,请单击 Grant Permissions 按钮(使用admin的帐户登录) .

相关问题