mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ssooidc): name the modeled exception in x-amzn-ErrorType (#7919)
SSO OIDC errors carried the OAuth error code in the body but no x-amzn-ErrorType header. AWS sends both, and the SDKs resolve the modeled exception from the header, so a pending device authorization surfaced as an unmodeled 400 instead of AuthorizationPendingException: `aws sso login` stopped polling and failed with "An error occurred (400) when calling the CreateToken operation". Every OIDC error now names its exception, derived from the OAuth code (authorization_pending -> AuthorizationPendingException, slow_down -> SlowDownException, invalid_grant -> InvalidGrantException, ...). Address review on #7919: server_error is the one SSO OIDC error whose modeled exception is not named after its OAuth code, so it mapped to ServerErrorException, which the SDKs cannot resolve. It now maps to InternalServerException. A unit test pins the header name for every OAuth code Floci returns.
This commit is contained in:
1 parent
464e32fff4
commit
bfea1bec1c
3 files changed
+113
-44
No files matched your search
@@ -409,6 +409,25 @@ public class SsoOidcController {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("error", error);
|
||||
response.put("error_description", description);
|
||||
return Response.status(status).type(MediaType.APPLICATION_JSON).entity(response).build();
|
||||
// AWS SDKs read the modeled exception from this header, not from the OAuth "error" body
|
||||
// member: without it a pending device authorization is not retried and `aws sso login` fails.
|
||||
return Response.status(status).type(MediaType.APPLICATION_JSON)
|
||||
.header("x-amzn-ErrorType", exceptionName(error))
|
||||
.entity(response).build();
|
||||
}
|
||||
|
||||
/** OAuth error code to the SSO OIDC exception name, e.g. authorization_pending to AuthorizationPendingException. */
|
||||
static String exceptionName(String error) {
|
||||
// The one modeled exception not named after its OAuth code.
|
||||
if ("server_error".equals(error)) {
|
||||
return "InternalServerException";
|
||||
}
|
||||
StringBuilder name = new StringBuilder();
|
||||
for (String part : error.split("_")) {
|
||||
if (!part.isEmpty()) {
|
||||
name.append(Character.toUpperCase(part.charAt(0))).append(part.substring(1));
|
||||
}
|
||||
}
|
||||
return name.append("Exception").toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user