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

Error message is unclear when oauth is missing from config #4922

Open
4 of 14 tasks
sisygoboom opened this issue May 26, 2024 · 3 comments
Open
4 of 14 tasks

Error message is unclear when oauth is missing from config #4922

sisygoboom opened this issue May 26, 2024 · 3 comments
Assignees
Labels
auth Issues related to the Auth Category bug Something is not working; the issue has reproducible steps and has been reproduced good first issue Good for newcomers pending-release Issues that have been addressed in main but have not been released

Comments

@sisygoboom
Copy link

sisygoboom commented May 26, 2024

Description

Full error:

iOS error:

flutter: Successfully configured
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: No instance found for CognitoOAuthConfig
package:amplify_core/src/state_machine/dependency_manager.dart 69:7                       DependencyManager.expect
package:amplify_core/src/state_machine/dependency_manager.dart 148:22                     _ScopedDependencyManager.expect
package:amplify_core/src/state_machine/state_machine.dart 146:26                          StateMachineManager.expect
package:amplify_core/src/state_machine/state_machine.dart 410:60                          StateMachine.expect
package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 34:37   HostedUiStateMachine._config
package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 35:42   HostedUiStateMachine._keys
package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 119:12  HostedUiStateMachine.onSignIn
package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_ma<…>
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: No instance found for CognitoOAuthConfig
package:amplify_core/src/state_machine/dependency_manager.dart 69:7                       DependencyManager.expect
package:amplify_core/src/state_machine/dependency_manager.dart 148:22                     _ScopedDependencyManager.expect
package:amplify_core/src/state_machine/state_machine.dart 146:26                          StateMachineManager.expect
package:amplify_core/src/state_machine/state_machine.dart 410:60                          StateMachine.expect
package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 34:37   HostedUiStateMachine._config
package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 35:42   HostedUiStateMachine._keys
package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 119:12  HostedUiStateMachine.onSignIn
package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_ma<…>

Android error:

E/flutter ( 5553): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: No instance found for CognitoOAuthConfig
E/flutter ( 5553): package:amplify_core/src/state_machine/dependency_manager.dart 69:7                       DependencyManager.expect
E/flutter ( 5553): package:amplify_core/src/state_machine/dependency_manager.dart 148:22                     _ScopedDependencyManager.expect
E/flutter ( 5553): package:amplify_core/src/state_machine/state_machine.dart 146:26                          StateMachineManager.expect
E/flutter ( 5553): package:amplify_core/src/state_machine/state_machine.dart 410:60                          StateMachine.expect
E/flutter ( 5553): package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 34:37   HostedUiStateMachine._config
E/flutter ( 5553): package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 35:42   HostedUiStateMachine._keys
E/flutter ( 5553): package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 119:12  HostedUiStateMachine.onSignIn
E/flutter ( 5553): package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart 57:15   HostedUiStateMachine.resolve
E/flutter ( 5553): package:amplify_core/src/state_machine/state_machine.dart 262:59                          StateMachine._listenForEvents.<fn>.<fn>
E/flutter ( 5553): dart:async/future.dart 422:39                                                             new Future.delayed.<fn>
E/flutter ( 5553): dart:async/zone.dart 1391:47                                                              _rootRun
E/flutter ( 5553): dart:async/zone.dart 1301:19                                                              _CustomZone.run
E/flutter ( 5553): dart:async/zone.dart 1209:7                                                               _CustomZone.runGuarded
E/flutter ( 5553): dart:async/zone.dart 1249:23                                                              _CustomZone.bindCallbackGuarded.<fn>
E/flutter ( 5553): dart:async/zone.dart 1399:13                                                              _rootRun
E/flutter ( 5553): dart:async/zone.dart 1301:19                                                              _CustomZone.run
E/flutter ( 5553): dart:async/zone.dart 1233:23                                                              _CustomZone.bindCallback.<fn>
E/flutter ( 5553): dart:async-patch/timer_patch.dart 18:15                                                   Timer._createTimer.<fn>
E/flutter ( 5553): dart:isolate-patch/timer_impl.dart 398:19                                                 _Timer._runTimers
E/flutter ( 5553): dart:isolate-patch/timer_impl.dart 429:5                                                  _Timer._handleMessage
E/flutter ( 5553): dart:isolate-patch/isolate_patch.dart 184:12                                              _RawReceivePort._handleMessage
E/flutter ( 5553): ===== asynchronous gap ===========================
E/flutter ( 5553): package:amplify_core/src/state_machine/event.dart 39:47                                   new EventCompleter
E/flutter ( 5553): package:amplify_core/src/state_machine/state_machine.dart 157:23                          StateMachineManager.accept
E/flutter ( 5553): package:amplify_auth_cognito_dart/src/auth_plugin_impl.dart 329:10                        AmplifyAuthCognitoDart.signInWithWebUI
E/flutter ( 5553): package:amplify_core/src/category/amplify_auth_category.dart 1052:29                      AuthCategory.signInWithWebUI.<fn>
E/flutter ( 5553): dart:async/zone.dart 1399:13                                                              _rootRun
E/flutter ( 5553): dart:async/zone.dart 1301:19                                                              _CustomZone.run
E/flutter ( 5553): dart:async/zone.dart 1804:10                                                              _runZoned
E/flutter ( 5553): dart:async/zone.dart 1747:10                                                              runZoned
E/flutter ( 5553): package:amplify_core/src/http/amplify_category_method.dart 147:10                         identifyCall
E/flutter ( 5553): package:amplify_core/src/category/amplify_auth_category.dart 1050:7                       AuthCategory.signInWithWebUI
E/flutter ( 5553): package:datingapp/widgets/login/socialLogin.dart 101:30                                   SocialLoginButtons.signInWithProvider
E/flutter ( 5553): package:datingapp/widgets/login/socialLogin.dart 53:15                                    SocialLoginButtons.loginButton.<fn>
E/flutter ( 5553): package:flutter/src/material/ink_well.dart 1183:21                                        _InkResponseState.handleTap
E/flutter ( 5553): package:flutter/src/gestures/recognizer.dart 315:24                                       GestureRecognizer.invokeCallback
E/flutter ( 5553): package:flutter/src/gestures/tap.dart 652:11                                              TapGestureRecognizer.handleTapUp
E/flutter ( 5553): package:flutter/src/gestures/tap.dart 309:5                                               BaseTapGestureRecognizer._checkUp
E/flutter ( 5553): package:flutter/src/gestures/tap.dart 242:7                                               BaseTapGestureRecognizer.handlePrimaryPointer
E/flutter ( 5553): package:flutter/src/gestures/recognizer.dart 670:9                                        PrimaryPointerGestureRecognizer.handleEvent
E/flutter ( 5553): package:flutter/src/gestures/pointer_router.dart 98:12                                    PointerRouter._dispatch
E/flutter ( 5553): package:flutter/src/gestures/pointer_router.dart 143:9                                    PointerRouter._dispatchEventToRoutes.<fn>
E/flutter ( 5553): dart:collection-patch/compact_hash.dart 633:13                                            _LinkedHashMapMixin.forEach
E/flutter ( 5553): package:flutter/src/gestures/pointer_router.dart 141:18                                   PointerRouter._dispatchEventToRoutes
E/flutter ( 5553): package:flutter/src/gestures/pointer_router.dart 127:7                                    PointerRouter.route
E/flutter ( 5553): package:flutter/src/gestures/binding.dart 495:19                                          GestureBinding.handleEvent
E/flutter ( 5553): package:flutter/src/gestures/binding.dart 475:22                                          GestureBinding.dispatchEvent
E/flutter ( 5553): package:flutter/src/rendering/binding.dart 430:11                                         RendererBinding.dispatchEvent
E/flutter ( 5553): package:flutter/src/gestures/binding.dart 420:7                                           GestureBinding._handlePointerEventImmediately
E/flutter ( 5553): package:flutter/src/gestures/binding.dart 383:5                                           GestureBinding.handlePointerEvent
E/flutter ( 5553): package:flutter/src/gestures/binding.dart 330:7                                           GestureBinding._flushPointerEventQueue
E/flutter ( 5553): package:flutter/src/gestures/binding.dart 299:9                                           GestureBinding._handlePointerDataPacket
E/flutter ( 5553): dart:ui/hooks.dart 328:13                                                                 _invoke1
E/flutter ( 5553): dart:ui/platform_dispatcher.dart 429:7                                                    PlatformDispatcher._dispatchPointerDataPacket
E/flutter ( 5553): dart:ui/hooks.dart 262:31                                                                 _dispatchPointerDataPacket
E/flutter ( 5553):

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

  1. configure social login with Facebook and google, have email login disabled, mobile login enabled
  2. configure the authenticator with a custom UI:
    return Authenticator(
      authenticatorBuilder: (BuildContext context, AuthenticatorState state) {
        return SocialLoginButtons();
      },
  1. when social login button is clicked, execute login with webui:
        case LoginPlatform.facebook:
          await Amplify.Auth.signInWithWebUI(provider: AuthProvider.facebook);
          break;
        case LoginPlatform.google:
          await Amplify.Auth.signInWithWebUI(provider: AuthProvider.google);
          break;
  1. error should surface with no web browser open

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.22.0 & 3.19.6

Amplify Flutter Version

2.0.0

Deployment Method

AWS CDK

Schema

No response

@Jordan-Nelson
Copy link
Contributor

Hello @sisygoboom. Can you share your Amplify Configuration? You can remove any sensitive or app specific information.

@Jordan-Nelson Jordan-Nelson added auth Issues related to the Auth Category pending-response Issue is pending response from the issue requestor pending-triage This issue is in the backlog of issues to triage labels May 28, 2024
@sisygoboom
Copy link
Author

Auth construct:

import { defineAuth, secret } from '@aws-amplify/backend';

/**
 * Define and configure your auth resource
 * @see https://docs.amplify.aws/gen2/build-a-backend/auth
 */
export const auth = defineAuth({
  loginWith: {
    phone: true,
    externalProviders: {
      facebook: {
        clientId: secret('FACEBOOK_APP_ID'),
        clientSecret: secret('FACEBOOK_APP_SECRET'),
        scopes: ['email', 'public_profile'],
      },
      google: {
        clientId: secret('GOOGLE_CLIENT_ID'),
        clientSecret: secret('GOOGLE_CLIENT_SECRET'),
        scopes: ['email', 'profile'],
      },
      callbackUrls: ['paritae://callback'], // Ensure these match your actual callback URLs
      logoutUrls: ['paritae://logout'], // Ensure these match your actual logout URLs
    },    
  },
  userAttributes: {
    email: {
      required: true,
      mutable: true
    },
    phoneNumber: {
      required: false,
      mutable: true
    },
    profilePicture: {
      required: false,
      mutable: true,
    }
  }
});

amplify config:

const amplifyConfig = '''{
  "UserAgent": "@aws-amplify/client-config/1.0.2",
  "Version": "1.0",
  "auth": {
    "plugins": {
      "awsCognitoAuthPlugin": {
        "UserAgent": "@aws-amplify/client-config/1.0.2",
        "Version": "1.0",
        "CognitoUserPool": {
          "Default": {
            "PoolId": "REDACTED",
            "AppClientId": "REDACTED",
            "Region": "REDACTED"
          }
        },
        "CredentialsProvider": {
          "CognitoIdentity": {
            "Default": {
              "PoolId": "REDACTED",
              "Region": "REDACTED"
            }
          }
        },
        "Auth": {
          "Default": {
            "authenticationFlowType": "USER_SRP_AUTH",
            "passwordProtectionSettings": {
              "passwordPolicyMinLength": 8,
              "passwordPolicyCharacters": [
                "REQUIRES_NUMBERS",
                "REQUIRES_LOWERCASE",
                "REQUIRES_UPPERCASE",
                "REQUIRES_SYMBOLS"
              ]
            },
            "signupAttributes": [
              "EMAIL"
            ],
            "usernameAttributes": [
              "PHONE_NUMBER"
            ],
            "verificationMechanisms": [
              "PHONE_NUMBER"
            ]
          }
        },
        "AppSync": {
          "Default": {
            "ApiUrl": "REDACTED",
            "Region": "REDACTED",
            "AuthMode": "REDACTED",
            "ClientDatabasePrefix": "REDACTED"
          },
          "data_AMAZON_COGNITO_USER_POOLS": {
            "ApiUrl": "REDACTED",
            "Region": "REDACTED",
            "AuthMode": "REDACTED",
            "ClientDatabasePrefix": "REDACTED"
          }
        }
      }
    }
  },
  "api": {
    "plugins": {
      "awsAPIPlugin": {
        "data": {
          "endpointType": "GraphQL",
          "endpoint": "REDACTED",
          "region": "REDACTED",
          "authorizationType": "REDACTED"
        }
      }
    }
  }
}''';

Command used:

npx ampx sandbox --outputs-format dart --outputs-out-dir lib --outputs-version 0

@Jordan-Nelson
Copy link
Contributor

@sisygoboom Thank you. It looks like the issue is that the oAuth info isn't added to your config. We have an issue open for this already: aws-amplify/amplify-backend#1551

I am going to keep this issue open because Amplify Flutter should throw a better error message in this scenario.

@Jordan-Nelson Jordan-Nelson changed the title Bad state: No instance found for CognitoOAuthConfig Error message is unclear when oauth is missing from config May 28, 2024
@Jordan-Nelson Jordan-Nelson added bug Something is not working; the issue has reproducible steps and has been reproduced good first issue Good for newcomers and removed pending-response Issue is pending response from the issue requestor pending-triage This issue is in the backlog of issues to triage labels May 28, 2024
@NikaHsn NikaHsn self-assigned this Jun 12, 2024
@NikaHsn NikaHsn added the pending-release Issues that have been addressed in main but have not been released label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth Category bug Something is not working; the issue has reproducible steps and has been reproduced good first issue Good for newcomers pending-release Issues that have been addressed in main but have not been released
Projects
None yet
Development

No branches or pull requests

3 participants