Skip to content

Commit 705efd7

Browse files
author
Justin Dahmubed
committed
Including packages
1 parent cac9dda commit 705efd7

19 files changed

+825
-1
lines changed

lib/src/main/java/com/auth0/jwt/ExtendedJwtCreator.java renamed to lib/src/main/java/com/auth0/jwt/creators/ExtendedJwtCreator.java

File renamed without changes.

lib/src/main/java/com/auth0/jwt/FbJwtCreator.java renamed to lib/src/main/java/com/auth0/jwt/creators/FbJwtCreator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
55
import com.auth0.jwt.impl.PublicClaims;
6+
import com.auth0.jwt.jwts.JWT;
67

78
import java.util.Date;
89
import java.util.HashMap;

lib/src/main/java/com/auth0/jwt/GoogleJwtCreator.java renamed to lib/src/main/java/com/auth0/jwt/creators/GoogleJwtCreator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
55
import com.auth0.jwt.impl.PublicClaims;
6+
import com.auth0.jwt.jwts.JWT;
67

78
import java.util.Date;
89
import java.util.HashMap;

lib/src/main/java/com/auth0/jwt/ImplicitJwtCreator.java renamed to lib/src/main/java/com/auth0/jwt/creators/ImplicitJwtCreator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
55
import com.auth0.jwt.impl.PublicClaims;
6+
import com.auth0.jwt.jwts.JWT;
67

78
import java.util.Date;
89
import java.util.HashMap;
File renamed without changes.

lib/src/main/java/com/auth0/jwt/ScopedJwtCreator.java renamed to lib/src/main/java/com/auth0/jwt/creators/ScopedJwtCreator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
55
import com.auth0.jwt.impl.PublicClaims;
6+
import com.auth0.jwt.jwts.JWT;
67

78
import java.util.Date;
89
import java.util.HashMap;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.auth0.jwt.jwts;
2+
3+
import com.auth0.jwt.algorithms.Algorithm;
4+
import com.auth0.jwt.interfaces.GoogleVerification;
5+
import com.auth0.jwt.interfaces.Verification;
6+
7+
import java.util.List;
8+
9+
public class ExtendedJWT extends GoogleJWT implements GoogleVerification{
10+
11+
ExtendedJWT(Algorithm algorithm) throws IllegalArgumentException {
12+
super(algorithm);
13+
}
14+
15+
16+
public Verification createVerifierForExtended(String picture, String email, List<String> issuer,
17+
List<String> audience, String name, long nbf, long expLeeway, long iatLeeway) {
18+
Verification verification = createVerifierForGoogle(picture, email, issuer, audience, name, expLeeway, iatLeeway);
19+
return verification.withNbf(nbf);
20+
}
21+
22+
public static GoogleVerification require(Algorithm algorithm) {
23+
return ExtendedJWT.init(algorithm);
24+
}
25+
26+
static GoogleVerification init(Algorithm algorithm) throws IllegalArgumentException {
27+
return new ExtendedJWT(algorithm);
28+
}
29+
30+
/**
31+
* Require a specific Not Before ("nbf") claim.
32+
*
33+
* @param nbf the required Not Before value
34+
* @return this same Verification instance.
35+
*/
36+
@Override
37+
public Verification withNbf(long nbf) {
38+
requireClaim("nbf", nbf);
39+
return this;
40+
}
41+
42+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.auth0.jwt.jwts;
2+
3+
import com.auth0.jwt.ClockImpl;
4+
import com.auth0.jwt.algorithms.Algorithm;
5+
import com.auth0.jwt.interfaces.Clock;
6+
import com.auth0.jwt.interfaces.Verification;
7+
8+
public class FbJWT extends JWT.BaseVerification implements Verification{
9+
10+
FbJWT(Algorithm algorithm) throws IllegalArgumentException {
11+
super(algorithm);
12+
}
13+
14+
/**
15+
* Create Verification object for verification purposes
16+
* @param userId
17+
* @param appId
18+
* @return
19+
*/
20+
public Verification createVerifierForFb(String userId, String appId) {
21+
return withUserId(userId).withAppId(appId);
22+
}
23+
24+
/**
25+
* Require a specific userId ("userId") claim.
26+
*
27+
* @param userId the required userId value
28+
* @return this same Verification instance.
29+
*/
30+
public Verification withUserId(String userId) {
31+
requireClaim("userId", userId);
32+
return this;
33+
}
34+
35+
/**
36+
* Require a specific appId ("appId") claim.
37+
*
38+
* @param appId the required appId value
39+
* @return this same Verification instance.
40+
*/
41+
public Verification withAppId(String appId) {
42+
requireClaim("appId", appId);
43+
return this;
44+
}
45+
46+
/**
47+
* Returns a {Verification} to be used to validate token signature.
48+
*
49+
* @param algorithm that will be used to verify the token's signature.
50+
* @return Verification
51+
* @throws IllegalArgumentException if the provided algorithm is null.
52+
*/
53+
public static Verification require(Algorithm algorithm) {
54+
return FbJWT.init(algorithm);
55+
}
56+
57+
/**
58+
* Initialize a Verification instance using the given Algorithm.
59+
*
60+
* @param algorithm the Algorithm to use on the JWT verification.
61+
* @return a FbJWT instance to configure.
62+
* @throws IllegalArgumentException if the provided algorithm is null.
63+
*/
64+
static Verification init(Algorithm algorithm) throws IllegalArgumentException {
65+
return new FbJWT(algorithm);
66+
}
67+
68+
/**
69+
* Creates a new and reusable instance of the JWT with the configuration already provided.
70+
*
71+
* @return a new JWT instance.
72+
*/
73+
@Override
74+
public JWT build() {
75+
return this.build(new ClockImpl());
76+
}
77+
78+
/**
79+
* Creates a new and reusable instance of the JWT the configuration already provided.
80+
* ONLY FOR TEST PURPOSES.
81+
*
82+
* @param clock the instance that will handle the current time.
83+
* @return a new JWT instance with a custom Clock.
84+
*/
85+
public JWT build(Clock clock) {
86+
addLeewayToDateClaims();
87+
return new JWT(algorithm, claims, clock);
88+
}
89+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package com.auth0.jwt.jwts;
2+
3+
import com.auth0.jwt.ClockImpl;
4+
import com.auth0.jwt.algorithms.Algorithm;
5+
import com.auth0.jwt.interfaces.Clock;
6+
import com.auth0.jwt.interfaces.GoogleVerification;
7+
import com.auth0.jwt.interfaces.Verification;
8+
9+
import java.util.List;
10+
11+
public class GoogleJWT extends JWT.BaseVerification implements GoogleVerification{
12+
13+
GoogleJWT(Algorithm algorithm) throws IllegalArgumentException {
14+
super(algorithm);
15+
}
16+
17+
/**
18+
* Create Verification object for verification purposes
19+
* @param picture
20+
* @param email
21+
* @param issuer
22+
* @param audience
23+
* @param name
24+
* @return
25+
*/
26+
public Verification createVerifierForGoogle(String picture, String email, List<String> issuer,
27+
List<String> audience, String name, long expLeeway, long iatLeeway) {
28+
return withPicture(picture).withName(name).withEmail(email).withIssuer(issuer.toArray(new String[issuer.size()])).withAudience(audience.toArray(new String[audience.size()]))
29+
.acceptExpiresAt(expLeeway).acceptIssuedAt(iatLeeway);
30+
}
31+
32+
/**
33+
* Require a specific Picture ("picture") claim.
34+
*
35+
* @param picture the required Picture value
36+
* @return this same Verification instance.
37+
*/
38+
@Override
39+
public GoogleVerification withPicture(String picture) {
40+
requireClaim("picture", picture);
41+
return this;
42+
}
43+
44+
/**
45+
* Require a specific Email ("email") claim.
46+
*
47+
* @param email the required Email value
48+
* @return this same Verification instance.
49+
*/
50+
@Override
51+
public GoogleVerification withEmail(String email) {
52+
requireClaim("email", email);
53+
return this;
54+
}
55+
56+
/**
57+
* Require a specific Name ("name") claim.
58+
*
59+
* @param name the required Name value
60+
* @return this same Verification instance.
61+
*/
62+
@Override
63+
public GoogleVerification withName(String name) {
64+
requireClaim("name", name);
65+
return this;
66+
}
67+
68+
@Override
69+
public Verification createVerifierForExtended(String picture, String email, List<String> issuer, List<String> audience, String name, long nbf, long expLeeway, long iatLeeway) {
70+
throw new UnsupportedOperationException("you shouldn't be calling this method");
71+
}
72+
73+
/**
74+
* Returns a {GoogleVerification} to be used to validate token signature.
75+
*
76+
* @param algorithm that will be used to verify the token's signature.
77+
* @return GoogleVerification
78+
* @throws IllegalArgumentException if the provided algorithm is null.
79+
*/
80+
public static GoogleVerification require(Algorithm algorithm) {
81+
return GoogleJWT.init(algorithm);
82+
}
83+
84+
/**
85+
* Initialize a GoogleVerification instance using the given Algorithm.
86+
*
87+
* @param algorithm the Algorithm to use on the JWT verification.
88+
* @return a GoogleJWT instance to configure.
89+
* @throws IllegalArgumentException if the provided algorithm is null.
90+
*/
91+
static GoogleVerification init(Algorithm algorithm) throws IllegalArgumentException {
92+
return new GoogleJWT(algorithm);
93+
}
94+
95+
/**
96+
* Creates a new and reusable instance of the JWT with the configuration already provided.
97+
*
98+
* @return a new JWT instance.
99+
*/
100+
@Override
101+
public JWT build() {
102+
return this.build(new ClockImpl());
103+
}
104+
105+
/**
106+
* Creates a new and reusable instance of the JWT the configuration already provided.
107+
* ONLY FOR TEST PURPOSES.
108+
*
109+
* @param clock the instance that will handle the current time.
110+
* @return a new JWT instance with a custom Clock.
111+
*/
112+
public JWT build(Clock clock) {
113+
addLeewayToDateClaims();
114+
return new JWT(algorithm, claims, clock);
115+
}
116+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.auth0.jwt.jwts;
2+
3+
import com.auth0.jwt.ClockImpl;
4+
import com.auth0.jwt.algorithms.Algorithm;
5+
import com.auth0.jwt.interfaces.Clock;
6+
import com.auth0.jwt.interfaces.Verification;
7+
8+
import java.util.List;
9+
10+
public class ImplicitJWT extends JWT.BaseVerification implements Verification{
11+
12+
ImplicitJWT(Algorithm algorithm) throws IllegalArgumentException {
13+
super(algorithm);
14+
}
15+
16+
/**
17+
* Create Verification object for verification purposes
18+
* @issuer scope
19+
* @param issuer
20+
* @param audience
21+
* @return
22+
*/
23+
public Verification createVerifierForImplicit(List<String> issuer,
24+
List<String> audience, long iatLeeway) {
25+
return withIssuer(issuer.toArray(new String[issuer.size()])).withAudience(audience.toArray(new String[audience.size()]))
26+
.acceptIssuedAt(iatLeeway);
27+
}
28+
29+
/**
30+
* Returns a {Verification} to be used to validate token signature.
31+
*
32+
* @param algorithm that will be used to verify the token's signature.
33+
* @return Verification
34+
* @throws IllegalArgumentException if the provided algorithm is null.
35+
*/
36+
public static Verification require(Algorithm algorithm) {
37+
return ImplicitJWT.init(algorithm);
38+
}
39+
40+
/**
41+
* Initialize a Verification instance using the given Algorithm.
42+
*
43+
* @param algorithm the Algorithm to use on the JWT verification.
44+
* @return a ImplicitJWT instance to configure.
45+
* @throws IllegalArgumentException if the provided algorithm is null.
46+
*/
47+
static Verification init(Algorithm algorithm) throws IllegalArgumentException {
48+
return new ImplicitJWT(algorithm);
49+
}
50+
51+
/**
52+
* Creates a new and reusable instance of the JWT with the configuration already provided.
53+
*
54+
* @return a new JWT instance.
55+
*/
56+
@Override
57+
public JWT build() {
58+
return this.build(new ClockImpl());
59+
}
60+
61+
/**
62+
* Creates a new and reusable instance of the JWT the configuration already provided.
63+
* ONLY FOR TEST PURPOSES.
64+
*
65+
* @param clock the instance that will handle the current time.
66+
* @return a new JWT instance with a custom Clock.
67+
*/
68+
public JWT build(Clock clock) {
69+
addLeewayToDateClaims();
70+
return new JWT(algorithm, claims, clock);
71+
}
72+
}

0 commit comments

Comments
 (0)