Search in sources :

Example 41 with JwtDecoder

use of org.springframework.security.oauth2.jwt.JwtDecoder in project spring-security by spring-projects.

the class ReactiveOidcIdTokenDecoderFactory method createDecoder.

@Override
public ReactiveJwtDecoder createDecoder(ClientRegistration clientRegistration) {
    Assert.notNull(clientRegistration, "clientRegistration cannot be null");
    return this.jwtDecoders.computeIfAbsent(clientRegistration.getRegistrationId(), (key) -> {
        NimbusReactiveJwtDecoder jwtDecoder = buildDecoder(clientRegistration);
        jwtDecoder.setJwtValidator(this.jwtValidatorFactory.apply(clientRegistration));
        Converter<Map<String, Object>, Map<String, Object>> claimTypeConverter = this.claimTypeConverterFactory.apply(clientRegistration);
        if (claimTypeConverter != null) {
            jwtDecoder.setClaimSetConverter(claimTypeConverter);
        }
        return jwtDecoder;
    });
}
Also used : NimbusReactiveJwtDecoder(org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 42 with JwtDecoder

use of org.springframework.security.oauth2.jwt.JwtDecoder in project spring-security by spring-projects.

the class OidcAuthorizationCodeReactiveAuthenticationManager method createOidcToken.

private Mono<OidcIdToken> createOidcToken(ClientRegistration clientRegistration, OAuth2AccessTokenResponse accessTokenResponse) {
    ReactiveJwtDecoder jwtDecoder = this.jwtDecoderFactory.createDecoder(clientRegistration);
    String rawIdToken = (String) accessTokenResponse.getAdditionalParameters().get(OidcParameterNames.ID_TOKEN);
    // @formatter:off
    return jwtDecoder.decode(rawIdToken).map((jwt) -> new OidcIdToken(jwt.getTokenValue(), jwt.getIssuedAt(), jwt.getExpiresAt(), jwt.getClaims()));
// @formatter:on
}
Also used : ReactiveJwtDecoder(org.springframework.security.oauth2.jwt.ReactiveJwtDecoder) OidcIdToken(org.springframework.security.oauth2.core.oidc.OidcIdToken)

Aggregations

Test (org.junit.jupiter.api.Test)37 NimbusJwtDecoder (org.springframework.security.oauth2.jwt.NimbusJwtDecoder)34 JwtDecoder (org.springframework.security.oauth2.jwt.JwtDecoder)33 Jwt (org.springframework.security.oauth2.jwt.Jwt)9 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)6 Map (java.util.Map)4 ApplicationContext (org.springframework.context.ApplicationContext)4 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)4 RSAKey (com.nimbusds.jose.jwk.RSAKey)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Base64 (java.util.Base64)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 BDDMockito.given (org.mockito.BDDMockito.given)3 Mockito.mock (org.mockito.Mockito.mock)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 Converter (org.springframework.core.convert.converter.Converter)3 HttpStatus (org.springframework.http.HttpStatus)3 JWKSource (com.nimbusds.jose.jwk.source.JWKSource)2