Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k 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 Reply

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();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...