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

Add WebAuthProvider Rule error message parsing #89

Merged
merged 3 commits into from
Apr 6, 2017

Conversation

lbalmaceda
Copy link
Contributor

Support custom Auth0 Rules error messages and construct a proper exception with the unauthorized code and the given user's description. You might need to update your Rule's script as the error must be an instance of UnauthorizedError. Check this article for more context.

Fixes #87.

@lbalmaceda lbalmaceda added this to the v1-Next milestone Apr 4, 2017
@lbalmaceda lbalmaceda changed the title Fix WebAuthProvider custom Rule error message parsing Fix WebAuthProvider Rule error message parsing Apr 4, 2017
@@ -1550,6 +1584,12 @@ private String createHash(@Nullable String idToken, @Nullable String accessToken
}
hash = hash.concat("error=" + error);
}
if (errorDescription != null) {
if (!hash.endsWith("&")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is working, but I don't think it can ever be false (except if the values end with a & which is wrong).
all these checks should be endsWith("#") just in case all previous values where empty/null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess i wanted to do that check but got lost and used the same & for comparison. Good catch 👍

if (errorValue == null) {
return;
}
Log.e(TAG, "Error, access denied. Check that the required Permissions are granted and that the Application has this Connection configured in Auth0 Dashboard.");
if (ERROR_VALUE_ACCESS_DENIED.equalsIgnoreCase(errorValue)) {
throw new AuthenticationException(ERROR_VALUE_ACCESS_DENIED, "Permissions were not granted. Try again.");
} else if (ERROR_VALUE_UNAUTHORIZED.equalsIgnoreCase(errorValue)) {
throw new AuthenticationException(ERROR_VALUE_UNAUTHORIZED, errorDescription);
Copy link
Contributor

Choose a reason for hiding this comment

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

can errorDescription be null/empty? in the case of a rule error, this is something we don't control, right? it's user defined.
maybe we can add a generic message "Unknown error" in case it's null, just to avoid a null description?

Copy link
Contributor Author

@lbalmaceda lbalmaceda Apr 5, 2017

Choose a reason for hiding this comment

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

Yes! If the key doesn't exist on the map, then the returned value will be null. This case is covered by the behavior of the AuthenticationException class. exception.getDescription() will always return a valid message. Maybe instead of checking for null I can use TextUtils.isEmptyString(description) here so it checks for null and empty strings. What do you think?

@lbalmaceda lbalmaceda force-pushed the fix-oauth-rule-error-parsing branch from cac8ce2 to bced8e5 Compare April 5, 2017 16:59
@lbalmaceda lbalmaceda force-pushed the fix-oauth-rule-error-parsing branch from d028047 to 4335edd Compare April 5, 2017 20:02
@lbalmaceda lbalmaceda merged commit f65585d into master Apr 6, 2017
@lbalmaceda lbalmaceda deleted the fix-oauth-rule-error-parsing branch April 6, 2017 14:34
@lbalmaceda lbalmaceda changed the title Fix WebAuthProvider Rule error message parsing Add WebAuthProvider Rule error message parsing Apr 6, 2017
@lbalmaceda lbalmaceda modified the milestones: v1-Next, 1.7.0 Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants