2016-06-08 65 views
1

我正在编写使用Microsoft Graph API的服务。要检索访问令牌我也做了以下内容:基于IProvisioningWebServiceADAL - 如何以编程方式检索oAuth访问令牌

  1. 创建一个ServicePrincipal W /“公司管理员”角色使用SOAP(假设我会组织管理员凭据)
  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:{ “错误”: “invalid_grant”, “ERROR_DESCRIPTION”:“AADSTS65001:用户或管理员未同意使用具有ID 'XXXX' 应用程序发送为此用户和资源提供交互式授权请求。\ r \ n追踪ID:

回答

0

您需要前往Azure门户并在您的应用程序中添加访问图表的权限,此选项将位于在“委托权限”下的页面

0

发现它是我的一个问题...我应该使用clientId(th e 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);