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
+82-74Lines changed: 82 additions & 74 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,43 @@ The library implements JWT Verification and Signing using the following algorith
44
44
| ES384 | ECDSA384 | ECDSA with curve P-384 and SHA-384 |
45
45
| ES512 | ECDSA512 | ECDSA with curve P-521 and SHA-512 |
46
46
47
-
## Usage
47
+
## Supported token profile types
48
+
49
+
#### Basic Token
50
+
51
+
- Standard claims: *iss, sub, iat, jti*
52
+
- Nonstandard claims: *aud, exp, nbf*
53
+
54
+
#### Extended Token
55
+
- Standard claims: *name, email, picture, iss, sub, iat*
56
+
- Nonstandard claims: *aud, exp, nbf*
57
+
58
+
#### Access Token
59
+
- Standard claims: *iss, sub, iat*
60
+
- Nonstandard claims: *aud, exp*
61
+
62
+
#### Facebook Token
63
+
- Standard claims: *user_id, app_id, issued_at*
64
+
- Nonstandard claims: *expired_at*
65
+
66
+
#### Google Token
67
+
- Standard claims: *name, email, picture, iss, sub, iat*
68
+
- Nonstandard claims: *exp, aud*
69
+
70
+
#### Implicit Access Token
71
+
- Standard claims: *iss, sub, iat*
72
+
- Nonstandard claims: *aud*
73
+
74
+
#### Refresh Token
75
+
- Standard claims: *refresh_token, access_token*
76
+
77
+
#### Risc Token
78
+
- Standard claims: *jti, iss, sub, iat*
79
+
- Nonstandard claims: *aud, nbf, exp*
80
+
81
+
#### Scoped Access Token
82
+
- Standard claims: *iss, sub, iat, scope*
83
+
- Nonstandard claims: *aud, exp*
48
84
49
85
### Pick the Algorithm
50
86
@@ -147,23 +183,22 @@ If a Claim couldn't be converted to JSON or the Key used in the signing process
147
183
148
184
### Verify a Token
149
185
150
-
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.
186
+
You'll first need to create a `Verification` instance by calling `JWT.require()` and passing the `Algorithm` instance. Once you have the `Verification` instance, you can call the corresponding verifier method. For the example of Google,
187
+
you would have a `GoogleVerificiation` instance that has inherited from the `Verification` instance in order to call `createVerifierForGoogle()`, and you would pass in the claims that you would want to be verified.
188
+
Once you call `build`, you would get back a `JWT` object and with that, you would call `decode()` while passing in the token that was created after signing. You will get back a `DecodedJWT` object, which contains all of the claims, and you can verify
189
+
those claims against what's the expected claims by calling `verifyClaims()`.
If the token has a Claim requirement that has not been met, an `InvalidClaimException` will raise.
221
+
If the token has an invalid signature, an `AlgorithmMismatchException` will raise.
188
222
189
223
#### Time Validation
190
224
@@ -195,20 +229,20 @@ The JWT token may include DateNumber fields that can be used to validate that:
195
229
196
230
When verifying a token the time validation occurs automatically, resulting in a `JWTVerificationException` being throw when the values are invalid. If any of the previous fields are missing they won't be considered in this validation.
197
231
198
-
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.
199
-
232
+
To specify a **nbf value** in which the Token should still be considered valid, use the `withNbf()` method in the respective `Creator` builder and pass a Date object. This applies to every item listed above.
233
+
**NOTE:**`Nbf` and `iat` date values should be in the past, but the `exp` value should be in the future.
200
234
```java
201
-
JWTVerifier verifier =JWT.require(algorithm)
202
-
.acceptLeeway(1) // 1 sec for nbf, iat and exp
235
+
Verification verifier =JWT.require(algorithm)
236
+
.withNbf(newDate(2016,1,1))
203
237
.build();
204
238
```
205
239
206
240
You can also specify a custom value for a given Date claim and override the default one for only that claim.
If the token has an invalid syntax or the header or payload are not JSONs, a `JWTDecodeException` will raise.
@@ -278,12 +311,12 @@ Additional Claims defined in the token's Header can be obtained by calling `getH
278
311
Claim claim = jwt.getHeaderClaim("owner");
279
312
```
280
313
281
-
When creating a Token with the `JWT.create()` you can specify header Claims by calling `withHeader()` and passing both the map of claims.
314
+
When creating a Token with the `JWTCreator.init()` you can specify header Claims by calling `withHeader()` and passing both the map of claims.
282
315
283
316
```java
284
317
Map<String, Object> headerClaims =newHashMap();
285
318
headerClaims.put("owner", "auth0");
286
-
String token =JWT.create()
319
+
String token =JWTCreator.init()
287
320
.withHeader(headerClaims)
288
321
.sign(algorithm);
289
322
```
@@ -349,9 +382,9 @@ Returns the JWT ID value or null if it's not defined in the Payload.
349
382
String id = jwt.getId();
350
383
```
351
384
352
-
#### Private Claims
385
+
#### Nonstandard Claims
353
386
354
-
Additional Claims defined in the token's Payload can be obtained by calling `getClaims()` or `getClaim()` and passing the Claim name. A Claim will always be returned, even if it can't be found. You can check if a Claim's value is null by calling `claim.isNull()`.
387
+
Nonstandard Claims defined in the token's Payload can be obtained by calling `getClaims()` or `getClaim()` and passing the Claim name. A Claim will always be returned, even if it can't be found. You can check if a Claim's value is null by calling `claim.isNull()`.
355
388
356
389
```java
357
390
Map<String, Claim> claims = jwt.getClaims(); //Key is the Claim name
@@ -364,24 +397,16 @@ or
364
397
Claim claim = jwt.getClaim("isAdmin");
365
398
```
366
399
367
-
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.
400
+
When creating an Implicit Token for example with the `ImplicitJwtCreator.build()` you can specify a custom Claim by calling `withNonStandardClaim()` and passing both the name and the value.
368
401
369
402
```java
370
-
String token =JWT.create()
371
-
.withClaim("name", 123)
403
+
String token =ImplicitJwtCreator.build()
404
+
.withNonStandardClaim("nonStandardClaim", 123)
372
405
.withArrayClaim("array", newInteger[]{1, 2, 3})
373
406
.sign(algorithm);
374
407
```
375
408
376
-
You can also verify custom Claims on the `JWT.require()` by calling `withClaim()` and passing both the name and the required value.
377
-
378
-
```java
379
-
JWTVerifier verifier =JWT.require(algorithm)
380
-
.withClaim("name", 123)
381
-
.withArrayClaim("array", 1, 2, 3)
382
-
.build();
383
-
DecodedJWT jwt = verifier.verify("my.jwt.token");
384
-
```
409
+
**NOTE:** Nonstandard claims do not need to verified.
385
410
386
411
> Currently supported classes for custom JWT Claim creation and verification are: Boolean, Integer, Double, String, Date and Arrays of type String and Integer.
387
412
@@ -407,31 +432,14 @@ To obtain a Claim as a Collection you'll need to provide the **Class Type** of t
407
432
408
433
If the values can't be converted to the given **Class Type** a `JWTDecodeException` will raise.
409
434
410
-
411
-
412
-
## What is Auth0?
413
-
414
-
Auth0 helps you to:
415
-
416
-
* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, among others**, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
417
-
* Add authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**.
418
-
* Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user.
419
-
* Support for generating signed [Json Web Tokens](https://docs.auth0.com/jwt) to call your APIs and **flow the user identity** securely.
420
-
* Analytics of how, when and where users are logging in.
421
-
* Pull data from other sources and add it to the user profile, through [JavaScript rules](https://docs.auth0.com/rules).
422
-
423
-
## Create a free account in Auth0
424
-
425
-
1. Go to [Auth0](https://auth0.com) and click Sign Up.
426
-
2. Use Google, GitHub or Microsoft Account to login.
427
-
428
435
## Issue Reporting
429
436
430
-
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
437
+
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker.
0 commit comments