Skip to content

Commit

Permalink
fix: use a throwable in the UserInfoResponse on technical error for u…
Browse files Browse the repository at this point in the history
  • Loading branch information
phiz71 committed Nov 23, 2023
1 parent c13a525 commit 9814a5f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main/java/io/gravitee/resource/oauth2/am/OAuth2AMResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void userInfo(String accessToken, Handler<UserInfoResponse> responseHandl
@Override
public void handle(Throwable event) {
logger.error("An error occurs while getting userinfo from access token", event);
responseHandler.handle(new UserInfoResponse(false, event.getMessage()));
responseHandler.handle(new UserInfoResponse(event));
}
}
)
Expand All @@ -296,8 +296,8 @@ public void handle(HttpClientRequest request) {
@Override
public void handle(AsyncResult<HttpClientResponse> asyncResponse) {
if (asyncResponse.failed()) {
logger.error("An error occurs while introspecting access token", asyncResponse.cause());
responseHandler.handle(new UserInfoResponse(false, asyncResponse.cause().getMessage()));
logger.error("An error occurs while getting userinfo from access token", asyncResponse.cause());
responseHandler.handle(new UserInfoResponse(asyncResponse.cause()));
} else {
final HttpClientResponse response = asyncResponse.result();
response.bodyHandler(buffer -> {
Expand All @@ -309,7 +309,18 @@ public void handle(AsyncResult<HttpClientResponse> asyncResponse) {
if (response.statusCode() == HttpStatusCode.OK_200) {
responseHandler.handle(new UserInfoResponse(true, buffer.toString()));
} else {
responseHandler.handle(new UserInfoResponse(false, buffer.toString()));
logger.error(
"An error occurs while getting userinfo from access token. Request ends with status {}: {}",
response.statusCode(),
buffer.toString()
);
responseHandler.handle(
new UserInfoResponse(
new OAuth2ResourceException(
"An error occurs while getting userinfo from access token"
)
)
);
}
});
}
Expand All @@ -320,8 +331,8 @@ public void handle(AsyncResult<HttpClientResponse> asyncResponse) {
new io.vertx.core.Handler<Throwable>() {
@Override
public void handle(Throwable event) {
logger.error("An error occurs while introspecting access token", event);
responseHandler.handle(new UserInfoResponse(false, event.getMessage()));
logger.error("An error occurs while getting userinfo from access token", event);
responseHandler.handle(new UserInfoResponse(event));
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public void shouldNotGetUserInfo() throws Exception {
"xxxx-xxxx-xxxx-xxxx",
userInfoResponse -> {
Assert.assertFalse(userInfoResponse.isSuccess());
Assert.assertEquals("An error occurs while getting userinfo from access token", userInfoResponse.getPayload());
lock.countDown();
}
);
Expand All @@ -280,6 +281,7 @@ public void shouldAppendMissingTrailingSlah() throws Exception {
"xxxx-xxxx-xxxx-xxxx",
userInfoResponse -> {
Assert.assertFalse(userInfoResponse.isSuccess());
Assert.assertEquals("An error occurs while getting userinfo from access token", userInfoResponse.getPayload());
lock.countDown();
}
);
Expand Down

0 comments on commit 9814a5f

Please sign in to comment.