2016-08-24 27 views
0

看起來好像我是否使用「https://management.core.windows.net」作爲資源ID創建令牌,那麼我將無法對圖API使用相同的accessToken 。有沒有辦法避免多次調用AcquireTokenAsync?我可以使用相同的accessToken訪問Azure AD圖api和Azure管理資源嗎?

AuthenticationResult result = authContext.AcquireTokenAsync("https://management.core.windows.net", "<some_client_id>, new Uri("https://localhost"), new PlatformParameters(PromptBehavior.Always)).Result; 

TaskCompletionSource<string> tcs = new TaskCompletionSource<string>(); 
tcs.SetResult(result.AccessToken); 
ActiveDirectoryClient graphClient = new ActiveDirectoryClient(new Uri("https://graph.windows.net/" + result.TenantId), 
() => { return tcs.Task; }); 
foreach (var app in graphClient.Applications.ExecuteAsync().Result.CurrentPage) 
{ 
    Console.WriteLine($"{app.AppId}, {app.DisplayName}"); 
} 

回答

1

Azure AD訪問令牌僅適用於單個資源,因此簡短回答爲否。

但是,您確實從Azure AD發佈multi-resource refresh tokens這一事實中獲益,這意味着獲取第二個資源的訪問令牌只是對AAD令牌端點的調用,而不是完整的身份驗證流。

相關問題