簡體   English   中英

ADAL - 如何以編程方式檢索oAuth訪問令牌

[英]ADAL -How do I retrieve oAuth access token programmatically

我正在編寫一個使用Microsoft Graph API的服務。 要檢索訪問令牌,我已完成以下操作:

  1. 使用基於SOAP的IProvisioningWebService創建一個具有“公司管理員”角色的ServicePrincipal(假設我將擁有組織管理員憑據)
  2. 然后使用ADAL4J lib來檢索訪問令牌

     // clientId = AppPrincipalId created in step#1 Future<AuthenticationResult> future = context.acquireToken( "https://graph.windows.net", clientId, username, password, null); 

我收到以下錯誤,我的方法無效嗎?

com.microsoft.aad.adal4j.AuthenticationException:{“error”:“invalid_grant”,“error_description”:“AADSTS65001:用戶或管理員未同意使用ID為'XXXX'的應用程序。發送交互式授權請求用戶和資源。\\ r \\ nTrace ID:

您需要轉到azure portal並添加訪問應用程序中圖形的權限。 執行此操作的選項將位於“委派權限”下的頁面底部。

發現這是我的問題...我應該使用clientId(appPrincipalId和client_secret(創建SP時使用的密碼)並使用以下調用來檢索access_token。

String authority = String.format(" https://login.windows.net/%s ",getTenantContextId()); context = new AuthenticationContext(authority, false, service); ClientCredential clientCredential = new ClientCredential(getAppPrincipalId(),getSymmetricKey()); Future future = context.acquireToken(" https://graph.windows.net ", clientCredential, null);

暫無
暫無

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

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