在我的初步分析上使用OpenID的獲取從Azure的AD訪問令牌連接協議,我才知道有考慮背景信息需要傳遞給圖形API
-
兩種方式
使用使用緩存的登錄用戶上下文獲取訪問令牌。
使用應用程序上下文獲取訪問令牌。
任何人都可以幫助我知道哪些需要考慮一些示例代碼。
在我的初步分析上使用OpenID的獲取從Azure的AD訪問令牌連接協議,我才知道有考慮背景信息需要傳遞給圖形API
使用使用緩存的登錄用戶上下文獲取訪問令牌。
使用應用程序上下文獲取訪問令牌。
任何人都可以幫助我知道哪些需要考慮一些示例代碼。
要獲取訪問令牌的圖形API,您需要:
將用戶重定向到Azure的授權端點(https://login.microsoftonline.com/common/oauth2/v2.0/authorize
),
找回授權令牌,
您需要在訪問令牌端點(https://login.microsoftonline.com/common/oauth2/v2.0/token
)上爲您的Azure提供您的應用程序憑據。
最後,可以提供圖形API此訪問令牌的用戶信息端點:https://graph.microsoft.com/v1.0/me
一些示例代碼
我寫了一個示例代碼,但它完全取決於您使用的語言,環境和OIDC庫。在你的servlet環境與MIT實施OIDC(MITREid連接)的使用Java的情況下,我的例子訪問在Azure上的OIDC手段的微軟圖形API可以在GitHub上的位置:https://github.com/AlexandreFenyo/mitreid-azure
使用使用緩存的登錄用戶上下文獲取訪問令牌。
OpenID Connect將認證作爲OAuth 2.0授權過程的擴展來實現。它以id_token的形式提供有關最終用戶的信息,驗證用戶的身份並提供有關用戶的基本配置文件信息。
請參考代碼示例:Calling a web API in a web app using Azure AD and OpenID Connect,本示例使用OpenID Connect ASP.Net OWIN中間件和ADAL .Net。在控制器,你可以使用用戶的上下文中籤獲得訪問令牌特定的資源:
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userObjectID));
ClientCredential credential = new ClientCredential(clientId, appKey);
result = await authContext.AcquireTokenSilentAsync(todoListResourceId, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
抓取訪問令牌使用應用程序上下文。
你所說的 「應用程序上下文」 是什麼意思?如果你在談論OAuth 2。0客戶端證書授權流程,允許Web服務(機密客戶端)使用自己的憑證而不是模擬用戶,在調用其他Web服務時進行身份驗證。你可以參考這個scenario explanation和code samples。