Skip to content

Commit

Permalink
chore: improve logging of access token validator
Browse files Browse the repository at this point in the history
  • Loading branch information
astsiapanay committed Sep 23, 2024
1 parent f3c2728 commit 7640323
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/epam/aidial/core/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ private Future<AuthorizationResult> authorizeRequest(HttpServerRequest request)
if (apiKey == null) {
return tokenValidator.extractClaims(authorization)
.compose(extractedClaims -> Future.succeededFuture(new AuthorizationResult(new ApiKeyData(), extractedClaims)),
error -> Future.failedFuture(new HttpException(HttpStatus.UNAUTHORIZED, "Bad Authorization header")));
error -> {
log.error("Can't extract claims from authorization header", error);
return Future.failedFuture(new HttpException(HttpStatus.UNAUTHORIZED, "Bad Authorization header"));
});
}

if (apiKey.equals(extractTokenFromHeader(authorization))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Future<ExtractedClaims> extractClaimsFromUserInfo(String accessToken) {
request.putHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken);
request.send().onFailure(promise::fail).onSuccess(response -> {
if (response.statusCode() != 200) {
promise.fail(String.format("Request failed with http code %d", response.statusCode()));
promise.fail(String.format("UserInfo endpoint '%s' is failed with http code %d", userInfoUrl, response.statusCode()));
return;
}
response.body().map(body -> {
Expand All @@ -280,7 +280,7 @@ Future<ExtractedClaims> extractClaimsFromUserInfo(String accessToken) {
}).onFailure(promise::fail);
});
});
return promise.future();
return promise.future().onFailure(error -> log.warn(String.format("Can't extract claims from user info endpoint '%s':", userInfoUrl), error));
}

private ExtractedClaims from(DecodedJWT jwt) {
Expand Down

0 comments on commit 7640323

Please sign in to comment.