Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How access shared pref to save new token inside ApiInterceptor #71

Open
amitkumarverma-android opened this issue May 1, 2018 · 0 comments

Comments

@amitkumarverma-android
Copy link

@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
    final Request request = chain.request();
    final Request.Builder builder = request.newBuilder();
    String apiAuthType = request.header(ApiHeader.API_AUTH_TYPE);
    if (apiAuthType == null) {
        apiAuthType = ApiHeader.PROTECTED_API;
    }

    switch (apiAuthType) {
        case ApiHeader.PROTECTED_API:
            builder.addHeader(ApiHeader.HEADER_PARAM_API_KEY, mApiHeader.getmApiKey());
            builder.addHeader(ApiHeader.HEADER_PARAM_AUTHRIZATION, mApiHeader.getmTokenType() + " " + mApiHeader.getmAccessToken());
            builder.addHeader(ApiHeader.HEADER_PARAM_REFRESH_TOKEN, mApiHeader.getmRefreshToken());
        case ApiHeader.PUBLIC_API:
        default:
            builder.addHeader(ApiHeader.HEADER_PARAM_API_KEY, mApiHeader.getmApiKey());
    }

    Response response = chain.proceed(builder.build());
    String newAccessToken = response.header("access_token");
    String newRefreshToken = response.header("refresh_token");
    String newTokenType = response.header("token_type");
    if (newAccessToken != null) {

        **//  I want to save data here**
    }
    return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant