Answer the question
In order to leave comments, you need to log in
How to work with refresh token correctly?
I need to catch an expired token by sending a refreshToken and get new access_token and refresh_token in return.
Below I have posted the code that I am going to apply. It is not written to the end. Because I do not fully understand everything.
@FormUrlEncoded
@POST("/api/o/token/")
Call<TokenModel> getToken(
@Field("username") String username,
@Field("password") String password,
@Field("client_id") String clientId,
@Field("client_secret") String clientSecret,
@Field("grant_type") String grantType
);
@FormUrlEncoded
@POST("/api/o/token/")
Call<TokenModel> getNewToken(
@Field("refresh_token") String refreshToken,
@Field("client_id") String clientId,
@Field("client_secret") String clientSecret,
@Field("grant_type") String grantType
);
@GET("/api/users/profile")
Call<UserProfile> getProfile();
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(logging)
.addInterceptor(new AccessTokenInterceptor(preferences))
.addInterceptor(new Interceptor() {
@NotNull
@Override
public Response intercept(@NotNull Chain chain) throws IOException {
Request original = chain.request();
Request request = original.newBuilder()
.header("Authorization", ?)
.method(original.method(), original.body())
.build();
Response response = chain.proceed(request);
Log.d("MyApp", "Code : "+response.code());
if (response.code() == 401){
?
return response;
}
return response;
}
})
.build();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question