![](/img/trans.png)
[英]Spring Boot Azure AD - AzureADGraphClient.aquireTokenForGraphApi throw error: unable to acquire on-behalf-of token for client
[英]Authenticate to Azure AD on-behalf-of a client application
在這樣的情況下: https : //github.com/Azure-Samples/active-directory-dotnet-webapi-onbehalfof
我想代表客戶端(而不是用戶)在后端對Azure AD進行身份驗證。 我在適合這種情況的文檔中找不到合適的示例。
那我在做什么呢?
在客戶端中:
var authContext = new AuthenticationContext(authorityUrl);
var result = authContext.AcquireTokenAsync(webServiceUri, new ClientCredential(nativeClientId, nativeClientSecret)).GetAwaiter().GetResult();
在后端服務中:
var authContext = new AuthenticationContext(authorityUrl);
var result = authContext.AcquireTokenAsync(office365ResourceUri, new ClientAssertion(webClientId, result.AccessToken))
這將引發以下異常:
AADSTS70002: Client assertion application identifier doesn't match 'client_id' parameter.
只有當我在后端指向與客戶端相同的服務(指的是自身!)時,它才會成功:
authContext.AcquireTokenAsync(webServiceUri, new ClientAssertion(nativeClientId, result.AccessToken))
但這沒有意義,因為該服務必須轉到Office 365 API。
有人知道嗎?
OAuth 2.0代理流程是通過請求鏈傳播委派的用戶身份和權限。 為了使中間層服務向下游服務發出經過身份驗證的請求,它需要代表用戶保護來自Azure Active Directory(Azure AD)的訪問令牌。
在您的方案中,您可以使用客戶端憑據流來獲取服務應用程序中Office 365 api的令牌,而無需任何人為干預,例如交互式登錄對話框。
請單擊此處以獲取有關Azure AD身份驗證方案的更多詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.