我正在使用 Adal4j Java 库。我已经有刷新 token ,但希望根据刷新 token 获取访问 token 。
我有以下代码,但我不知道如何定义 AuthenticationCallback
ExecutorService service = Executors.newFixedThreadPool(1);
AuthenticationContext context = new AuthenticationContext(authority, true, service);
context.acquireTokenByRefreshToken(resultFuture.get().getRefreshToken(), new ClientCredential("8a6....4b6", "J5....EU="), ?????? );
如何定义AuthenticationCallback?
最佳答案
我们需要实现 AuthenticationCallback 接口(interface)。下面是一个代码示例供您引用:
import com.microsoft.aad.adal4j.AuthenticationCallback;
import com.microsoft.aad.adal4j.AuthenticationResult;
public class MYAuthenticationCallback implements AuthenticationCallback
{
public void onFailure(Throwable arg0) {
// TODO Auto-generated method stub
}
public void onSuccess(AuthenticationResult arg0) {
// TODO Auto-generated method stub
System.out.println(arg0.getAccessToken());
}
}
Here是有关将 Azure AD 与 Java Web 应用程序集成的有用文档。
关于azure - 当尝试从 Adal4j 中的刷新 token 访问访问 token 时,如何定义 AuthenticationCallback?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41293291/