use of org.pac4j.core.exception.HttpCommunicationException in project pac4j by pac4j.
the class OAuth10RedirectionActionBuilder method getRedirectionAction.
@Override
public Optional<RedirectionAction> getRedirectionAction(final WebContext context, final SessionStore sessionStore) {
try {
final var service = (OAuth10aService) this.configuration.buildService(context, client);
final OAuth1RequestToken requestToken;
try {
requestToken = service.getRequestToken();
} catch (final IOException | InterruptedException | ExecutionException e) {
throw new HttpCommunicationException("Error getting token: " + e.getMessage());
}
logger.debug("requestToken: {}", requestToken);
// save requestToken in user session
sessionStore.set(context, configuration.getRequestTokenSessionAttributeName(client.getName()), requestToken);
final var authorizationUrl = service.getAuthorizationUrl(requestToken);
logger.debug("authorizationUrl: {}", authorizationUrl);
return Optional.of(HttpActionHelper.buildRedirectUrlAction(context, authorizationUrl));
} catch (final OAuthException e) {
throw new TechnicalException(e);
}
}
use of org.pac4j.core.exception.HttpCommunicationException in project pac4j by pac4j.
the class OAuth20Authenticator method retrieveAccessToken.
@Override
protected void retrieveAccessToken(final WebContext context, final Credentials credentials) {
var oAuth20Credentials = (OAuth20Credentials) credentials;
// no request token saved in context and no token (OAuth v2.0)
final var code = oAuth20Credentials.getCode();
logger.debug("code: {}", code);
final OAuth2AccessToken accessToken;
try {
accessToken = ((OAuth20Service) this.configuration.buildService(context, client)).getAccessToken(code);
} catch (final IOException | InterruptedException | ExecutionException e) {
throw new HttpCommunicationException("Error getting token:" + e.getMessage());
}
logger.debug("accessToken: {}", accessToken);
oAuth20Credentials.setAccessToken(accessToken);
}
Aggregations