Skip to content

Commit 167dc93

Browse files
committed
Add Decoder
1 parent 3b66027 commit 167dc93

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main/java/net/coderic/core/api/config/SecurityConfiguration.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package net.coderic.core.api.config;
22

3+
import com.nimbusds.jose.JOSEException;
4+
import com.nimbusds.jose.jwk.JWK;
5+
import com.nimbusds.jose.jwk.JWKSet;
6+
import com.nimbusds.jose.jwk.RSAKey;
37
import org.springframework.beans.factory.annotation.Value;
48
import org.springframework.context.annotation.Bean;
59
import org.springframework.context.annotation.Configuration;
@@ -22,6 +26,11 @@
2226
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
2327

2428
import javax.crypto.spec.SecretKeySpec;
29+
import java.io.IOException;
30+
import java.net.URL;
31+
import java.security.PublicKey;
32+
import java.security.interfaces.RSAPublicKey;
33+
import java.text.ParseException;
2534
import java.util.Arrays;
2635

2736
@Configuration
@@ -133,9 +142,20 @@ private JwtAuthenticationConverter jwtAuthenticationConverter() {
133142
return converter;
134143
}
135144
@Bean
145+
public JwtDecoder jwtDecoder() throws IOException, JOSEException, ParseException {
146+
// URL del JWKS de Auth0
147+
String jwkSetUri = "https://auth.coderic.org/.well-known/jwks.json";
148+
JWKSet jwkSet = JWKSet.load(new URL(jwkSetUri));
149+
JWK jwk = jwkSet.getKeys().get(0);
150+
RSAKey rsaKey = (RSAKey) jwk;
151+
RSAPublicKey publicKey = rsaKey.toRSAPublicKey();
152+
return NimbusJwtDecoder.withPublicKey(publicKey).build();
153+
}
154+
/*
155+
@Bean
136156
public JwtDecoder jwtDecoder() {
137157
// URI del JWKS de Auth0
138158
String jwkSetUri = "https://auth.coderic.org/.well-known/jwks.json";
139159
return NimbusJwtDecoder.withJwkSetUri(jwkSetUri).build();
140-
}
160+
}*/
141161
}

0 commit comments

Comments
 (0)