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

Credentials are not returned when trying to login, app gets stuck

Open aakashawalkar opened this issue 2 years ago • 5 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

After logging in with auth0, the credentials cannot be retrieved on Android or the Web (Works for iOS). The warning message, No stored state: unable to handle response appears on the console when the webpage gets stuck and you have to kill the app and relaunch the app to try logging in again.

Initially, I was using the flutter_appauth package for logging in using Auth0 and everything was working fine. Now, I am trying to migrate it to the official Auth0 package i.e. auth0_flutter and it is now working for Android and Web.

Reproduction

  1. Login function below:
Future<Credentials?> login() async {
    try {
      if (kIsWeb) {
        /// Attempt to login the user with the redirect method
          await _auth0Web.loginWithRedirect(
              audience: auth0Audience,
              scopes: authScopes['auth'],
              redirectUrl: auth0RedirectUri);

         return await _auth0Web.credentials();
      } else {
        /// Handle the needed credentials for mobile
        Credentials? credentials = await _auth0
            .webAuthentication(scheme: 'com.project.portal')
            .login(
              audience: auth0Audience,
              scopes: const {'openid', 'profile', 'email', 'offline_access'},
              redirectUrl: auth0RedirectUri,
              idTokenValidationConfig: IdTokenValidationConfig(issuer: 'https://$auth0Domain'),
              safariViewController: const SafariViewController(),
              parameters: {'prompt': 'login'},
            );

        return credentials;
      }
    } on Exception catch (e) {
      print('Error logging in: $e');
      return null;
    }
  }
  1. Call above login function on a button click:
ElevatedButton(
  onPressed: () async {
    final credentials = await login();

    setState(() {
      _credentials = credentials;
    });
  },
  child: const Text('Login'),
),

Additional context

On Auth0, I have first created a new Native Application. I have created a flutter application that supports iOS, Android, and the Web which uses the same configuration from Auth0. The auth0 domain is a custom domain

Flutter Doctor Output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.9, on macOS 14.1.1 23B81 darwin-x64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc2)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.85.0)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

auth0_flutter version

1.3.1

Flutter version

3.13.9

Platform

Android, Web

Platform version(s)

No response

aakashawalkar avatar Dec 12 '23 13:12 aakashawalkar

Hi @aakashawalkar, thanks for raising this.

Can you confirm that you can indeed reproduce this on the auth0_flutter sample app?

Widcket avatar Dec 12 '23 23:12 Widcket

@Widcket - Yes, I see the same behavior on the sample app.

aakashawalkar avatar Dec 13 '23 08:12 aakashawalkar

Thanks. @poovamraj could you please take a look?

Widcket avatar Dec 18 '23 06:12 Widcket

Hi @Widcket @poovamraj -

When I tried tweaking the Auth0 configuration, most of the time I saw the below error message

No stored state - unable to handle the response

Also, sometimes, I see below error messages while logging in -

E/flutter (26530): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: a0.sdk.internal_error.unknown: Received error with code a0.sdk.internal_error.unknown
E/flutter (26530): #0      MethodChannelAuth0FlutterWebAuth.invokeRequest (package:auth0_flutter_platform_interface/src/method_channel_auth0_flutter_web_auth.dart:45:7)
E/flutter (26530): <asynchronous suspension>
E/flutter (26530): #1      MethodChannelAuth0FlutterWebAuth.login (package:auth0_flutter_platform_interface/src/method_channel_auth0_flutter_web_auth.dart:21:9)
E/flutter (26530): <asynchronous suspension>
E/flutter (26530): #2      WebAuthentication.login (package:auth0_flutter/src/mobile/web_authentication.dart:82:25)
E/flutter (26530): <asynchronous suspension>

aakashawalkar avatar Dec 20 '23 12:12 aakashawalkar

Has any solution been found for this issue? I am in the same situation. Trying to migrate away from flutter_appauth, and it works in iOS but not in Android.

sarbogast avatar Sep 12 '24 09:09 sarbogast

Any workarounds to fix this?

pankajpreet avatar Sep 30 '24 21:09 pankajpreet