【问题标题】:How can I define AuthenticationCallback when trying to access access token from refresh token in Adal4j?尝试从 Adal4j 中的刷新令牌访问访问令牌时如何定义 AuthenticationCallback?
【发布时间】:2016-12-22 23:46:25
【问题描述】:

我正在使用 Adal4j J​​ava 库。我已经有一个刷新令牌,但想根据刷新令牌获取访问令牌。

我有以下代码,但我不知道如何定义 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 ?

【问题讨论】:

    标签: azure office365api azure-active-directory azure-ad-graph-api adal4j


    【解决方案1】:

    我们需要实现 AuthenticationCallback 接口。这是一个代码示例供您参考:

    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 应用程序集成的有用文档。

    【讨论】:

    • 谢谢@Fei。所以这意味着,我应该在成功时获取令牌?
    • 是的,你是对的。我们需要根据成功或失败的结果来处理我们需要的响应。
    • 这是预期的。首先refresh_token只用于更新access_token,与access_token不同。其次,当我们使用 refresh_token 更新 access_token 时,Azure Active Directory 会发出一个新的令牌。您可以从here 解码access_token。您应该看到声明 iat、nbf、exp 是不同的。有关 Azure AD 颁发的令牌中的详细声明,请参阅 here。
    • 要同时支持 Microsoft 帐户和 Azure AD 帐户,我们需要使用 Azure AD V2.0 端点。详情请参考here。
    • @WowBow 我已经回复了那个帖子,请告诉我它是否有帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 2020-07-12
    • 2020-11-09
    • 2018-09-25
    • 2019-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多