Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions library/java/net/openid/appauth/AuthorizationException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link

Choose a reason for hiding this comment

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

467

Copy link

Choose a reason for hiding this comment

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

Null

Copy link

Choose a reason for hiding this comment

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

General error

Copy link

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

Copy link

Choose a reason for hiding this comment

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

467+

Copy link

Choose a reason for hiding this comment

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

+467 to +465

}

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

/**
Expand All @@ -496,6 +496,7 @@ public static AuthorizationException fromTemplate(
ex.error,
ex.errorDescription,
ex.errorUri,
ex.responseJson,
rootCause);
}

Expand All @@ -508,13 +509,15 @@ public static AuthorizationException fromOAuthTemplate(
@NonNull AuthorizationException ex,
@Nullable String errorOverride,
@Nullable String errorDescriptionOverride,
@Nullable Uri errorUriOverride) {
@Nullable Uri errorUriOverride,
@Nullable 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);
}

Expand All @@ -533,6 +536,7 @@ public static AuthorizationException fromOAuthRedirect(
error,
errorDescription != null ? errorDescription : base.errorDescription,
errorUri != null ? Uri.parse(errorUri) : base.errorUri,
base.responseJson,
null);
}

Expand All @@ -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,

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 663
JsonUtil.putIfNotNull(json, KEY_ERROR_URI, errorUri);
JsonUtil.putIfNotNull(json, KEY_RESPONSE_JSON, responseJson);
return json;

null);
}

Expand Down Expand Up @@ -631,6 +636,12 @@ private static Map<String, AuthorizationException> exceptionMapByString(
@Nullable
public final Uri errorUri;

/**
* The raw error json object
*/
@Nullable
public final JSONObject responseJson;

/**

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
@VisibleForTesting
static final String KEY_RESPONSE_JSON = "responseJson";

* Instantiates an authorization request with optional root cause information.
*/
Expand All @@ -640,13 +651,15 @@ public AuthorizationException(
@Nullable String error,
@Nullable String errorDescription,
@Nullable Uri errorUri,
@Nullable JSONObject responseJson,
@Nullable Throwable rootCause) {
super(errorDescription, rootCause);
this.type = type;
this.code = code;
this.error = error;
this.errorDescription = errorDescription;
this.errorUri = errorUri;
this.responseJson = responseJson;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions library/java/net/openid/appauth/AuthorizationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down