authentication - Android - Retrofit 2 - Authenticator Result -
i'm trying use retrofit (2.0.0-beta3), when using authenticator add token, can't seem data synchronous call. our logging on back-end shows lot of login attempts, can't data body add header.
public static class tokenauthenticator implements authenticator { @override public request authenticate(route route, response response) throws ioexception { // refresh access_token using synchronous api request userservice userservice = createservice(userservice.class); call<session> call = userservice.emaillogin(new credentials("handle", "pass")); // call made correctly, shows on back-end. session body = call.execute().body(); // line never hit. logger.d("session token: " + body.token); // add new header rejected request , retry return response.request().newbuilder() .header("auth-token", body.token) .build(); } }
i'm not sure on why it's not printing out. tips on how solve issue appreciated, taking time help.
these sources i've been reading on how implement retrofit.
using authenticator:
making synchronous calls retrofit 2:
i have similar authenticator , works 2.0.0-beta2.
if lots of login attempts authenticator, suggest make sure when make synchronous call, not using authenticator call. end in loop, if "emaillogin" fails.
also recommend adding logginginterceptor see trafic server: logging retrofit 2
Comments
Post a Comment