我可以使用java中的电子邮件和密码获取访问令牌吗?我看到很多使用.NET库的例子,但没有任何关于java的例子,我尝试了以下内容: -
private static String getAccess_Token() {
AuthenticationContext authContext = null;
AuthenticationResult authResult = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
String url = "https://login.microsoftonline.com/" + Authentication_Constants.TENANT + "/oauth2/authorize";
authContext = new AuthenticationContext(url, false, service);
Future<AuthenticationResult> future = authContext.acquireToken(Authentication_Constants.RESOURCE, Authentication_Constants.CLIENTID,
Authentication_Constants.EMAIL, Authentication_Constants.Passowrd, null);
authResult = future.get();
/* System.out.println("get access token: \n" + authResult.getAccessToken());
System.out.println("get refresh token: \n" + authResult.getRefreshToken());*/
return authResult.getAccessToken();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
但它给我一个例外
com.microsoft.aad.adal4j.AuthenticationException: {"error_description":"AADSTS70002: The request body must contain the following parameter: 'client_secret or client_assertion'.
是否有其他API可以让我这样做?