Skip to content

Commit 709ca99

Browse files
author
Justin Dahmubed
committed
Don't need to provide nonstandard claims
1 parent 705efd7 commit 709ca99

File tree

7 files changed

+12
-49
lines changed

7 files changed

+12
-49
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.auth0.jwt;
1+
package com.auth0.jwt.creators;
22

33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
@@ -12,7 +12,6 @@ public class ExtendedJwtCreator extends GoogleJwtCreator{
1212

1313
public ExtendedJwtCreator() {
1414
super();
15-
addedClaims.put("Nbf", false);
1615
}
1716

1817
/**
@@ -23,7 +22,6 @@ public ExtendedJwtCreator() {
2322
*/
2423
public GoogleJwtCreator withNbf(Date nbf) {
2524
jwt.withNotBefore(nbf);
26-
addedClaims.put("Nbf", true);
2725
return this;
2826
}
2927

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.auth0.jwt;
1+
package com.auth0.jwt.creators;
22

33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
@@ -24,7 +24,6 @@ public FbJwtCreator() {
2424
addedClaims = new HashMap<String, Boolean>() {{
2525
put("UserId", false);
2626
put("AppId", false);
27-
put("Exp", false);
2827
put("Iat", false);
2928
}};
3029
publicClaims = new HashSet<String>() {{
@@ -53,7 +52,6 @@ public FbJwtCreator withIat(Date iat) {
5352
*/
5453
public FbJwtCreator withExp(Date exp) {
5554
jwt.withExpiresAt(exp);
56-
addedClaims.put("Exp", true);
5755
return this;
5856
}
5957

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.auth0.jwt;
1+
package com.auth0.jwt.creators;
22

33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
@@ -27,9 +27,7 @@ public GoogleJwtCreator() {
2727
put("Picture", false);
2828
put("Issuer", false);
2929
put("Subject", false);
30-
put("Audience", false);
3130
put("Iat", false);
32-
put("Exp", false);
3331
}};
3432
publicClaims = new HashSet<String>() {{
3533
add(PublicClaims.ISSUER);
@@ -49,7 +47,7 @@ public GoogleJwtCreator() {
4947
* @param name the Name value.
5048
* @return this same Builder instance.
5149
*/
52-
protected GoogleJwtCreator withName(String name) {
50+
public GoogleJwtCreator withName(String name) {
5351
jwt.withNonStandardClaim("name", name);
5452
addedClaims.put("Name", true);
5553
return this;
@@ -61,7 +59,7 @@ protected GoogleJwtCreator withName(String name) {
6159
* @param email the Email value.
6260
* @return this same Builder instance.
6361
*/
64-
GoogleJwtCreator withEmail(String email) {
62+
public GoogleJwtCreator withEmail(String email) {
6563
jwt.withNonStandardClaim("email", email);
6664
addedClaims.put("Email", true);
6765
return this;
@@ -73,7 +71,7 @@ GoogleJwtCreator withEmail(String email) {
7371
* @param picture the Picture value.
7472
* @return this same Builder instance.
7573
*/
76-
protected GoogleJwtCreator withPicture(String picture) {
74+
public GoogleJwtCreator withPicture(String picture) {
7775
jwt.withNonStandardClaim("picture", picture);
7876
addedClaims.put("Picture", true);
7977
return this;
@@ -114,7 +112,6 @@ public GoogleJwtCreator withSubject(String... subject) {
114112
*/
115113
public GoogleJwtCreator withAudience(String... audience) {
116114
jwt.withAudience(audience);
117-
addedClaims.put("Audience", true);
118115
return this;
119116
}
120117

@@ -138,7 +135,6 @@ public GoogleJwtCreator withIat(Date iat) {
138135
*/
139136
public GoogleJwtCreator withExp(Date exp) {
140137
jwt.withExpiresAt(exp);
141-
addedClaims.put("Exp", true);
142138
return this;
143139
}
144140

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.auth0.jwt;
1+
package com.auth0.jwt.creators;
22

33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
@@ -24,7 +24,6 @@ public ImplicitJwtCreator() {
2424
addedClaims = new HashMap<String, Boolean>() {{
2525
put("Issuer", false);
2626
put("Subject", false);
27-
put("Audience", false);
2827
put("Iat", false);
2928
}};
3029
publicClaims = new HashSet<String>() {{
@@ -70,7 +69,6 @@ public ImplicitJwtCreator withSubject(String... subject) {
7069
*/
7170
public ImplicitJwtCreator withAudience(String... audience) {
7271
jwt.withAudience(audience);
73-
addedClaims.put("Audience", true);
7472
return this;
7573
}
7674

lib/src/main/java/com/auth0/jwt/creators/JWTCreator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.auth0.jwt;
1+
package com.auth0.jwt.creators;
22

33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
@@ -48,7 +48,7 @@ private JWTCreator(Algorithm algorithm, Map<String, Object> headerClaims, Map<St
4848
*
4949
* @return a JWTCreator.Builder instance to configure.
5050
*/
51-
static JWTCreator.Builder init() {
51+
public static JWTCreator.Builder init() {
5252
return new Builder();
5353
}
5454

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.auth0.jwt;
1+
package com.auth0.jwt.creators;
22

33
import com.auth0.jwt.algorithms.Algorithm;
44
import com.auth0.jwt.exceptions.JWTCreationException;
@@ -25,9 +25,7 @@ public ScopedJwtCreator() {
2525
put("Scope", false);
2626
put("Issuer", false);
2727
put("Subject", false);
28-
put("Audience", false);
2928
put("Iat", false);
30-
put("Exp", false);
3129
}};
3230
publicClaims = new HashSet<String>() {{
3331
add(PublicClaims.ISSUER);
@@ -88,7 +86,6 @@ public ScopedJwtCreator withSubject(String... subject) {
8886
*/
8987
public ScopedJwtCreator withAudience(String... audience) {
9088
jwt.withAudience(audience);
91-
addedClaims.put("Audience", true);
9289
return this;
9390
}
9491

@@ -112,7 +109,6 @@ public ScopedJwtCreator withIat(Date iat) {
112109
*/
113110
public ScopedJwtCreator withExp(Date exp) {
114111
jwt.withExpiresAt(exp);
115-
addedClaims.put("Exp", true);
116112
return this;
117113
}
118114

lib/src/test/java/com/auth0/jwt/creators/ExtendedJwtCreatorTest.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.auth0.jwt;
1+
package com.auth0.jwt.creators;
22

3-
import static com.auth0.jwt.GoogleJwtCreatorTest.*;
3+
import static com.auth0.jwt.creators.GoogleJwtCreatorTest.*;
44
import static com.auth0.jwt.TimeUtil.generateRandomExpDateInFuture;
55
import static com.auth0.jwt.TimeUtil.generateRandomIatDateInPast;
66
import com.auth0.jwt.algorithms.Algorithm;
@@ -166,29 +166,6 @@ public void testExtendedJwtCreatorInvalidName() throws Exception {
166166
verifyClaims(claims, exp);
167167
}
168168

169-
@Test
170-
public void testExtendedJwtCreatorNbfNotProvided() throws Exception {
171-
thrown.expect(Exception.class);
172-
thrown.expectMessage("Standard claim: Nbf has not been set");
173-
Algorithm algorithm = Algorithm.HMAC256("secret");
174-
String token = ExtendedJwtCreator.build()
175-
.withPicture(PICTURE)
176-
.withEmail(EMAIL)
177-
.withIssuer("accounts.fake.com")
178-
.withSubject("subject")
179-
.withAudience("audience")
180-
.withExp(exp)
181-
.withIat(iat)
182-
.withName(NAME)
183-
.sign(algorithm);
184-
GoogleVerification verification = ExtendedJWT.require(algorithm);
185-
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("accounts.fake.com"), asList("audience"),
186-
NAME, 1, 1, 1).build();
187-
DecodedJWT jwt = verifier.decode(token);
188-
Map<String, Claim> claims = jwt.getClaims();
189-
verifyClaims(claims, exp);
190-
}
191-
192169
@Test
193170
public void testExtendedJwtCreatorNoneAlgorithmNotAllowed() throws Exception {
194171
thrown.expect(IllegalAccessException.class);

0 commit comments

Comments
 (0)