首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用adal4j Api获取Azure令牌

无法使用adal4j Api获取Azure令牌
EN

Stack Overflow用户
提问于 2018-09-11 07:13:16
回答 1查看 775关注 0票数 1

我试图从Microsoft图形中读取用户配置文件/图像,并使用adal4j-1.5.0.jar生成蔚蓝令牌,以便基于标记调用图形API/Microsoft delve。

我在下面的代码中面临问题。在没有生成令牌或任何异常的情况下,最后逐行块很简单。未来= context.acquireToken(resourceUri,凭据,空);

代码语言:javascript
复制
String clientId = "clientid";
String clientSecret = "cleintsecret";
String resourceUri = "https://graph.microsoft.com/v1.0/me";

String redirectUri = "http://localhost:9082/contextroot";

String authorityUri ="https://login.microsoftonline.com/{tenent id}/oauth2/authorize";


AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
    service = Executors.newFixedThreadPool(1);
    context = new AuthenticationContext(authorityUri, false, service);
    ClientCredential credential = new ClientCredential(clientId,clientSecret);

    Future<AuthenticationResult> future = context.acquireToken(resourceUri, credential, null);



    result = future.get();
}
finally {
    service.shutdown();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-12 08:07:11

看起来adal4j-1.5.0的一些依赖项也没有下载,请查看项目中的jar包文件。基于我的测试,如果我使用adal4j 1.5.0。我发现项目中缺少adal4j-1.5.0的一些依赖项。那我就拿不到访问令牌了。

但是,如果我使用adal4j 1.0.0,它对我是正确的。如果版本1.0.0是可以接受的,您可以使用该版本作为解决办法,或者手动添加依赖项。

测试演示代码:

代码语言:javascript
复制
 private static final String APP_ID = "clientId";
 private static final String APP_SECRET = "secret key";
 private static final String TENATID = "xxxxx";
 public static void main(String[] args) throws Exception {
 String authority = "https://login.microsoftonline.com/"+TENATID; 
 String resourceUrl = "https://graph.microsoft.com"; //Microsoft graph. AD graph: https://graph.windows.net
 ExecutorService service = Executors.newFixedThreadPool(1);
 AuthenticationContext context = new AuthenticationContext(authority, true, service);
        // Acquire Token
 Future<AuthenticationResult> result = context.acquireToken(
                resourceUrl,
                new ClientCredential(APP_ID, APP_SECRET),
                null
        );
        String token = result.get().getAccessToken();
        System.out.println(token);
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52270540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档