use of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest in project OpenRefine by OpenRefine.
the class GoogleAPIExtension method getTokenFromCode.
public static String getTokenFromCode(ButterflyModule module, HttpServletRequest request) throws IOException {
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();
GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(HTTP_TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, code, redirectUrl).execute();
String tokenAndExpiresInSeconds = response.getAccessToken() + "," + response.getExpiresInSeconds();
return tokenAndExpiresInSeconds;
}
return null;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest 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;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest 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() {
String credentials = gson.toJson(new AuthManager.AccessToken(token));
onSocialAuthSuccess(AuthManager.PROVIDER_GOOGLE, credentials);
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
} else
Toast.makeText(this, R.string.auth_google_error, Toast.LENGTH_LONG).show();
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest in project Android-SDK by Backendless.
the class LoginWithGooglePlusSDKActivity method exchangeAuthTokenOnAccessToken.
private void exchangeAuthTokenOnAccessToken(String gpAuthToken) {
GoogleTokenResponse tokenResponse;
try {
tokenResponse = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), JacksonFactory.getDefaultInstance(), "https://www.googleapis.com/oauth2/v4/token", getString(R.string.gp_WebApp_ClientId), getString(R.string.gp_WebApp_ClientSecret), gpAuthToken, // Specify the same redirect URI that you use with your web
"").execute();
} catch (Exception e) {
Log.e("LoginWithGooglePlus", e.getMessage(), e);
String msg = socialAccountInfo.getText() + "\n" + e.getMessage();
socialAccountInfo.setText(msg);
socialAccountInfo.setTextColor(getColor(android.R.color.holo_red_dark));
return;
}
gpAccessToken = tokenResponse.getAccessToken();
final String msg = socialAccountInfo.getText() + "\n" + "AccessToken: " + gpAccessToken;
this.runOnUiThread(() -> socialAccountInfo.setText(msg));
}
Aggregations