Merge pull request #246 from Ledenel/master

Update README.md
This commit is contained in:
Les Hazlewood 2018-07-20 19:38:23 -04:00 committed by GitHub
commit 2eeca41a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -118,6 +118,8 @@ Now let's verify the JWT (you should always discard JWTs that don't match an exp
assert Jwts.parser().setSigningKey(key).parseClaimsJws(compactJws).getBody().getSubject().equals("Joe");
```
Please make sure that you are calling the **correct** parse method `parseClaimsJws` (since there are many similar methods available). You will get an `UnsupportedJwtException` if you parse your JWT with wrong method.
There are two things going on here. The `key` from before is being used to validate the signature of the JWT. If it fails to verify the JWT, a `SignatureException` is thrown. Assuming the JWT is validated, we parse out the claims and assert that that subject is set to `Joe`.
You have to love code one-liners that pack a punch!