use of org.wikipedia.login.LoginClient in project apps-android-wikipedia by wikimedia.
the class CsrfTokenClient method getTokenBlocking.
@NonNull
public String getTokenBlocking() throws Throwable {
String token = "";
Service service = cachedService.service(csrfWikiSite);
for (int retry = 0; retry < MAX_RETRIES_OF_LOGIN_BLOCKING; retry++) {
try {
if (retry > 0) {
// Log in explicitly
new LoginClient().loginBlocking(loginWikiSite, AccountUtil.getUserName(), AccountUtil.getPassword(), "");
}
Response<MwQueryResponse> response = service.request().execute();
if (response.body() == null || !response.body().success() || TextUtils.isEmpty(response.body().query().csrfToken())) {
continue;
}
token = response.body().query().csrfToken();
if (AccountUtil.isLoggedIn() && token.equals(ANON_TOKEN)) {
throw new RuntimeException("App believes we're logged in, but got anonymous token.");
}
break;
} catch (Throwable t) {
L.w(t);
}
}
if (TextUtils.isEmpty(token) || token.equals(ANON_TOKEN)) {
throw new IOException("Invalid token, or login failure.");
}
return token;
}
Aggregations