Skip to content

Commit

Permalink
feat: refactored into private method
Browse files Browse the repository at this point in the history
(cherry picked from commit ffa8cf4)
  • Loading branch information
1nb0und committed Jan 24, 2024
1 parent dcaa15e commit e707858
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,21 @@ public Map.Entry<String, String> getTokenHeader(Product product) {
if (tokens.containsKey(product)) {
token = tokens.get(product);
} else {
Identity identity = identityConfig.get(product).getIdentity();
String audience = jwtConfig.getProduct(product).getAudience();
Tokens identityTokens = identity.authentication().requestToken(audience);
try {
identity.authentication().verifyToken(identityTokens.getAccessToken());
} catch (TokenExpiredException exception) {
identityTokens = identity.authentication().renewToken(identityTokens.getRefreshToken());
}
tokens.put(product, identityTokens.getAccessToken());
token = tokens.get(product);
token = getIdentityToken(product);
}
return new AbstractMap.SimpleEntry<>("Authorization", "Bearer " + token);
}

private String getIdentityToken(Product product) {
Identity identity = identityConfig.get(product).getIdentity();
String audience = jwtConfig.getProduct(product).getAudience();
Tokens identityTokens = identity.authentication().requestToken(audience);
try {
identity.authentication().verifyToken(identityTokens.getAccessToken());
} catch (TokenExpiredException exception) {
identityTokens = identity.authentication().renewToken(identityTokens.getRefreshToken());
}
tokens.put(product, identityTokens.getAccessToken());
return tokens.get(product);
}
}

0 comments on commit e707858

Please sign in to comment.