angular validate Jwt Token

Viewed 28

I have a public and private key to create a JWT token. With the private key, I create a JWT token, and with the public key, I check the validity of the token. To create a token on the server side, I use the following code:

        Jwts.builder()
          .setHeaderParam("typ","JWT")
          .claim("email", userPrincipal.getEmail())
          .claim("roles", roleList)
          .setIssuedAt(new Date())
          .setExpiration(new Date(new Date().getTime() + jwtExpirationMs))
          .signWith(getPrivateKey(), SignatureAlgorithm.RS512)
          .compact();

To check the validity of the token on the server side, I use the public key and the following code:

        Jwts.parserBuilder().setSigningKey(getPublicKey()).build().parseClaimsJws(jwtString);

Now my task is to check the validity of the token on the Angular client side.

Please tell me how can this be done?

1 Answers

I don't think you should check it on the client side!

Set your JWT token as an HttpOnly cookie so that future requests from the client side have the token as a cookie and you can evaluate the token on the server for each request.

Related