Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ELY-2610] migrate getAccessTokenHash method to AtValidator class. #2001

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ public ErrorCodeValidator.Error validate(JwtContext jwtContext) throws Malformed
}
return null;
}

private static String getAccessTokenHash(String accessTokenString, String jwsAlgorithm) throws NoSuchAlgorithmException {
byte[] inputBytes = accessTokenString.getBytes(StandardCharsets.UTF_8);
String javaAlgName = getJavaAlgorithmForHash(jwsAlgorithm);
MessageDigest md = MessageDigest.getInstance(javaAlgName);
md.update(inputBytes);
byte[] hash = md.digest();
int hashLength = hash.length / 2;
byte[] hashInput = Arrays.copyOf(hash, hashLength); // leftmost half of the hash
return ByteIterator.ofBytes(hashInput).base64Encode(BASE64_URL, false).drainToString();
}

}

private static class TypeValidator implements ErrorCodeValidator {
Expand All @@ -297,17 +309,6 @@ public ErrorCodeValidator.Error validate(JwtContext jwtContext) throws Malformed
}
}

private static String getAccessTokenHash(String accessTokenString, String jwsAlgorithm) throws NoSuchAlgorithmException {
byte[] inputBytes = accessTokenString.getBytes(StandardCharsets.UTF_8);
String javaAlgName = getJavaAlgorithmForHash(jwsAlgorithm);
MessageDigest md = MessageDigest.getInstance(javaAlgName);
md.update(inputBytes);
byte[] hash = md.digest();
int hashLength = hash.length / 2;
byte[] hashInput = Arrays.copyOf(hash, hashLength); // leftmost half of the hash
return ByteIterator.ofBytes(hashInput).base64Encode(BASE64_URL, false).drainToString();
}

public static class VerifiedTokens {

private final AccessToken accessToken;
Expand Down
Loading