Java Code Examples for com.github.scribejava.core.model.OAuth2AccessToken#getAccessToken()

The following examples show how to use com.github.scribejava.core.model.OAuth2AccessToken#getAccessToken() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OAuthManagerProviders.java    From react-native-oauth with MIT License 6 votes vote down vote up
static public OAuthRequest getRequestForProvider(
  final String providerName,
  final Verb httpVerb,
  final OAuth2AccessToken oa2token,
  final URL url,
  final HashMap<String,Object> cfg,
  @Nullable final ReadableMap params
) {
  final OAuth20Service service =
      OAuthManagerProviders.getApiFor20Provider(providerName, cfg, null, null);

  OAuthConfig config = service.getConfig();
  OAuthRequest request = new OAuthRequest(httpVerb, url.toString(), config);
  String token = oa2token.getAccessToken();

  request = OAuthManagerProviders.addParametersToRequest(request, token, params);

  //
  Log.d(TAG, "Making request for " + providerName + " to add token " + token);
  // Need a way to standardize this, but for now
  if (providerName.equalsIgnoreCase("slack")) {
    request.addParameter("token", token);
  }

  return request;
}
 
Example 2
Source File: MollieConnectManager.java    From alf.io with GNU General Public License v3.0 6 votes vote down vote up
@Override
public AccessTokenResponseDetails storeConnectedAccountId(String code, int organizationId) {
    try {
        ConfigurationLevel configurationLevel = ConfigurationLevel.organization(organizationId);
        var options = configurationManager.getFor(Set.of(MOLLIE_API_KEY, MOLLIE_CONNECT_CLIENT_ID, MOLLIE_CONNECT_CLIENT_SECRET, MOLLIE_CONNECT_CALLBACK, BASE_URL), configurationLevel);
        OAuth20Service service = new ServiceBuilder(options.get(MOLLIE_CONNECT_CLIENT_ID).getRequiredValue())
            .apiSecret(options.get(MOLLIE_CONNECT_CLIENT_SECRET).getRequiredValue())
            .callback(options.get(MOLLIE_CONNECT_CALLBACK).getRequiredValue())
            .build(new MollieConnectApi());
        OAuth2AccessToken accessTokenResponse = service.getAccessToken(code);
        var refreshToken = accessTokenResponse.getRefreshToken();
        if(refreshToken != null) {
            //var mollieProfileId = retrieveProfileId(accessTokenResponse.getAccessToken());
            configurationManager.saveConfig(Configuration.from(organizationId, MOLLIE_CONNECT_REFRESH_TOKEN), refreshToken);
            //configurationManager.saveConfig(Configuration.from(organizationId, MOLLIE_PROFILE_ID), mollieProfileId);
        }
        return new AccessTokenResponseDetails(accessTokenResponse.getAccessToken(), refreshToken, null, true);
    } catch (Exception e) {
        log.warn("Got exception while retrieving access token", e);
        return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
    }
}
 
Example 3
Source File: MollieConnectManager.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
public AccessTokenResponseDetails refreshAccessToken(Map<ConfigurationKeys, MaybeConfiguration> options) {
    try {
        OAuth20Service service = new ServiceBuilder(options.get(MOLLIE_CONNECT_CLIENT_ID).getRequiredValue())
            .apiSecret(options.get(MOLLIE_CONNECT_CLIENT_SECRET).getRequiredValue())
            .callback(options.get(MOLLIE_CONNECT_CALLBACK).getRequiredValue())
            .build(new MollieConnectApi());
        String refreshToken = options.get(MOLLIE_CONNECT_REFRESH_TOKEN).getRequiredValue();
        OAuth2AccessToken accessTokenResponse = service.refreshAccessToken(refreshToken);
        return new AccessTokenResponseDetails(accessTokenResponse.getAccessToken(), refreshToken, null, true);
    } catch (Exception e) {
        log.warn("Got exception while retrieving access token", e);
        return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
    }
}
 
Example 4
Source File: OAuthManagerModule.java    From react-native-oauth with MIT License 4 votes vote down vote up
private WritableMap accessTokenResponse(
  final String providerName,
  final HashMap<String,Object> cfg,
  final OAuth2AccessToken accessToken,
  final String oauthVersion
) {
  WritableMap resp = Arguments.createMap();
  WritableMap response = Arguments.createMap();

  resp.putString("status", "ok");
  resp.putBoolean("authorized", true);
  resp.putString("provider", providerName);

  String uuid = accessToken.getParameter("user_id");
  response.putString("uuid", uuid);
  
  WritableMap credentials = Arguments.createMap();
  Log.d(TAG, "Credential raw response: " + accessToken.getRawResponse());
  
  credentials.putString("accessToken", accessToken.getAccessToken());
  String authHeader;

  String tokenType = accessToken.getTokenType();
  if (tokenType == null) {
    tokenType = "Bearer";
  }
  
  String scope = accessToken.getScope();
  if (scope == null) {
    scope = (String) cfg.get("scopes");
  }

  String clientID = (String) cfg.get("client_id");
  String idToken = accessToken.getParameter("id_token");

  authHeader = tokenType + " " + accessToken.getAccessToken();
  credentials.putString("authorizationHeader", authHeader);
  credentials.putString("type", tokenType);
  credentials.putString("scopes", scope);
  credentials.putString("clientID", clientID);
  credentials.putString("idToken", idToken);
  response.putMap("credentials", credentials);

  resp.putMap("response", response);

  return resp;
}
 
Example 5
Source File: Network.java    From mirror with MIT License 4 votes vote down vote up
/**
 * Creates a new access token by wrapping a {@link OAuth2AccessToken}.
 */
public AccessToken(OAuth2AccessToken accessToken, long refreshTime) {
  this(accessToken.getAccessToken(), accessToken.getExpiresIn(), accessToken.getRefreshToken(),
      refreshTime);
}