Search in sources :

Example 1 with AuthorizationCodeRequest

use of net.petafuel.styx.core.xs2a.oauth.http.AuthorizationCodeRequest in project styx by petafuel.

the class OAuthCallbackProcessor method handleSuccessfulOAuth2.

/**
 * This will retrieve and save the access_token an other oauth related data from an ASPSP into the styx system
 *
 * @param code  oauth query param
 * @param state oauth query param
 * @param path  redirect path
 * @return whether we were able to retrieve the access_token successfully
 */
private static boolean handleSuccessfulOAuth2(String code, String state, String path) {
    OAuthService service = new OAuthService();
    try {
        OAuthSession stored = PersistentOAuthSession.getByState(state);
        AuthorizationCodeRequest request = new AuthorizationCodeRequest(code, stored.getCodeVerifier());
        request.setRedirectUri(request.getRedirectUri() + path);
        request.setJsonBody(false);
        OAuthSession authorized = service.tokenRequest(stored.getTokenEndpoint(), request);
        authorized.setState(state);
        PersistentOAuthSession.update(authorized);
        LOG.info("Successfully received callback from ASPSP for OAuthSession state={}", stored.getState());
        return true;
    } catch (Exception e) {
        LOG.error(e);
        return false;
    }
}
Also used : AuthorizationCodeRequest(net.petafuel.styx.core.xs2a.oauth.http.AuthorizationCodeRequest) OAuthService(net.petafuel.styx.core.xs2a.oauth.OAuthService) PersistentOAuthSession(net.petafuel.styx.core.persistence.layers.PersistentOAuthSession) OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException) PersistenceEmptyResultSetException(net.petafuel.styx.core.persistence.PersistenceEmptyResultSetException) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)

Aggregations

BankLookupFailedException (net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)1 BankNotFoundException (net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)1 PersistenceEmptyResultSetException (net.petafuel.styx.core.persistence.PersistenceEmptyResultSetException)1 PersistentOAuthSession (net.petafuel.styx.core.persistence.layers.PersistentOAuthSession)1 OAuthService (net.petafuel.styx.core.xs2a.oauth.OAuthService)1 OAuthSession (net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession)1 AuthorizationCodeRequest (net.petafuel.styx.core.xs2a.oauth.http.AuthorizationCodeRequest)1