From aab2c838a24d7ea087af3a6d462c5458f055c1b4 Mon Sep 17 00:00:00 2001 From: Xiaomei Huang Date: Thu, 27 Oct 2022 13:19:41 -0400 Subject: [PATCH 1/2] Expose error response json in case extra parameters are given. --- .../appauth/AuthorizationException.java | 23 +++++++++++++++---- .../openid/appauth/AuthorizationService.java | 8 +++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/library/java/net/openid/appauth/AuthorizationException.java b/library/java/net/openid/appauth/AuthorizationException.java index e2057ce7..a51d01ef 100644 --- a/library/java/net/openid/appauth/AuthorizationException.java +++ b/library/java/net/openid/appauth/AuthorizationException.java @@ -464,22 +464,22 @@ public static AuthorizationException byString(String error) { private static AuthorizationException generalEx(int code, @Nullable String errorDescription) { return new AuthorizationException( - TYPE_GENERAL_ERROR, code, null, errorDescription, null, null); + TYPE_GENERAL_ERROR, code, null, errorDescription, null, null, null); } private static AuthorizationException authEx(int code, @Nullable String error) { return new AuthorizationException( - TYPE_OAUTH_AUTHORIZATION_ERROR, code, error, null, null, null); + TYPE_OAUTH_AUTHORIZATION_ERROR, code, error, null, null, null, null); } private static AuthorizationException tokenEx(int code, @Nullable String error) { return new AuthorizationException( - TYPE_OAUTH_TOKEN_ERROR, code, error, null, null, null); + TYPE_OAUTH_TOKEN_ERROR, code, error, null, null, null, null); } private static AuthorizationException registrationEx(int code, @Nullable String error) { return new AuthorizationException( - TYPE_OAUTH_REGISTRATION_ERROR, code, error, null, null, null); + TYPE_OAUTH_REGISTRATION_ERROR, code, error, null, null, null, null); } /** @@ -496,6 +496,7 @@ public static AuthorizationException fromTemplate( ex.error, ex.errorDescription, ex.errorUri, + ex.responseJson, rootCause); } @@ -508,13 +509,15 @@ public static AuthorizationException fromOAuthTemplate( @NonNull AuthorizationException ex, @Nullable String errorOverride, @Nullable String errorDescriptionOverride, - @Nullable Uri errorUriOverride) { + @Nullable Uri errorUriOverride, + @NonNull JSONObject responseJson) { return new AuthorizationException( ex.type, ex.code, (errorOverride != null) ? errorOverride : ex.error, (errorDescriptionOverride != null) ? errorDescriptionOverride : ex.errorDescription, (errorUriOverride != null) ? errorUriOverride : ex.errorUri, + responseJson, null); } @@ -533,6 +536,7 @@ public static AuthorizationException fromOAuthRedirect( error, errorDescription != null ? errorDescription : base.errorDescription, errorUri != null ? Uri.parse(errorUri) : base.errorUri, + base.responseJson, null); } @@ -559,6 +563,7 @@ public static AuthorizationException fromJson(@NonNull JSONObject json) throws J JsonUtil.getStringIfDefined(json, KEY_ERROR), JsonUtil.getStringIfDefined(json, KEY_ERROR_DESCRIPTION), JsonUtil.getUriIfDefined(json, KEY_ERROR_URI), + json, null); } @@ -631,6 +636,12 @@ private static Map exceptionMapByString( @Nullable public final Uri errorUri; + /** + * The raw error json object + */ + @Nullable + public final JSONObject responseJson; + /** * Instantiates an authorization request with optional root cause information. */ @@ -640,6 +651,7 @@ public AuthorizationException( @Nullable String error, @Nullable String errorDescription, @Nullable Uri errorUri, + @Nullable JSONObject responseJson, @Nullable Throwable rootCause) { super(errorDescription, rootCause); this.type = type; @@ -647,6 +659,7 @@ public AuthorizationException( this.error = error; this.errorDescription = errorDescription; this.errorUri = errorUri; + this.responseJson = responseJson; } /** diff --git a/library/java/net/openid/appauth/AuthorizationService.java b/library/java/net/openid/appauth/AuthorizationService.java index b3bdf7ed..9028c2e8 100644 --- a/library/java/net/openid/appauth/AuthorizationService.java +++ b/library/java/net/openid/appauth/AuthorizationService.java @@ -673,7 +673,9 @@ protected void onPostExecute(JSONObject json) { error, json.optString(AuthorizationException.PARAM_ERROR_DESCRIPTION, null), UriUtil.parseUriIfAvailable( - json.optString(AuthorizationException.PARAM_ERROR_URI))); + json.optString(AuthorizationException.PARAM_ERROR_URI)), + json); + } catch (JSONException jsonEx) { ex = AuthorizationException.fromTemplate( GeneralErrors.JSON_DESERIALIZATION_ERROR, @@ -821,7 +823,9 @@ protected void onPostExecute(JSONObject json) { error, json.getString(AuthorizationException.PARAM_ERROR_DESCRIPTION), UriUtil.parseUriIfAvailable( - json.getString(AuthorizationException.PARAM_ERROR_URI))); + json.getString(AuthorizationException.PARAM_ERROR_URI)), + json); + } catch (JSONException jsonEx) { ex = AuthorizationException.fromTemplate( GeneralErrors.JSON_DESERIALIZATION_ERROR, From 496fbb675a8ae18349c0401e27c9bc776ca21979 Mon Sep 17 00:00:00 2001 From: Xiaomei Huang Date: Thu, 27 Oct 2022 14:04:37 -0400 Subject: [PATCH 2/2] Make responseJson argument nullable. --- library/java/net/openid/appauth/AuthorizationException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/java/net/openid/appauth/AuthorizationException.java b/library/java/net/openid/appauth/AuthorizationException.java index a51d01ef..0a139db8 100644 --- a/library/java/net/openid/appauth/AuthorizationException.java +++ b/library/java/net/openid/appauth/AuthorizationException.java @@ -510,7 +510,7 @@ public static AuthorizationException fromOAuthTemplate( @Nullable String errorOverride, @Nullable String errorDescriptionOverride, @Nullable Uri errorUriOverride, - @NonNull JSONObject responseJson) { + @Nullable JSONObject responseJson) { return new AuthorizationException( ex.type, ex.code,