-
Notifications
You must be signed in to change notification settings - Fork 82
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
Raise Unauthorized and Access Denied errors through callback [SDK-2480] #618
Conversation
@@ -75,6 +77,11 @@ public void onEvent(@LockEvent int event, @NonNull Intent data) { | |||
* @param data the intent received at the end of the login process. | |||
*/ | |||
private void parseAuthentication(Intent data) { | |||
if (data.hasExtra(Constants.EXCEPTION_EXTRA)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if an exception is present after an authentication event, raise it through the onError
method
@@ -150,8 +151,8 @@ private void processEvent(@NonNull Context context, @NonNull Intent data) { | |||
switch (action) { | |||
case Constants.AUTHENTICATION_ACTION: | |||
Log.v(TAG, "AUTHENTICATION action received in our BroadcastReceiver"); | |||
if (data.hasExtra(Constants.ERROR_EXTRA)) { | |||
callback.onError(new LockException(data.getStringExtra(Constants.ERROR_EXTRA))); | |||
if (data.hasExtra(Constants.EXCEPTION_EXTRA)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The former was not used from the code. Replaced with a more meaningful extra that can hold the Exception instance with all the details.
@@ -484,9 +492,13 @@ public void onFailure(@NonNull final Dialog dialog) { | |||
|
|||
@Override | |||
public void onFailure(@NonNull final AuthenticationException exception) { | |||
Log.e(TAG, "Failed to authenticate the user: " + exception.getCode(), exception); | |||
if (exception.isRuleError() || exception.isAccessDenied()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
covers the webauth flow for Lock
@@ -506,12 +518,16 @@ public void onSuccess(@Nullable Credentials credentials) { | |||
|
|||
@Override | |||
public void onFailure(@NonNull final AuthenticationException error) { | |||
Log.e(TAG, "Failed to authenticate the user: " + error.getMessage(), error); | |||
final AuthenticationError authError = loginErrorBuilder.buildFrom(error); | |||
Log.e(TAG, "Failed to authenticate the user: " + error.getCode(), error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
covers the database/enterprise flow for Lock
@@ -494,6 +502,10 @@ public void onSuccess(@Nullable Credentials credentials) { | |||
@Override | |||
public void onFailure(@NonNull final AuthenticationException error) { | |||
Log.e(TAG, "Failed to authenticate the user: " + error.getMessage(), error); | |||
if (error.isRuleError() || error.isAccessDenied()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
covers the passwordless flow for PasswordlessLock
@@ -507,9 +519,13 @@ public void onFailure(@NonNull final Dialog dialog) { | |||
|
|||
@Override | |||
public void onFailure(@NonNull final AuthenticationException exception) { | |||
Log.e(TAG, "Failed to authenticate the user: " + exception.getCode(), exception); | |||
if (exception.isRuleError() || exception.isAccessDenied()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
covers the webauth flow for PasswordlessLock
data.putExtra(Constants.EXCEPTION_EXTRA, error); | ||
callback.onEvent(LockEvent.AUTHENTICATION, data); | ||
|
||
assertThat(callback, hasError()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checks that when an "exception extra" is present, the onError
is invoked with a non-null value for the exception
@@ -542,7 +558,7 @@ public void onSuccess(@Nullable final DatabaseUser user) { | |||
|
|||
@Override | |||
public void onFailure(@NonNull final AuthenticationException error) { | |||
Log.e(TAG, "Failed to create the user: " + error.getMessage(), error); | |||
Log.e(TAG, "Failed to create the user: " + error.getCode(), error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed a few log lines, moved them up in the code and used the error code instead. These might be removed before the release.
Changes
These two error codes
unauthorized
andaccess_denied
can be raised through Auth0 Rules.To improve the use case of handling custom errors in the authentication pipeline, these will now be raised directly through the provided callback instead of displaying an orange toast / snackbar with a generic error message. That means developers will need to handle this use case from now on.
This represents a breaking change in behavior. The public API remains the same after this PR.
Affected flows: Any authentication flow. (e.g. Passwordless, Database, Enterprise, WebAuth)
References
See
SDK-2480
Testing
There are currently no tests for this part of the widget. This change was tested manually.