Added Risc token · GJWT/javaOIDCMsg@085a46f · GitHub
Skip to content

Commit 085a46f

Browse files
author
Justin Dahmubed
committed
Added Risc token
1 parent 08f9dc0 commit 085a46f

6 files changed

Lines changed: 722 additions & 0 deletions

File tree

Lines changed: 262 additions & 0 deletions

lib/src/main/java/com/auth0/jwt/interfaces/Verification.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@ Verification createVerifierForImplicit(List<String> issuer,
5555
Verification createVerifierForAccess(List<String> issuer,
5656
List<String> audience, long expLeeway, long iatLeeway);
5757

58+
Verification createVerifierForRisc(String jti, List<String> issuer,
59+
List<String> audience, long iatLeeway, long expLeeway, long nbf);
60+
5861
JWT build();
5962
}

lib/src/main/java/com/auth0/jwt/jwts/JWT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public Verification withNbf(long nbf) {
102102
throw new UnsupportedOperationException("you shouldn't be calling this method");
103103
}
104104

105+
@Override
106+
public Verification createVerifierForRisc(String jti, List<String> issuer,
107+
List<String> audience, long iatLeeway, long expLeeway, long nbf) {
108+
throw new UnsupportedOperationException("you shouldn't be calling this method");
109+
}
110+
105111
@Override
106112
public Verification createVerifierForScoped(String scope, List<String> issuer, List<String> audience, long expLeeway, long iatLeeway) {
107113
throw new UnsupportedOperationException("you shouldn't be calling this method");
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 RiscJWT extends JWT.BaseVerification implements Verification {
11+
12+
RiscJWT(Algorithm algorithm) throws IllegalArgumentException {
13+
super(algorithm);
14+
}
15+
16+
/**
17+
* Create Verification object for verification purposes
18+
* @param jti
19+
* @param issuer
20+
* @param audience
21+
* @param iatLeeway
22+
* @param expLeeway
23+
* @return
24+
*/
25+
public Verification createVerifierForRisc(String jti, List<String> issuer,
26+
List<String> audience, long iatLeeway, long expLeeway, long nbf) {
27+
Verification verification = withJWTId(jti).withIssuer(issuer.toArray(new String[issuer.size()])).acceptIssuedAt(iatLeeway);
28+
29+
if(audience != null && !audience.isEmpty()) {
30+
verification.withAudience(audience.toArray(new String[audience.size()]));
31+
}
32+
33+
if(nbf >= 0) {
34+
verification.acceptNotBefore(iatLeeway);
35+
}
36+
37+
if(expLeeway >= 0) {
38+
verification.acceptExpiresAt(expLeeway);
39+
}
40+
41+
return verification;
42+
}
43+
44+
/**
45+
* Returns a {Verification} to be used to validate token signature.
46+
*
47+
* @param algorithm that will be used to verify the token's signature.
48+
* @return Verification
49+
* @throws IllegalArgumentException if the provided algorithm is null.
50+
*/
51+
public static Verification require(Algorithm algorithm) {
52+
return RiscJWT.init(algorithm);
53+
}
54+
55+
/**
56+
* Initialize a Verification instance using the given Algorithm.
57+
*
58+
* @param algorithm the Algorithm to use on the JWT verification.
59+
* @return a RiscJWT instance to configure.
60+
* @throws IllegalArgumentException if the provided algorithm is null.
61+
*/
62+
static Verification init(Algorithm algorithm) throws IllegalArgumentException {
63+
return new RiscJWT(algorithm);
64+
}
65+
66+
/**
67+
* Creates a new and reusable instance of the JWT with the configuration already provided.
68+
*
69+
* @return a new JWT instance.
70+
*/
71+
@Override
72+
public JWT build() {
73+
return this.build(new ClockImpl());
74+
}
75+
76+
/**
77+
* Creates a new and reusable instance of the JWT the configuration already provided.
78+
* ONLY FOR TEST PURPOSES.
79+
*
80+
* @param clock the instance that will handle the current time.
81+
* @return a new JWT instance with a custom Clock.
82+
*/
83+
public JWT build(Clock clock) {
84+
addLeewayToDateClaims();
85+
return new JWT(algorithm, claims, clock);
86+
}
87+
}

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

Lines changed: 7 additions & 0 deletions

0 commit comments

Comments
 (0)