【发布时间】:2020-06-19 01:10:52
【问题描述】:
我目前正在尝试使用 MSAL4J 库来获取 ConfidentialClientApplication 的 AccessToken。我已经获得了令牌,但是当我将它传递给 Exchange 时,我收到错误“令牌不包含权限,或者权限无法被理解”。我用 jwt.io 检查了令牌,我可以看到没有“scp”字段,这意味着可能没有范围,但我不知道为什么。
访问令牌的Java代码:
String AUTHORITY = "https://login.microsoftonline.com/common";
IClientSecret createFromSecret = ClientCredentialFactory.createFromSecret(clientSecret);
Builder builder = ConfidentialClientApplication.builder(clientId, createFromSecret).authority(aUTHORITY).validateAuthority(true);
ConfidentialClientApplication application = builder.build();
HashSet<String> scopes = new HashSet<String>();
scopes.add("https://outlook.office.com/.default");
ClientCredentialParameters clientCredentialParameters = ClientCredentialParameters.builder(scopes).build();
CompletableFuture<IAuthenticationResult> acquireTokenFuture = application.acquireToken(clientCredentialParameters);
IAuthenticationResult iAuthenticationResult = acquireTokenFuture.get(30, TimeUnit.SECONDS);
iAuthenticationResult = acquireTokenFuture.get(30, TimeUnit.SECONDS);
我已经添加了必要的 api 权限并使用管理员帐户批准了它们:
有什么想法吗?
【问题讨论】:
标签: java oauth-2.0 exchangewebservices access-token msal