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

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

Open
6 tasks done
aakashawalkar opened this issue Dec 12, 2023 · 4 comments
Open
6 tasks done
Assignees
Labels
android more info needed This issue is waiting for more information in order to progress web

Comments

@aakashawalkar
Copy link

Checklist

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

@Widcket
Copy link
Contributor

Widcket commented Dec 12, 2023

Hi @aakashawalkar, thanks for raising this.

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

@Widcket Widcket added the more info needed This issue is waiting for more information in order to progress label Dec 12, 2023
@aakashawalkar
Copy link
Author

aakashawalkar commented Dec 13, 2023

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

@Widcket
Copy link
Contributor

Widcket commented Dec 18, 2023

Thanks. @poovamraj could you please take a look?

@aakashawalkar
Copy link
Author

aakashawalkar commented Dec 20, 2023

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android more info needed This issue is waiting for more information in order to progress web
Projects
None yet
Development

No branches or pull requests

3 participants