0

I have written the following code to generate a json web token -

byte[] secret = Base64.getDecoder().decode("XXX");

public String generateJsonWebToken(String strUsernameForTokenCreation) {
         
    Instant now = Instant.now();
    
    String jwt = Jwts.builder()
            .setSubject(strUsernameForTokenCreation)
            .setIssuedAt(Date.from(now))
            //set expiration time         from now 10 minute
            .setExpiration(Date.from(now.plus(10,ChronoUnit.MINUTES)))
            //use the secret key
            .signWith(Keys.hmacShaKeyFor(secret))
            //generate jwt string
            .compact();
    System.out.println(jwt);
    
    return jwt;
}

Which is working fine .But ,I need to add that json web token in a confirmation link which needs to be sent to registered e-mail id. I am finding it difficult to create a confirmation link including a jsonweb token which we insert in header section of postman in authentication bearer.How can a link be generated with json web token ? Also , how can it be utilized in a post method in reactJS later on ?

0 Answers0