我有一个Azure AD 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。
那么,我的配置有什么问题?我需要做什么才能使用Azure Graph API再次读取和写入用户租户用户数据?
谢谢你的帮助!
亚历克斯
您正在使用client credential flow获取访问令牌。这意味着您需要在Required permissions
刀片中添加相关的应用程序权限。
azure ad graph api的所有应用程序权限都需要管理员同意。添加应用程序权限后,请单击Grant Permissions
按钮(使用admin的帐户登录)。