Skip to content

Commit 862ae3f

Browse files
committed
use varargs to specify audience
1 parent 074dcf4 commit 862ae3f

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static class Builder {
6363
/**
6464
* Add specific Claims to set as the Header.
6565
*
66+
* @param headerClaims the values to use as Claims in the token's Header.
6667
* @return this same Builder instance.
6768
*/
6869
public Builder withHeader(Map<String, Object> headerClaims) {
@@ -73,6 +74,7 @@ public Builder withHeader(Map<String, Object> headerClaims) {
7374
/**
7475
* Add a specific Issuer ("iss") claim.
7576
*
77+
* @param issuer the Issuer value.
7678
* @return this same Builder instance.
7779
*/
7880
public Builder withIssuer(String issuer) {
@@ -83,6 +85,7 @@ public Builder withIssuer(String issuer) {
8385
/**
8486
* Add a specific Subject ("sub") claim.
8587
*
88+
* @param subject the Subject value.
8689
* @return this same Builder instance.
8790
*/
8891
public Builder withSubject(String subject) {
@@ -93,16 +96,18 @@ public Builder withSubject(String subject) {
9396
/**
9497
* Add a specific Audience ("aud") claim.
9598
*
99+
* @param audience the Audience value.
96100
* @return this same Builder instance.
97101
*/
98-
public Builder withAudience(String[] audience) {
102+
public Builder withAudience(String... audience) {
99103
addClaim(PublicClaims.AUDIENCE, audience);
100104
return this;
101105
}
102106

103107
/**
104108
* Add a specific Expires At ("exp") claim.
105109
*
110+
* @param expiresAt the Expires At value.
106111
* @return this same Builder instance.
107112
*/
108113
public Builder withExpiresAt(Date expiresAt) {
@@ -113,6 +118,7 @@ public Builder withExpiresAt(Date expiresAt) {
113118
/**
114119
* Add a specific Not Before ("nbf") claim.
115120
*
121+
* @param notBefore the Not Before value.
116122
* @return this same Builder instance.
117123
*/
118124
public Builder withNotBefore(Date notBefore) {
@@ -123,6 +129,7 @@ public Builder withNotBefore(Date notBefore) {
123129
/**
124130
* Add a specific Issued At ("iat") claim.
125131
*
132+
* @param issuedAt the Issued At value.
126133
* @return this same Builder instance.
127134
*/
128135
public Builder withIssuedAt(Date issuedAt) {
@@ -133,6 +140,7 @@ public Builder withIssuedAt(Date issuedAt) {
133140
/**
134141
* Add a specific JWT Id ("jti") claim.
135142
*
143+
* @param jwtId the Token Id value.
136144
* @return this same Builder instance.
137145
*/
138146
public Builder withJWTId(String jwtId) {

lib/src/main/java/com/auth0/jwt/JWTVerifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Verification withSubject(String subject) {
7979
* @param audience the required Audience value
8080
* @return this same Verification instance.
8181
*/
82-
public Verification withAudience(String[] audience) {
82+
public Verification withAudience(String... audience) {
8383
requireClaim(PublicClaims.AUDIENCE, audience);
8484
return this;
8585
}

lib/src/test/java/com/auth0/jwt/ConcurrentVerifyTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import com.auth0.jwt.algorithms.Algorithm;
44
import net.jodah.concurrentunit.Waiter;
5-
import org.junit.AfterClass;
6-
import org.junit.BeforeClass;
7-
import org.junit.Rule;
8-
import org.junit.Test;
5+
import org.junit.*;
96
import org.junit.rules.ExpectedException;
107

118
import java.security.interfaces.ECKey;

lib/src/test/java/com/auth0/jwt/JWTCreatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public void shouldAddSubject() throws Exception {
6262
@Test
6363
public void shouldAddAudience() throws Exception {
6464
String signed = JWTCreator.init()
65-
.withAudience(new String[]{"Mark"})
65+
.withAudience("Mark")
6666
.sign(Algorithm.HMAC256("secret"));
6767

6868
assertThat(signed, is(notNullValue()));
6969
assertThat(TokenUtils.splitToken(signed)[1], is("eyJhdWQiOiJNYXJrIn0"));
7070

7171

7272
String signedArr = JWTCreator.init()
73-
.withAudience(new String[]{"Mark", "David"})
73+
.withAudience("Mark", "David")
7474
.sign(Algorithm.HMAC256("secret"));
7575

7676
assertThat(signedArr, is(notNullValue()));

lib/src/test/java/com/auth0/jwt/JWTVerifierTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ public void shouldThrowOnInvalidSubject() throws Exception {
8686
public void shouldValidateAudience() throws Exception {
8787
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJNYXJrIn0.xWB6czYI0XObbVhLAxe55TwChWZg7zO08RxONWU2iY4";
8888
JWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret"))
89-
.withAudience(new String[]{"Mark"})
89+
.withAudience("Mark")
9090
.build()
9191
.verify(token);
9292

9393
assertThat(jwt, is(notNullValue()));
9494

9595
String tokenArr = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiTWFyayIsIkRhdmlkIl19.6WfbIt8m61f9WlCYIQn5CThvw4UNyC66qrPaoinfssw";
9696
JWT jwtArr = JWTVerifier.init(Algorithm.HMAC256("secret"))
97-
.withAudience(new String[]{"Mark", "David"})
97+
.withAudience("Mark", "David")
9898
.build()
9999
.verify(tokenArr);
100100

@@ -107,7 +107,7 @@ public void shouldThrowOnInvalidAudience() throws Exception {
107107
exception.expectMessage("The Claim 'aud' value doesn't match the required one.");
108108
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.Rq8IxqeX7eA6GgYxlcHdPFVRNFFZc5rEI3MQTZZbK3I";
109109
JWTVerifier.init(Algorithm.HMAC256("secret"))
110-
.withAudience(new String[]{"nope"})
110+
.withAudience("nope")
111111
.build()
112112
.verify(token);
113113
}

lib/src/test/java/com/auth0/jwt/PemUtils.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,4 @@ public static PrivateKey readPrivateKeyFromFile(String filepath, String algorith
6565
return PemUtils.getPrivateKey(bytes, algorithm);
6666
}
6767

68-
public static ECPublicKey readPublicKeyFromRawString(String pemString, String algorithm) throws Exception {
69-
PemReader reader = new PemReader(new StringReader(pemString));
70-
PemObject pemObject = reader.readPemObject();
71-
return (ECPublicKey) PemUtils.getPublicKey(pemObject.getContent(), algorithm);
72-
}
73-
7468
}

0 commit comments

Comments
 (0)