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();
}
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;
}
Aggregations