我正在尝试在Xamarin应用程序中获取我所属的组。
现在,我用这个方法得到了一个令牌:
public async Task SignIn()
{
if (App.IdentityClientApp != null)
this.authenticationResult = await App.IdentityClientApp.AcquireTokenAsync(new String[] { Constants.ApplicationID });
}
我的应用ID来自Apps.dev.microsoft.com注册门户。
然后,我使用此方法静默获取另一个令牌:
private async Task GetTokenForGroups()
{
this.authenticationResult = await App.IdentityClientApp.AcquireTokenAsync(new String[] { "User.Read", "Directory.AccessAsUser.All" }, null);
}
如果我这样做,系统会提示我使用管理员帐户登录。如果我这样做了,令牌获取将会成功,但不是“记住”其他非管理员用户的授权,而是每次都会提示我进行管理员授权。
如果我仅使用"User.Read“作用域进行此调用:
public void GetAuthenticatedClient()
{
try
{
this.graphClient = new GraphServiceClient(
"https://graph.microsoft.com/v1.0",
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
await GetTokenForGroups();
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", this.authenticationResult.Token);
}));
}
catch (Exception ex)
{
Debug.WriteLine("Could not create a graph client: " + ex.Message + ex.InnerException);
}
}
public async void GetGroups()
{
this.GetAuthenticatedClient();
var groups = await graphClient.Me.MemberOf.Request().GetAsync();
}
我得到了一些组,但他们似乎是Outlook组,而不是安全组。
我在apps.dev.microsoft.com中的图表权限是完全空的。
怎样才能读取目录数据?我做错了什么?
谢谢。
发布于 2017-06-22 05:03:13
您需要使用管理员同意工作流。简单地以管理员身份登录不会向非管理员用户提供同意。有一个特定的工作流程来实现这一点。
看看我写的一篇名为v2 Endpoint and Admin Consent的文章。它应该为您提供一个连接同意流程的起点。
https://stackoverflow.com/questions/44680152
复制相似问题