Azure Graph API:Azure AD B2C 禁止使用错误 403
Azure Graph API : Error 403 Forbidden with Azure AD B2C
我有一个 Azure AD B2C。由于 Azure Active Directory 已迁移到新门户,我在使用 Azure Graph API 读取和写入租户用户数据时遇到问题。之前,我有一个从旧门户创建的应用程序,现在无法使用。
因此,我从新门户创建了一个新应用程序,如下所示:
- 打开 "Azure Active Directory" 选项卡
- 打开"App registrations"
- 点击"New application registration"
"Properties" 选项卡:
- Name : GraphApi
- App ID URI : https://myTenant.onmicrosoft.com/graphapi
- Home page URL : https://graph.windows.net/winbizdev.onmicrosoft.com
"Reply URLs" 选项卡:
- https:// graph.windows.net/winbizdev.onmicrosoft.com
"Required permissions" 选项卡:
- Windows Azure Active Directory -> Check 3 elements which don't require admin
"Keys" 选项卡:
- CLIENT_SECRET which never expires
下面是我的 C# 代码,用于从 Azure Graph 访问用户数据 API :
_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 错误 Forbidden。程序集的版本 "Microsoft.IdentityModel.Clients.ActiveDirectory" 是 3.13.8.99.
那么,我的配置有什么问题?我需要做什么才能使用 Azure Graph 再次读取和写入用户租户用户数据 API?
感谢您的帮助!
亚历克斯
您正在使用 client credential flow 获取访问令牌。这意味着您需要在 Required permissions
blade .
中添加相关的 Application Permissions
azure ad graph 的所有应用程序权限api 需要管理员同意。添加应用权限后请点击Grant Permissions
按钮(使用管理员账号登录)。
我有一个 Azure AD B2C。由于 Azure Active Directory 已迁移到新门户,我在使用 Azure Graph API 读取和写入租户用户数据时遇到问题。之前,我有一个从旧门户创建的应用程序,现在无法使用。
因此,我从新门户创建了一个新应用程序,如下所示:
- 打开 "Azure Active Directory" 选项卡
- 打开"App registrations"
- 点击"New application registration"
"Properties" 选项卡:
- Name : GraphApi
- App ID URI : https://myTenant.onmicrosoft.com/graphapi
- Home page URL : https://graph.windows.net/winbizdev.onmicrosoft.com
"Reply URLs" 选项卡:
- https:// graph.windows.net/winbizdev.onmicrosoft.com
"Required permissions" 选项卡:
- Windows Azure Active Directory -> Check 3 elements which don't require admin
"Keys" 选项卡:
- CLIENT_SECRET which never expires
下面是我的 C# 代码,用于从 Azure Graph 访问用户数据 API :
_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 错误 Forbidden。程序集的版本 "Microsoft.IdentityModel.Clients.ActiveDirectory" 是 3.13.8.99.
那么,我的配置有什么问题?我需要做什么才能使用 Azure Graph 再次读取和写入用户租户用户数据 API?
感谢您的帮助!
亚历克斯
您正在使用 client credential flow 获取访问令牌。这意味着您需要在 Required permissions
blade .
azure ad graph 的所有应用程序权限api 需要管理员同意。添加应用权限后请点击Grant Permissions
按钮(使用管理员账号登录)。