diff --git a/metadata-service/auth-impl/build.gradle b/metadata-service/auth-impl/build.gradle index f6ed0033667fa6..f87b2cd2b2c892 100644 --- a/metadata-service/auth-impl/build.gradle +++ b/metadata-service/auth-impl/build.gradle @@ -7,7 +7,7 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-api:0.11.2' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2', - 'io.jsonwebtoken:jjwt-jackson:0.11.2' // or 'io.jsonwebtoken:jjwt-gson:0.11.2' for gson + 'io.jsonwebtoken:jjwt-jackson:0.11.2' compile externalDependency.lombok diff --git a/metadata-service/auth-impl/src/main/java/com/datahub/authentication/token/TokenService.java b/metadata-service/auth-impl/src/main/java/com/datahub/authentication/token/TokenService.java index 419c192175c0a3..4b844ed07048f6 100644 --- a/metadata-service/auth-impl/src/main/java/com/datahub/authentication/token/TokenService.java +++ b/metadata-service/auth-impl/src/main/java/com/datahub/authentication/token/TokenService.java @@ -7,6 +7,7 @@ import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; +import java.nio.charset.StandardCharsets; import java.security.Key; import java.util.ArrayList; import java.util.Base64; @@ -104,7 +105,7 @@ public String generateAccessToken(@Nonnull final String sub, @Nonnull final Map< if (this.iss != null) { builder.setIssuer(this.iss); } - byte[] apiKeySecretBytes = Base64.getDecoder().decode(this.signingKey); // Key must be base64'd. + byte [] apiKeySecretBytes = this.signingKey.getBytes(StandardCharsets.UTF_8); final Key signingKey = new SecretKeySpec(apiKeySecretBytes, this.signingAlgorithm.getJcaName()); return builder.signWith(signingKey, this.signingAlgorithm).compact(); } @@ -118,8 +119,10 @@ public String generateAccessToken(@Nonnull final String sub, @Nonnull final Map< public TokenClaims validateAccessToken(@Nonnull final String accessToken) throws TokenException { Objects.requireNonNull(accessToken); try { + byte [] apiKeySecretBytes = this.signingKey.getBytes(StandardCharsets.UTF_8); + final String base64Key = Base64.getEncoder().encodeToString(apiKeySecretBytes); final Claims claims = (Claims) Jwts.parserBuilder() - .setSigningKey(this.signingKey) + .setSigningKey(base64Key) .build() .parse(accessToken) .getBody();