Skip to content

Expose error response json in case extra parameters are given. - #885

Open
doreaimon wants to merge 2 commits into
openid:masterfrom
MichiganLabs:expose-error-response-json
Open

Expose error response json in case extra parameters are given.#885
doreaimon wants to merge 2 commits into
openid:masterfrom
MichiganLabs:expose-error-response-json

Conversation

@doreaimon

Copy link
Copy Markdown

Checklist

  • I read the Contribution Guidelines
  • I signed the CLA and WG Agreements
  • I ran, updated and added unit tests as necessary.
  • I verified the contribution matches existing coding style.
  • I updated the documentation if necessary.

Motivation and Context

We have found that some servers will return non-standard parameters along with the standard ones in their error responses, and we see a need for getting access to those parameters. To facilitate this, we would like to pass back the full original error response JSONObject along in the token request callback in the AuthorizationException.

Description

We held onto the original error response JSONObject and added it as an optional field in the AuthorizationException that is passed to the token request callback.

Comment threadlibrary/java/net/openid/appauth/AuthorizationException.java Outdated
@codecov-commenter

codecov-commenter commented Oct 27, 2022

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.93%. Comparing base (5966cc7) to head (496fbb6).
⚠️ Report is 15 commits behind head on master.

Files with missing linesPatch %Lines
.../java/net/openid/appauth/AuthorizationService.java50.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## master #885 +/- ##
=========================================
Coverage 82.92% 82.93% Complexity 532 532 =========================================
Files 46 46 Lines 2642 2643 +1 Branches 264 264 =========================================
+ Hits 2191 2192 +1 
Misses 351 351 Partials 100 100 

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

467

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errodescriåtipn null null null

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

467+

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+467 to +465

@thereeroyzthereeroyz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__

@thereeroyzthereeroyz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pcuriel

Copy link
Copy Markdown

Very interested in this as well.

In this case, due to a Keycloak custom Authenticator returning additional non-standard fields for some error cases, which there is no way to access with the current implementation of AuthorizationException.

@Nullable
public final JSONObject responseJson;

/**

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add corresponding field for serialization

// Line 142@VisibleForTestingstaticfinalStringKEY_RESPONSE_JSON = "responseJson";

JsonUtil.getStringIfDefined(json, KEY_ERROR),
JsonUtil.getStringIfDefined(json, KEY_ERROR_DESCRIPTION),
JsonUtil.getUriIfDefined(json, KEY_ERROR_URI),
json,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
json,
JsonUtil.getJsonObjectIfDefined(json, KEY_RESPONSE_JSON),

And toJson is missing the reponseJson field serialization:

// Line 663JsonUtil.putIfNotNull(json, KEY_ERROR_URI, errorUri);
JsonUtil.putIfNotNull(json, KEY_RESPONSE_JSON, responseJson);
returnjson;

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@doreaimon@codecov-commenter@pcuriel@joshfriend@pablo-curiel@SgS1312@thereeroyz@Ggabbate88@hyomea