Search in sources :

Example 1 with OpenIDException

use of org.openid4java.OpenIDException in project pac4j by pac4j.

the class YahooAuthenticator method validate.

@Override
public void validate(final OpenIdCredentials credentials, final WebContext context) {
    final ParameterList parameterList = credentials.getParameterList();
    final DiscoveryInformation discoveryInformation = credentials.getDiscoveryInformation();
    logger.debug("parameterList: {}", parameterList);
    logger.debug("discoveryInformation: {}", discoveryInformation);
    try {
        // verify the response
        final VerificationResult verification = this.client.getConsumerManager().verify(this.client.computeFinalCallbackUrl(context), parameterList, discoveryInformation);
        // examine the verification result and extract the verified identifier
        final Identifier verified = verification.getVerifiedId();
        if (verified != null) {
            final AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
            logger.debug("authSuccess: {}", authSuccess);
            final YahooOpenIdProfile profile = createProfile(authSuccess);
            profile.setId(verified.getIdentifier());
            logger.debug("profile: {}", profile);
            credentials.setUserProfile(profile);
            return;
        }
    } catch (final OpenIDException e) {
        throw new TechnicalException("OpenID exception", e);
    }
    final String message = "No verifiedId found";
    throw new TechnicalException(message);
}
Also used : YahooOpenIdProfile(org.pac4j.openid.profile.yahoo.YahooOpenIdProfile) Identifier(org.openid4java.discovery.Identifier) TechnicalException(org.pac4j.core.exception.TechnicalException) VerificationResult(org.openid4java.consumer.VerificationResult) OpenIDException(org.openid4java.OpenIDException) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) AuthSuccess(org.openid4java.message.AuthSuccess) ParameterList(org.openid4java.message.ParameterList)

Example 2 with OpenIDException

use of org.openid4java.OpenIDException in project pac4j by pac4j.

the class YahooRedirectActionBuilder method redirect.

@Override
public RedirectAction redirect(final WebContext context) {
    try {
        // perform discovery on the user-supplied identifier
        final List discoveries = this.client.getConsumerManager().discover(YAHOO_GENERIC_USER_IDENTIFIER);
        // attempt to associate with the OpenID provider
        // and retrieve one service endpoint for authentication
        final DiscoveryInformation discoveryInformation = this.client.getConsumerManager().associate(discoveries);
        // save discovery information in session
        context.getSessionStore().set(context, this.client.getDiscoveryInformationSessionAttributeName(), discoveryInformation);
        // create authentication request to be sent to the OpenID provider
        final AuthRequest authRequest = this.client.getConsumerManager().authenticate(discoveryInformation, this.client.computeFinalCallbackUrl(context));
        // create fetch request for attributes
        final FetchRequest fetchRequest = getFetchRequest();
        if (fetchRequest != null) {
            authRequest.addExtension(fetchRequest);
        }
        final String redirectionUrl = authRequest.getDestinationUrl(true);
        logger.debug("redirectionUrl: {}", redirectionUrl);
        return RedirectAction.redirect(redirectionUrl);
    } catch (final OpenIDException e) {
        throw new TechnicalException("OpenID exception", e);
    }
}
Also used : AuthRequest(org.openid4java.message.AuthRequest) TechnicalException(org.pac4j.core.exception.TechnicalException) OpenIDException(org.openid4java.OpenIDException) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) FetchRequest(org.openid4java.message.ax.FetchRequest) List(java.util.List)

Aggregations

OpenIDException (org.openid4java.OpenIDException)2 DiscoveryInformation (org.openid4java.discovery.DiscoveryInformation)2 TechnicalException (org.pac4j.core.exception.TechnicalException)2 List (java.util.List)1 VerificationResult (org.openid4java.consumer.VerificationResult)1 Identifier (org.openid4java.discovery.Identifier)1 AuthRequest (org.openid4java.message.AuthRequest)1 AuthSuccess (org.openid4java.message.AuthSuccess)1 ParameterList (org.openid4java.message.ParameterList)1 FetchRequest (org.openid4java.message.ax.FetchRequest)1 YahooOpenIdProfile (org.pac4j.openid.profile.yahoo.YahooOpenIdProfile)1