我正在编程以在Java中生成令牌。我从git中获取了AADL库。
而不是博客中为.net建议的代码我使用以下代码来代替java, String token = null; String tenant =“my_tenant”;
String authority = "https://login.windows.net/"+tenant+"/oauth2/authorize";
ExecutorService service = null;
service=Executors.newFixedThreadPool(1);
try {
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false, service);
String certfile = "filapath/mycert.pfx";
InputStream pkcs12Certificate=new FileInputStream(certfile);
AsymmetricKeyCredential credential = AsymmetricKeyCredential.create("client_id", pkcs12Certificate,"password");
System.out.println("X509 is fine!");
Future<AuthenticationResult> future=authenticationContext.acquireToken("https://outlook.office365.com", credential, null);
System.out.println("Token Received"+future.get().getAccessToken());
token=future.get().getAccessToken();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但是当我使用令牌获取邮件REST APi时,这个过程得到了HTTP 401错误。 我在指定X509证书密钥时做错了什么? 或其他什么?