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