I'm having a authenticator attached to a Okhttp3 client which is getting called successfully when a 401 response comes. Within the authenticator, I want to authenticate the user with refresh token. I'm using IBM AppId for authentication.
private Authenticator getAuthenticator() {
return new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
// code to authenticate with refresh token
return null;
}
};
}
And I've the following code to authenticate with refresh token:
AppID.getInstance().signinWithRefreshToken(getApplicationContext(), refreshTokenString, new AuthorizationListener() {
@Override
public void onAuthorizationFailure(AuthorizationException exception) {
//Exception occurred
}
@Override
public void onAuthorizationCanceled() {
//Authentication canceled by the user
}
@Override
public void onAuthorizationSuccess(AccessToken accessToken, IdentityToken identityToken, RefreshToken refreshToken) {
//User authenticated
}
});
Now as you can see that it is asynchronous request and I cannot put this code inside the authenticator because the method will return before the calling onAuthorizationSuccess(). Also, AppId doesn't have synchronous type of request which I can use. Can you please point me how do I use this code within the authenticator class. Please help me with this issue.