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