dcore099 / demo2

Demo de Spring boot 2.5.0 con Spring security
1 stars 0 forks source link

JWT Maven dependency in project #7

Open dcore099 opened 3 years ago

dcore099 commented 3 years ago

Check out this used dependency, is it good and still widely used? Or just for study purposes?

`

io.jsonwebtoken
        <artifactId>jjwt</artifactId>
        <version>0.9.1</version>
    </dependency>`
dcore099 commented 3 years ago

It seems like it needs more dependencies,

https://github.com/jwtk/jjwt

`

io.jsonwebtoken
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>

io.jsonwebtoken jjwt-impl 0.11.2 runtime io.jsonwebtoken jjwt-jackson 0.11.2 runtime `
dcore099 commented 3 years ago

Creates a key like this

`import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.security.Keys; import java.security.Key;

// We need a signing key, so we'll create one just for this example. Usually // the key would be read from your application configuration instead. Key key = Keys.secretKeyFor(SignatureAlgorithm.HS256);

String jws = Jwts.builder().setSubject("Joe").signWith(key).compact();`

And i think it verifies it like this

assert Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(jws).getBody().getSubject().equals("Joe");