Search in sources :

Example 1 with Secret

use of com.nimbusds.oauth2.sdk.auth.Secret in project pac4j by pac4j.

the class OidcProfileCreator method internalInit.

@Override
protected void internalInit() {
    assertNotNull("configuration", configuration);
    // check algorithms
    final List<JWSAlgorithm> metadataAlgorithms = configuration.findProviderMetadata().getIDTokenJWSAlgs();
    CommonHelper.assertTrue(CommonHelper.isNotEmpty(metadataAlgorithms), "There must at least one JWS algorithm supported on the OpenID Connect provider side");
    JWSAlgorithm jwsAlgorithm;
    final JWSAlgorithm preferredAlgorithm = configuration.getPreferredJwsAlgorithm();
    if (metadataAlgorithms.contains(preferredAlgorithm)) {
        jwsAlgorithm = preferredAlgorithm;
    } else {
        jwsAlgorithm = metadataAlgorithms.get(0);
        logger.warn("Preferred JWS algorithm: {} not available. Defaulting to: {}", preferredAlgorithm, jwsAlgorithm);
    }
    if ("none".equals(jwsAlgorithm.getName())) {
        jwsAlgorithm = null;
    }
    final ClientID _clientID = new ClientID(configuration.getClientId());
    final Secret _secret = new Secret(configuration.getSecret());
    // Init IDTokenVerifier
    if (jwsAlgorithm == null) {
        this.idTokenValidator = new IDTokenValidator(configuration.findProviderMetadata().getIssuer(), _clientID);
    } else if (CommonHelper.isNotBlank(configuration.getSecret()) && (JWSAlgorithm.HS256.equals(jwsAlgorithm) || JWSAlgorithm.HS384.equals(jwsAlgorithm) || JWSAlgorithm.HS512.equals(jwsAlgorithm))) {
        this.idTokenValidator = createHMACTokenValidator(jwsAlgorithm, _clientID, _secret);
    } else {
        this.idTokenValidator = createRSATokenValidator(jwsAlgorithm, _clientID);
    }
    this.idTokenValidator.setMaxClockSkew(configuration.getMaxClockSkew());
    defaultProfileDefinition(new OidcProfileDefinition<>());
}
Also used : Secret(com.nimbusds.oauth2.sdk.auth.Secret) ClientID(com.nimbusds.oauth2.sdk.id.ClientID) JWSAlgorithm(com.nimbusds.jose.JWSAlgorithm) IDTokenValidator(com.nimbusds.openid.connect.sdk.validators.IDTokenValidator)

Aggregations

JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)1 Secret (com.nimbusds.oauth2.sdk.auth.Secret)1 ClientID (com.nimbusds.oauth2.sdk.id.ClientID)1 IDTokenValidator (com.nimbusds.openid.connect.sdk.validators.IDTokenValidator)1