簡體   English   中英

從Azure Active Directory訪問所需的響應

[英]Access Required Response from Azure Active Directory

按照Microsoft提供代碼 (假設),我無法查詢Azure Active Directory。 每次調用以下內容時,都會收到{Authorization Required.}的響應:

ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();
IPagedCollection<IUser> pagedCollection = await client.Users.ExecuteAsync();

我是Azure Active Directory的新手,也是Graph的新手,並認為所提供的示例可以正常運行。 他們沒有,我希望這里的人可以告訴我代碼有什么問題,或者如何授予自己對自己目錄的授權? 我以為AccessKey將是身份驗證方法,但顯然沒有用,因為在他們的示例中未使用它。

基本上,要調用受支持OAuth2.0的受Azure AD保護的REST來授權第三方應用程序,我們需要傳遞承載令牌。

並且要遍歷代碼示例,請確保遵循README.md的步驟列表。

注意:README.md中關於配置權限的內容尚不清楚。 該代碼示例使用Azure AD Graph代替Microsoft Graph,我們需要選擇Windows Azure Active Directory代替Microsoft Graph 我已經在這里報告了這個問題。

您可以看到在AuthenticationHelper類中有一個名為file的靜態文件令牌 ,當用戶使用Startup.Auth.cs中的代碼登錄時,將設置該值,如下所示:(不使用cert)

// Create a Client Credential Using an Application Key
ClientCredential credential = new ClientCredential(clientId, appKey);
string userObjectID = context.AuthenticationTicket.Identity.FindFirst(
    "http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

AuthenticationContext authContext = new AuthenticationContext(Authority, new NaiveSessionCache(userObjectID));
AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
                                    code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);

AuthenticationHelper.token = result.AccessToken;

以下是通過OAuth 2.0代碼授權流程獲取令牌的詳細過程: 在此處輸入圖片說明

有關此流程的更多詳細信息,您可以在這里參考。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM