Search in sources :

Example 1 with AccessTokenResponseDetails

use of alfio.util.oauth2.AccessTokenResponseDetails in project alf.io by alfio-event.

the class StripeConnectManager method storeConnectedAccountId.

@Override
public AccessTokenResponseDetails storeConnectedAccountId(String code, int organizationId) {
    try {
        String clientSecret = baseStripeManager.getSystemSecretKey();
        OAuth20Service service = new ServiceBuilder(clientSecret).apiSecret(clientSecret).build(new StripeConnectApi());
        Map<String, String> token = Json.fromJson(service.getAccessToken(code).getRawResponse(), new TypeReference<>() {
        });
        String accountId = token.get("stripe_user_id");
        if (accountId != null) {
            configurationManager.saveConfig(Configuration.from(organizationId, ConfigurationKeys.STRIPE_CONNECTED_ID), accountId);
        }
        return new AccessTokenResponseDetails(accountId, null, token.get("error_message"), accountId != null);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        log.warn("Request interrupted while retrieving access token", e);
        return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
    } catch (Exception e) {
        log.error("cannot retrieve account ID", e);
        return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
    }
}
Also used : AccessTokenResponseDetails(alfio.util.oauth2.AccessTokenResponseDetails) OAuth20Service(com.github.scribejava.core.oauth.OAuth20Service) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder)

Example 2 with AccessTokenResponseDetails

use of alfio.util.oauth2.AccessTokenResponseDetails in project alf.io by alfio-event.

the class MollieConnectManager method refreshAccessToken.

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 (InterruptedException e) {
        Thread.currentThread().interrupt();
        log.warn("Request interrupted while retrieving access token", e);
        return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
    } catch (Exception e) {
        log.warn("Got exception while retrieving access token", e);
        return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
    }
}
Also used : OAuth2AccessToken(com.github.scribejava.core.model.OAuth2AccessToken) AccessTokenResponseDetails(alfio.util.oauth2.AccessTokenResponseDetails) OAuth20Service(com.github.scribejava.core.oauth.OAuth20Service) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder)

Example 3 with AccessTokenResponseDetails

use of alfio.util.oauth2.AccessTokenResponseDetails in project alf.io by alfio-event.

the class MollieConnectManager method storeConnectedAccountId.

@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) {
            configurationManager.saveConfig(Configuration.from(organizationId, MOLLIE_CONNECT_REFRESH_TOKEN), refreshToken);
        }
        return new AccessTokenResponseDetails(accessTokenResponse.getAccessToken(), refreshToken, null, true);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        log.warn("Request interrupted while retrieving access token", e);
        return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
    } catch (Exception e) {
        log.warn("Got exception while retrieving access token", e);
        return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
    }
}
Also used : ConfigurationLevel(alfio.manager.system.ConfigurationLevel) OAuth2AccessToken(com.github.scribejava.core.model.OAuth2AccessToken) AccessTokenResponseDetails(alfio.util.oauth2.AccessTokenResponseDetails) OAuth20Service(com.github.scribejava.core.oauth.OAuth20Service) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder)

Aggregations

AccessTokenResponseDetails (alfio.util.oauth2.AccessTokenResponseDetails)3 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)3 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)3 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)2 ConfigurationLevel (alfio.manager.system.ConfigurationLevel)1