我不知道如何使用adal4j库获取没有用户名和密码的令牌。我有这段代码:
public class GetToken implements AuthenticationCallback {
public static void main(String[] args) {
// TODO Auto-generated method stub
String resource = "resource";
String redirectUrl = "redirecturl";
String authority = "https://login.microsoftonline.com/common/";
ExecutorService executor = null;
ClientAssertion clientId = new ClientAssertion("my-client-id");
AuthenticationCallback callback;
// Authenticate the registered application with Azure Active Directory.
AuthenticationContext authContext;
try {
authContext = new AuthenticationContext(authority, false,executor);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Future <AuthenticationResult> result = authContext.acquireToken(resource, clientId, callback);
}
@Override
public void onSuccess(AuthenticationResult result) {
// TODO Auto-generated method stub
}
@Override
public void onFailure(Throwable exc) {
// TODO Auto-generated method stub
}
}
而且我不知道如何获得令牌......
答案 0 :(得分:0)
查看 getAccessToke()方法。这是您正在寻找的内容:
ExecutorService executor = Executors.newFixedThreadPool(1);
希望这有帮助!
答案 1 :(得分:-1)
您将收到IllegalArgumentException,因为传递给AuthenticationContext的Executor服务为null。你能分享抛出的异常吗?