Search in sources :

Example 1 with RequestToken

use of com.meisolsson.githubsdk.model.request.RequestToken in project gh4a by slapperwan.

the class Github4AndroidActivity method handleIntent.

private boolean handleIntent(Intent intent) {
    Uri data = intent.getData();
    if (data != null && data.getScheme().equals(CALLBACK_URI.getScheme()) && data.getHost().equals(CALLBACK_URI.getHost())) {
        OAuthService service = ServiceGenerator.createAuthService();
        RequestToken request = RequestToken.builder().clientId(BuildConfig.CLIENT_ID).clientSecret(BuildConfig.CLIENT_SECRET).code(data.getQueryParameter(PARAM_CODE)).build();
        service.getToken(request).map(ApiHelpers::throwOnFailure).flatMap(token -> {
            UserService userService = ServiceFactory.get(UserService.class, true, null, token.accessToken(), null);
            Single<User> userSingle = userService.getUser().map(ApiHelpers::throwOnFailure);
            return Single.zip(Single.just(token), userSingle, (t, user) -> Pair.create(t.accessToken(), user));
        }).compose(RxUtils::doInBackground).subscribe(pair -> onLoginFinished(pair.first, pair.second), this::handleLoadFailure);
        return true;
    }
    return false;
}
Also used : OAuthService(com.meisolsson.githubsdk.service.OAuthService) User(com.meisolsson.githubsdk.model.User) UserService(com.meisolsson.githubsdk.service.users.UserService) RequestToken(com.meisolsson.githubsdk.model.request.RequestToken) ApiHelpers(com.gh4a.utils.ApiHelpers) Uri(android.net.Uri)

Example 2 with RequestToken

use of com.meisolsson.githubsdk.model.request.RequestToken in project PocketHub by pockethub.

the class LoginActivity method onUserLoggedIn.

private void onUserLoggedIn(Uri uri) {
    if (uri != null && uri.getScheme().equals(getString(R.string.github_oauth_scheme))) {
        openLoadingDialog();
        String code = uri.getQueryParameter("code");
        RequestToken request = RequestToken.builder().clientId(clientId).clientSecret(secret).redirectUri(redirectUri).code(code).build();
        ServiceGenerator.createAuthService().getToken(request).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).as(AutoDisposeUtils.bindToLifecycle(this)).subscribe(response -> {
            GitHubToken token = response.body();
            if (token.accessToken() != null) {
                endAuth(token.accessToken(), token.scope());
            } else if (token.error() != null) {
                Toast.makeText(this, token.error(), Toast.LENGTH_LONG).show();
                progressDialog.dismiss();
            }
        }, Throwable::printStackTrace);
    }
}
Also used : RequestToken(com.meisolsson.githubsdk.model.request.RequestToken) GitHubToken(com.meisolsson.githubsdk.model.GitHubToken)

Aggregations

RequestToken (com.meisolsson.githubsdk.model.request.RequestToken)2 Uri (android.net.Uri)1 ApiHelpers (com.gh4a.utils.ApiHelpers)1 GitHubToken (com.meisolsson.githubsdk.model.GitHubToken)1 User (com.meisolsson.githubsdk.model.User)1 OAuthService (com.meisolsson.githubsdk.service.OAuthService)1 UserService (com.meisolsson.githubsdk.service.users.UserService)1