Skip to content

Commit 67fb9d1

Browse files
committed
fixup! Add JWTAuthorizer Implementation.
1 parent f91a2c5 commit 67fb9d1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

java/app/src/main/java/org/vss/auth/JwtAuthorizer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class JwtAuthorizer implements Authorizer {
1919
private final PublicKey publicKey;
2020
private final JWTVerifier verifier;
2121

22+
public static final String BEARER_PREFIX = "Bearer ";
23+
2224
public JwtAuthorizer(String pemFormatPublicKey) throws Exception {
2325
this.publicKey = loadPublicKey(pemFormatPublicKey);
2426

@@ -31,12 +33,12 @@ public AuthResponse verify(HttpHeaders headers) throws AuthException {
3133

3234
try {
3335
String authorizationHeader = headers.getHeaderString(HttpHeaders.AUTHORIZATION);
34-
if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) {
36+
if (authorizationHeader == null || !authorizationHeader.startsWith(BEARER_PREFIX)) {
3537
throw new AuthException("Missing or invalid Authorization header.");
3638
}
3739

38-
// Extract token by excluding 'Bearer '.
39-
String token = authorizationHeader.substring(7);
40+
// Extract token by excluding BEARER_PREFIX.
41+
String token = authorizationHeader.substring(BEARER_PREFIX.length());
4042

4143
DecodedJWT jwt = verifier.verify(token);
4244

0 commit comments

Comments
 (0)