我在我公司的AAD中注册了一个Web API应用程序。这是一个多租户应用程序,能够查询已订阅客户的AAD。当客户订阅我们的服务时,他们会在其AAD的“企业应用程序注册”部分中注册我们的应用程序,并向我们提供tenantId,clientId和clientSecret。然后,我们使用这些参数来查询客户的AAD。
我正在使用以下内容从客户的Azure AD中读取组:
public async Task<GraphServiceClient> CreateGraphServiceClient(string tenantId, string clientId, string clientSecret)
{
string aadInstance = "https://login.microsoftonline.com/{0}";
string resource = "https://graph.microsoft.com";
string authority = string.Format(aadInstance, tenantId);
AuthenticationContext authContext = new AuthenticationContext(authority);
ClientCredential credentials = new ClientCredential(clientId, clientSecret);
var authResult = await authContext.AcquireTokenAsync(resource, credentials);
if(authResult == null)
{
throw new Exception("GetGraphServiceClient: AcquireTokenAsync failed!");
}
var accessToken = authResult.AccessToken;
var graphServiceClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
requestMessageClientOtherTenant =>
{
requestMessageClientOtherTenant.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.FromResult(0);
}));
return graphServiceClient;
}
//....
var graphServiceClient = CreateGraphClient(tenantId, clientId, clientSecret);
var graphGroupsPage = await graphServiceClient.Groups
.Request()
.Select(e => new {
e.Id,
e.DisplayName
})
.GetAsync();
我获得的权限不足,无法完成操作。
[我已经看到许多在线解决方法,它们只有2-3岁,但其中的一些对我有用。
这些权限与我们在AAD注册中分配给该应用程序的权限完全相同。
我不知所措。所有必需的权限似乎都被授予了,但我仍然收到错误消息。
我可以使用相同的图形客户端,从客户的AAD毫无问题地获取所有用户。
任何建议将不胜感激。
当客户订阅我们的服务时,他们会在自己的网站上注册我们的应用AAD的企业应用程序注册部分,并向我们提供tenantId,clientId和clientSecret。然后,我们使用这些参数来查询客户的AAD。
由于您的客户已授予您的多租户应用访问他们的租户信息,因此仅需要客户的tennantId
,因此您应该使用自己的多租户应用的clientId
和clientSecret
来访问客户的广告。
如果使用客户的client_id和secret,则应检查其应用程序(而非企业应用程序)下的权限,但这没有任何意义。如果是这样,则无需使用您的多租户应用程序。