Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
974 views
in Technique[技术] by (71.8m points)

vue.js - OpenId App Auth Android - Send refreshed access token to vuejs

Hello I am wondering how after calling.

public String performTokenRefresh() {
        final AuthState state = AuthUtils.readAuthState(context, key);
        final AuthorizationService service = new AuthorizationService(context);
        state.performActionWithFreshTokens(service, new AuthState.AuthStateAction() {
            @Override
            public void execute(@Nullable String accessToken, @Nullable String idToken, 
                @Nullable AuthorizationException ex) {
                // TODO
            }

        });
        return state.getAccessToken();
}

it seems by the time the return statement happens the state has not yet updated to contain the new tokenResponse from when the code expires, the accessToken in the execute is up to date only issue is I cant return from that.

Can anyone help me please.

Regards

question from:https://stackoverflow.com/questions/65830178/openid-app-auth-android-send-refreshed-access-token-to-vuejs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Might not be the best way to do it but what I am having to do is

public String performTokenRefresh() {
    AuthState state = AuthUtils.readAuthState(context, key);
    AuthorizationService service = new AuthorizationService(context);
    state.performActionWithFreshTokens(service, new 
    AuthState.AuthStateAction() {
        @Override
        public void execute(@Nullable String accessToken, @Nullable String 
        idToken, @Nullable AuthorizationException ex) {
            updateAuthState(accessToken); // updates the authstate in Shared Preferences
        }

    });
    Thread.sleep(10000); // 10 seconds to work with slow connections

    return AuthUtils.readAuthState(context, key).getAccessToken();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...