You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-22Lines changed: 32 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@
8
8
9
9
A Java implementation of [JSON Web Tokens (draft-ietf-oauth-json-web-token-08)](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html).
10
10
11
-
If you're looking for an *Android* version of the JWT Decoder take a look at our [JWTDecode.Android](https://github.com/auth0/JWTDecode.Android) library.
11
+
If you're looking for an **Android** version of the JWT Decoder take a look at our [JWTDecode.Android](https://github.com/auth0/JWTDecode.Android) library.
12
12
13
13
## Installation
14
14
@@ -48,15 +48,18 @@ The library implements JWT Verification and Signing using the following algorith
48
48
49
49
### Create and Sign a Token
50
50
51
-
You'll first need to create a `JWTCreator` instance by calling `JWT.create()`. Use the builder to define the custom Claims your token needs to have. Finally to get the String token call `sign()` and pass the Algorithm instance.
51
+
You'll first need to create a `JWTCreator` instance by calling `JWT.create()`. Use the builder to define the custom Claims your token needs to have. Finally to get the String token call `sign()` and pass the `Algorithm` instance.
@@ -80,17 +85,20 @@ If a Claim couldn't be converted to JSON or the Key used in the signing process
80
85
81
86
### Verify a Token
82
87
83
-
You'll first need to create a `JWTVerifier` instance by calling `JWT.require()` and passing the Algorithm instance. If you require the token to have specific Claim values, use the builder to define them. The instance returned by the method `build()` is reusable, so you can define it once and use it to verify different tokens. Finally call `verifier.verify()` passing the token.
88
+
You'll first need to create a `JWTVerifier` instance by calling `JWT.require()` and passing the `Algorithm` instance. If you require the token to have specific Claim values, use the builder to define them. The instance returned by the method `build()` is reusable, so you can define it once and use it to verify different tokens. Finally call `verifier.verify()` passing the token.
@@ -126,15 +136,15 @@ When verifying a token the time validation occurs automatically, resulting in a
126
136
To specify a **leeway window** in which the Token should still be considered valid, use the `acceptLeeway()` method in the `JWTVerifier` builder and pass a positive seconds value. This applies to every item listed above.
If you need to test this behaviour in your lib/app cast the `Verification` instance to a `BaseVerification` to gain visibility of the `verification.build()` method that accepts a custom `Clock`. e.g.:
When creating a Token with the `JWT.create()` you can specify a custom Claim by calling `withClaim()` and passing both the name and the value.
296
306
297
307
```java
298
-
JWT.create()
299
-
.withClaim("name", 123)
300
-
.withArrayClaim("array", newInteger[]{1, 2, 3})
301
-
.sign(Algorithm.HMAC256("secret"));
308
+
String token =JWT.create()
309
+
.withClaim("name", 123)
310
+
.withArrayClaim("array", newInteger[]{1, 2, 3})
311
+
.sign(algorithm);
302
312
```
303
313
304
314
You can also verify custom Claims on the `JWT.require()` by calling `withClaim()` and passing both the name and the required value.
305
315
306
316
```java
307
-
JWT.require(Algorithm.HMAC256("secret"))
317
+
JWTVerifier verifier =JWT.require(algorithm)
308
318
.withClaim("name", 123)
309
319
.withArrayClaim("array", 1, 2, 3)
310
-
.build()
311
-
.verify("my.jwt.token");
320
+
.build();
321
+
DecodedJWT jwt = verifier.verify("my.jwt.token");
312
322
```
313
323
314
324
> Currently supported classes for custom JWT Claim creation and verification are: Boolean, Integer, Double, String, Date and Arrays of type String and Integer.
0 commit comments