我已经通过访问azure portal并点击App and Settings - >授予我在azure端口注册的所有权限的多租户应用程序。必需的权限 - > Microsoft Graph。 我几乎获得了阅读用户个人资料和设备的所有权限,然后我点击了#34;授予权限"。我遵循生成访问令牌的准则,然后访问图Get Access Without a User
的资源在阅读了stackoverflow https://jwt.ms/上发布的早期类似问题的链接后,我在Microsoft Graph 401 Unauthorized with access token检查了生成的令牌。
在令牌检查上,它给了我以下信息: -
"roles": [
"Device.ReadWrite.All",
"Member.Read.Hidden",
"Domain.ReadWrite.All",
"Application.ReadWrite.OwnedBy",
"Application.ReadWrite.All"
],
我在早些时候Unable to access users device in Microsoft Intune using Microsoft Graph API发布了我发布的问题,我们需要app +用户凭据。但我遵循的过程使管理员授予我的应用程序的权限。
当我尝试使用以下代码使用生成的令牌时: -
user_device_info_url = new URL("https://graph.microsoft.com/v1.0/me/");
intune_connection = ( HttpURLConnection )user_device_info_url.openConnection();
intune_connection.setDoInput(true);
intune_connection.setDoOutput(true);
intune_connection.setUseCaches(false);
intune_connection.setRequestMethod("GET");
intune_connection.setRequestProperty("Authorization", "Bearer "+ token);
intune_connection.setRequestProperty("Accept","application/json");
intune_connection.connect();
payload = new BufferedReader(new InputStreamReader( intune_connection.getInputStream() ));
String json_payload = null;
String line;
while((line = payload.readLine()) != null) {
json_payload += line;
}
System.out.println(json_payload);
但我正在为上述网址获取未经授权的访问权限401。有什么建议?
当我使用以下代码时,我能够访问除了intune之外的URL。
private String getAccessToken_Single_Tenant() {
String accessToken = "";
try {
ExecutorService service = Executors.newFixedThreadPool(1);
String authorization_url = "https://login.microsoftonline.com/" + Authentication_Constants.TENANT + "/oauth2/authorize/";
AuthenticationContext authContext = new AuthenticationContext(authorization_url, false, service);
ClientCredential clientCred = new ClientCredential(Authentication_Constants.CLIENTID, Authentication_Constants.SECRET);
Future<AuthenticationResult> future = authContext.acquireToken(Authentication_Constants.RESOURCE, clientCred, null);
AuthenticationResult authResult = future.get(); // why the future?
accessToken = authResult.getAccessToken();
} catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
}
return accessToken;
}