Search in sources :

Example 1 with OIDCException

use of org.obiba.oidc.OIDCException in project obiba-commons by obiba.

the class OIDCAuthenticationRequestFactory method create.

public AuthenticationRequest create(OIDCConfiguration configuration) {
    OIDCProviderMetadata providerMetadata = configuration.findProviderMetaData();
    // Generate random state string for pairing the response to the request
    State state = new State();
    // Generate nonce
    Nonce nonce = configuration.isUseNonce() ? new Nonce() : null;
    // Specify scope
    Scope scope = Scope.parse(configuration.getScope());
    AuthenticationRequest authenticationRequest = null;
    try {
        authenticationRequest = new AuthenticationRequest(providerMetadata.getAuthorizationEndpointURI(), new ResponseType(ResponseType.Value.CODE), scope, new ClientID(configuration.getClientId()), new URI(callbackURI), state, nonce);
    } catch (URISyntaxException e) {
        throw new OIDCException(e);
    }
    return authenticationRequest;
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) Scope(com.nimbusds.oauth2.sdk.Scope) State(com.nimbusds.oauth2.sdk.id.State) OIDCException(org.obiba.oidc.OIDCException) ClientID(com.nimbusds.oauth2.sdk.id.ClientID) OIDCProviderMetadata(com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata) URISyntaxException(java.net.URISyntaxException) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest) URI(java.net.URI) ResponseType(com.nimbusds.oauth2.sdk.ResponseType)

Example 2 with OIDCException

use of org.obiba.oidc.OIDCException in project obiba-commons by obiba.

the class OIDCTokenValidator method validate.

public IDTokenClaimsSet validate(final JWT idToken, final Nonce expectedNonce) throws BadJOSEException, JOSEException {
    BadJOSEException badJOSEException = null;
    JOSEException joseException = null;
    for (final IDTokenValidator idTokenValidator : idTokenValidators) {
        try {
            return idTokenValidator.validate(idToken, expectedNonce);
        } catch (final BadJOSEException e1) {
            badJOSEException = e1;
        } catch (final JOSEException e2) {
            joseException = e2;
        }
    }
    if (badJOSEException != null) {
        throw badJOSEException;
    } else if (joseException != null) {
        throw joseException;
    } else {
        throw new OIDCException("Unable to validate the ID token");
    }
}
Also used : BadJOSEException(com.nimbusds.jose.proc.BadJOSEException) OIDCException(org.obiba.oidc.OIDCException) JOSEException(com.nimbusds.jose.JOSEException) BadJOSEException(com.nimbusds.jose.proc.BadJOSEException) IDTokenValidator(com.nimbusds.openid.connect.sdk.validators.IDTokenValidator)

Aggregations

OIDCException (org.obiba.oidc.OIDCException)2 JOSEException (com.nimbusds.jose.JOSEException)1 BadJOSEException (com.nimbusds.jose.proc.BadJOSEException)1 ResponseType (com.nimbusds.oauth2.sdk.ResponseType)1 Scope (com.nimbusds.oauth2.sdk.Scope)1 ClientID (com.nimbusds.oauth2.sdk.id.ClientID)1 State (com.nimbusds.oauth2.sdk.id.State)1 AuthenticationRequest (com.nimbusds.openid.connect.sdk.AuthenticationRequest)1 Nonce (com.nimbusds.openid.connect.sdk.Nonce)1 OIDCProviderMetadata (com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata)1 IDTokenValidator (com.nimbusds.openid.connect.sdk.validators.IDTokenValidator)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1