2016-02-11 18 views
1

我正在使用Microsoft.Azure.ActiveDirectory.GraphClient 2.1.1.0版來獲取我的用戶所屬的組。 方法調用是這樣的:獲取Azure Graph API庫中的成員組掛起

ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(
             new Uri(GraphUrl), 
             async() => await GetAppTokenAsync()); 

IEnumerable<string> groups = GetGroupsAsync(activeDirectoryClient, "currentUserObjectId").Result; 

private static async Task<IEnumerable<string>> GetGroupsAsync(ActiveDirectoryClient activeDirectoryClient, string currentUserObjectId) 
{ 
    return await activeDirectoryClient.Users.GetByObjectId(currentUserObjectId).GetMemberGroupsAsync(true); 

} 

private static async Task<string> GetAppTokenAsync() 
{ 
      var authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(ServiceRoot); 
      var token = await authContext.AcquireTokenAsync(GraphUrl,new ClientCredential("clientId", "clientSecret")); 
      return token.AccessToken; 
} 

但是該方法掛起即使菲德勒我看到該請求已經succedeed幷包含正確的組。

我的問題是Azure ActiveDirectory Graph API GraphClient not returning AD Groups的重複。解決方法存在但不解釋爲什麼該方法不起作用。

+0

你能在你的例子提供多一點(HTTP://? stackoverflow.com/help/mcve)很高興看到調用此方法的代碼。 –

+0

我在示例中添加了調用方法 – jlp

回答

0

如果您的ServiceRoot值與ActiveDirectoryClient的實例化以及您對AuthenticationContext的調用確實相同,那可能是您的問題的根源。

ActiveDirectoryClient應該被實例化https://graph.windows.net/

AuthenticationContext應 https://login.microsoftonline.com/

被稱爲雖然這不會體現在方法掛,也不是一個成功的請求,這是我不得不做出的唯一改變到您的代碼爲它工作,否則它會返回一個未找到錯誤。

+0

我在代碼段中修復了URL,並添加了一個重複問題的鏈接。當我在Fiddler中看到正確的HTTP消息時,URL在我的真實代碼中是正確的。你認爲在方法上調用Result可能是問題嗎? – jlp

0

使用結果屬性時我已經與圖形API庫類似的問題,試着改變你的電話本: -

IEnumerable<string> groups = await GetGroupsAsync(activeDirectoryClient, "currentUserObjectId");