Skip to content

Commit 8c53618

Browse files
Avoid rehandling api based auth response
1 parent ac248ee commit 8c53618

File tree

1 file changed

+11
-5
lines changed
  • components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz

1 file changed

+11
-5
lines changed

components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4341,14 +4341,19 @@ private Response handleApiBasedAuthenticationResponse(OAuthMessage oAuthMessage,
43414341
ObjectMapper objectMapper = new ObjectMapper();
43424342
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
43434343
String jsonString = objectMapper.writeValueAsString(authResponse);
4344+
oAuthMessage.getRequest().setAttribute(IS_API_BASED_AUTH_HANDLED, true);
43444345
return Response.ok().entity(jsonString).build();
43454346

43464347
} else {
4347-
String location = oauthResponse.getMetadata().get("Location").get(0).toString();
4348-
if (StringUtils.isNotBlank(location)) {
4349-
Map<String, String> queryParams = getQueryParamsFromUrl(location);
4350-
String jsonPayload = new Gson().toJson(queryParams);
4351-
return Response.status(HttpServletResponse.SC_OK).entity(jsonPayload).build();
4348+
List<Object> locationHeader = oauthResponse.getMetadata().get("Location");
4349+
if (CollectionUtils.isNotEmpty(locationHeader)) {
4350+
String location = locationHeader.get(0).toString();
4351+
if (StringUtils.isNotBlank(location)) {
4352+
Map<String, String> queryParams = getQueryParamsFromUrl(location);
4353+
String jsonPayload = new Gson().toJson(queryParams);
4354+
oAuthMessage.getRequest().setAttribute(IS_API_BASED_AUTH_HANDLED, true);
4355+
return Response.status(HttpServletResponse.SC_OK).entity(jsonPayload).build();
4356+
}
43524357
}
43534358
}
43544359
} catch (AuthServiceException | JsonProcessingException | UnsupportedEncodingException | URISyntaxException e) {
@@ -4357,6 +4362,7 @@ private Response handleApiBasedAuthenticationResponse(OAuthMessage oAuthMessage,
43574362
params.put(OAuthConstants.OAUTH_ERROR, OAuth2ErrorCodes.SERVER_ERROR);
43584363
params.put(OAuthConstants.OAUTH_ERROR_DESCRIPTION, "Server error occurred while performing authorization.");
43594364
String jsonString = new Gson().toJson(params);
4365+
oAuthMessage.getRequest().setAttribute(IS_API_BASED_AUTH_HANDLED, true);
43604366
return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(jsonString).build();
43614367
}
43624368

0 commit comments

Comments
 (0)