auth0-flutter icon indicating copy to clipboard operation
auth0-flutter copied to clipboard

Android error: a0.authentication_canceled: The user closed the browser app and the authentication was canceled.

Open fbernaly opened this issue 1 year ago • 1 comments

Checklist

  • [X] The issue can be reproduced in the auth0_flutter sample app (or N/A).
  • [X] I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • [X] I have looked into the API documentation and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • [X] I agree to the terms within the Auth0 Code of Conduct.

Description

I clone this repo to play with the example app and follow the steps to use my domain and client id. I renamed .env.example to .env and filled with my values. Same for strings.xml.example to strings.xml and replace with my values. I edited the example app L54 and L83, with these code:

// L54
final result = await auth0.webAuthentication().login(
        redirectUrl: '<my_package_id>://login-callback',
        useEphemeralSession: true,
);

// L83
await auth0.webAuthentication().logout(
            returnTo: '<my_package_id>://logout-callback');

and run the app in both iOS and Android. It works on iOS, after tapping on Web Auth Login button, I can see the web page, enter my email and password and tap Log In, then I can see the idToken printed in the Flutter app. But when I run the same code on Android (both simulator or actual device) I always see the web page being dismissed automatically without user interaction and this is the error :

a0.authentication_canceled: The user closed the browser app and the authentication was canceled.

How can I fix that code? What am I missing to configure in Android to make it work?

Reproduction

  1. clone repo
  2. edit env file with your values
  3. edit strings.xml with your values
  4. edit webAuthLogin() method L54 with:
final result = await auth0.webAuthentication().login(
        redirectUrl: '<my_package_id>://login-callback',
        useEphemeralSession: true,
);
  1. edit webAuthLogout() method L83 with:
await auth0.webAuthentication().logout(
            returnTo: '<my_package_id>://logout-callback');
  1. run the app on iOS, tap on 'Web Auth Login', you will be able to log in and the idToken will be printed in the Flutter app.
  2. run the app on Android, tap on 'Web Auth Login',, you will see the web being launched and dismissed automatically without user interaction. And error is
a0.authentication_canceled: The user closed the browser app and the authentication was canceled.

Additional context

No response

auth0_flutter version

auth0_flutter

Flutter version

3.19.3

Platform

Android, iOS

Platform version(s)

No response

fbernaly avatar Jun 06 '24 00:06 fbernaly

This is a video of what I am seeing:

https://github.com/auth0/auth0-flutter/assets/7014968/a8894943-e0d2-4893-b987-49bc8c0b1aa6

fbernaly avatar Jun 06 '24 00:06 fbernaly

@fbernaly Did you find a fix for this issue? I am facing same issue in Android.

Venkat-dev9 avatar Nov 07 '24 21:11 Venkat-dev9

We had this exact issue. If you're using https in Auth0, you need to add the SHA256 fingerprints of your app’s signing certificate. You can update it here: Applications > Specific Application > Settings > Advanced Settings > Device Settings > Key Hashes

rileyjhardy avatar Dec 10 '24 16:12 rileyjhardy

We are facing the same error. @rileyjhardy Do you have a solution if the app is not signed yet during the development phase?

Edit: We are now using a custom scheme.

mluttmann avatar Dec 12 '24 14:12 mluttmann

any fix here? same issue in Android samsung - SM-G998U1

nininea avatar Dec 24 '24 09:12 nininea

Hi all, if this is happening for you with a custom scheme –are you using an emulator or a real device? Some emulators may not have a browser installed that supports Custom Tabs.

In you're using HTTPS, then you need to set up App Links, and that includes adding your app's SHA256 fingerprints to your Auth0 application's configuration. This is analogous as to how using HTTPS callbacks with iOS requires setting up an Associated Domain.

Widcket avatar Jan 30 '25 17:01 Widcket

Closing, as I believe the above answers your questions. Feel free to chime back in if you'd prefer to reopen.

Widcket avatar Feb 07 '25 15:02 Widcket