Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

696
Vistas
How do I validate a jwt token that I got from Cognito

I have a jwt token that I have retrieved from cognito after my user logs in.

I have a specific api end point in my application and I want only users with a valid jwt to be able to access this end point. I tried looking at various resources on the web but I couldn't understand anything. I am new to the jwt concept.

PS I have a Java application (spring boot ). I would really appreciate if someone would describe in detail the steps that i need to follow to verify my jwt. Please provide the code if possible.

@CrossOrigin
@RequestMapping(value= "/login", method=RequestMethod.POST,consumes="application/json")
@ResponseBody
public String authenticate(@RequestBody SignInDTO signInDetails)
{
    //boolean isAuthenticated=false;
        CognitoHelper cognitoHelper=new CognitoHelper();
        String authResult=cognitoHelper.ValidateUser(signInDetails.getEmailId(), signInDetails.getPassword());
.....
.....
.....

authResult is the jwt that i get from cognito. After this I am completely clueless about what needs to be done.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Spring Security 5.1 introduced support for this, making it much easier to implement. See https://docs.spring.io/spring-security/site/docs/current/reference/html/jc.html#oauth2resourceserver

Basically:

  1. Add dependencies as described in https://docs.spring.io/spring-security/site/docs/current/reference/html/jc.html#dependencies
  2. Add the yml configuration as described in https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2resourceserver-jwt-minimalconfiguration . For cognito, use the following URL: https://cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>
  3. You probably need to edit your security settings as described in https://docs.spring.io/spring-security/site/docs/current/reference/html/jc.html#oauth2resourceserver-sansboot
over 4 years ago · Santiago Trujillo Denunciar

0

Use a library like java-jwt (I guess you are using Maven)

<dependency>
    <groupId>com.auth0</groupId>
    <artifactId>java-jwt</artifactId>
    <version>3.3.0</version>
</dependency>

Then:

String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
try {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    // or
    Algorithm algorithm = Algorithm.RSA256(publicKey, privateKey);
    JWTVerifier verifier = JWT.require(algorithm)
        .withIssuer("auth0")
        .build(); //Reusable verifier instance
    DecodedJWT jwt = verifier.verify(token);
} catch (UnsupportedEncodingException exception){
    //UTF-8 encoding not supported
} catch (JWTVerificationException exception){
    //Invalid signature/claims
}

You can manually decode a jwt-token here: https://jwt.io
More info about java-jwt here: https://github.com/auth0/java-jwt

over 4 years ago · Santiago Trujillo Denunciar

0

Step 1: Confirm the Structure of the JWT

Step 2: Validate the JWT Signature

Step 3: Verify the Claims

Goto https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-verifying-a-jwt.html for more information.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda