private PFAuthTokenResponse parseAccessTokenResponse(String token) { PFAuthTokenResponse authTokenResponse = PFAuthTokenResponse.parseAuthTokenResponse(token); AuthToken tk = AuthToken.parse(token); assert tk != null; if (authTokenResponse.authToken == null && tk.getEmail() != null) { // Then we've received an authtoken (instead of an authtokenresponse), so // create the response authTokenResponse = new PFAuthTokenResponse(); authTokenResponse.success = true; authTokenResponse.errorCode = 200; authTokenResponse.authToken = tk; } return authTokenResponse; }
private Observable<PFAuthTokenResponse> getAuthTokenResponse(String url) { return subscribeIoObserveImmediate( Observable.create( subscriber -> { try { Timber.d("Getting AuthToken for with URL: %s ", url); String pfToken = PFNetworkManager.doPinnedGetForUrl(url); Timber.d("AuthToken response received. Token: %s", pfToken); subscriber.onNext(parseAccessTokenResponse(pfToken)); } catch (Exception e) { Timber.e(e, "Login failed with exception: %s", e.getMessage()); PFAuthTokenResponse response = new PFAuthTokenResponse(); response.exception = e; subscriber.onNext(response); } subscriber.onCompleted(); })); }