Search in sources :

Example 1 with GoogleTokenResponse

use of com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse in project xabber-android by redsolution.

the class BaseLoginActivity method handleSignInResult.

private void handleSignInResult(GoogleSignInResult result) {
    if (result.isSuccess()) {
        GoogleSignInAccount acct = result.getSignInAccount();
        if (acct != null) {
            final String googleAuthCode = acct.getServerAuthCode();
            Application.getInstance().runInBackground(new Runnable() {

                @Override
                public void run() {
                    try {
                        GoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), JacksonFactory.getDefaultInstance(), GOOGLE_TOKEN_SERVER, getString(R.string.SOCIAL_AUTH_GOOGLE_KEY), getString(R.string.SOCIAL_AUTH_GOOGLE_SECRET), googleAuthCode, "").execute();
                        final String token = tokenResponse.getAccessToken();
                        Application.getInstance().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                loginSocial(AuthManager.PROVIDER_GOOGLE, token);
                            }
                        });
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    } else
        Toast.makeText(this, "google error", Toast.LENGTH_LONG).show();
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) GoogleAuthorizationCodeTokenRequest(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GoogleTokenResponse(com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse) IOException(java.io.IOException)

Example 2 with GoogleTokenResponse

use of com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse in project OpenRefine by OpenRefine.

the class GDataExtension method getTokenFromCode.

public static String getTokenFromCode(ButterflyModule module, HttpServletRequest request) throws MalformedURLException {
    String redirectUrl = makeRedirectUrl(module, request);
    StringBuffer fullUrlBuf = request.getRequestURL();
    if (request.getQueryString() != null) {
        fullUrlBuf.append('?').append(request.getQueryString());
    }
    AuthorizationCodeResponseUrl authResponse = new AuthorizationCodeResponseUrl(fullUrlBuf.toString());
    // check for user-denied error
    if (authResponse.getError() != null) {
    // authorization denied...
    } else {
        // request access token using authResponse.getCode()...
        String code = authResponse.getCode();
        try {
            GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(HTTP_TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, code, redirectUrl).execute();
            String token = response.getAccessToken();
            return token;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return null;
}
Also used : GoogleAuthorizationCodeTokenRequest(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest) AuthorizationCodeResponseUrl(com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl) GoogleTokenResponse(com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse) IOException(java.io.IOException)

Aggregations

GoogleAuthorizationCodeTokenRequest (com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest)2 GoogleTokenResponse (com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse)2 IOException (java.io.IOException)2 GoogleSignInAccount (com.google.android.gms.auth.api.signin.GoogleSignInAccount)1 AuthorizationCodeResponseUrl (com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1