Search in sources :

Example 11 with HttpCommunicationException

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);
    }
}
Also used : OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) TechnicalException(org.pac4j.core.exception.TechnicalException) HttpCommunicationException(org.pac4j.core.exception.HttpCommunicationException) OAuthException(com.github.scribejava.core.exceptions.OAuthException) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with HttpCommunicationException

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);
}
Also used : OAuth2AccessToken(com.github.scribejava.core.model.OAuth2AccessToken) HttpCommunicationException(org.pac4j.core.exception.HttpCommunicationException) OAuth20Credentials(org.pac4j.oauth.credentials.OAuth20Credentials) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

HttpCommunicationException (org.pac4j.core.exception.HttpCommunicationException)12 IOException (java.io.IOException)10 ExecutionException (java.util.concurrent.ExecutionException)10 OAuthException (com.github.scribejava.core.exceptions.OAuthException)4 OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)3 OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)3 DefaultApi20 (com.github.scribejava.core.builder.api.DefaultApi20)2 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)2 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)2 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)2 TechnicalException (org.pac4j.core.exception.TechnicalException)2 OAuth10Credentials (org.pac4j.oauth.credentials.OAuth10Credentials)2 OAuth20Credentials (org.pac4j.oauth.credentials.OAuth20Credentials)2 OAuthCredentialsException (org.pac4j.oauth.exception.OAuthCredentialsException)2 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)1 Response (com.github.scribejava.core.model.Response)1 UserProfile (org.pac4j.core.profile.UserProfile)1 OAuth20Configuration (org.pac4j.oauth.config.OAuth20Configuration)1 OAuth10ProfileDefinition (org.pac4j.oauth.profile.definition.OAuth10ProfileDefinition)1 OAuth20ProfileDefinition (org.pac4j.oauth.profile.definition.OAuth20ProfileDefinition)1