我正在尝试创建一个简单的应用程序,允许我列出和编辑Azure Active Directory上的用户帐户。
这些用户通过Azure B2C添加到目录中。
我跟踪了一些示例,经过几个小时的研究,我想出了一段简单的代码,试图从Azure AD获得一个令牌,然后尝试查询Graph以获得用户列表。
我看过的样本是:
https://github.com/AzureAD/azure-activedirectory-library-for-java
https://github.com/Azure-Samples/active-directory-java-native-headless
和图书馆WIKI
https://github.com/AzureAD/azure-activedirectory-library-for-java/wiki
但出于某种原因,我从azure获得了401个未经身份验证的状态代码,其中包含以下错误消息:
{'odata.error':{'code':'Authentication_MissingOrMalformed','message':{'lang':'en','value':'Access Token missing or malformed.'},'date':'2018-08-02T18:39:48','requestId':'7ddb7d55-2074-4124-9863-a19626a6b49f','values':null}}即使在发送授权头时也是如此。
有一件事是,为了验证Azure AD中的应用程序,我使用了在Azure AD应用程序注册中注册的应用程序。
我编写了一个包含所有需求的示例项目,可以在github上获得
https://github.com/pedrorochaorg/Microsoft-ADAL-Sample
有人能告诉我实现这个目标的正确方法吗?
发布于 2018-08-06 06:44:57
根据错误消息Authentication_MissingOrMalformed。您获得的访问令牌不是对应的资源。
根据您提到的代码,资源url应该是https://graph.windows.net而不是APP_ID_URL。
String resourceUrl = "https://graph.windows.net";
Future<AuthenticationResult> result = context.acquireToken(
resourceUrl,
new ClientCredential(APP_ID, APP_SECRET),
null
);您正在使用Azure AD图形API。您只需要设置Azure Windows 的权限,并且不要忘记授予该权限。
下面的代码需要一个空格和一个头Accept:application/json。
conn.setRequestProperty("Accept","application/json");
conn.setRequestProperty("Authorization", result.get().getAccessTokenType() + " "+ result.get().getAccessToken());测试结果:

https://stackoverflow.com/questions/51660262
复制相似问题