Skip to content

Lack support of using both API plugin multi-auth and DataStore plugin multi-auth in the same App #1867

@dorontal

Description

@dorontal

Description

When you have more than one Auth configured in amplifyconfiguration.dart - the function Amplify.DataStore.observeQuery() throws an exception. You can see in the console errors that are provided from the Android emulator that the failure is due to the fact that Amplify Flutter cannot yet handle multiple Auth in the same configuration file. But the Amplify Flutter documentation explains in detail that this should be available, (see https://docs.amplify.aws/lib/datastore/setup-auth-rules/q/platform/flutter/#configure-multiple-authorization-types).

Here are the log lines from the VSCode console - those come from the Amplify libraries and/or Android libraries running on Android emulated OS:

I/amplify:aws-datastore( 4037): Orchestrator lock acquired.
I/amplify:aws-datastore( 4037): Orchestrator transitioning from LOCAL_ONLY to SYNC_VIA_API
I/amplify:aws-datastore( 4037): Setting currentState to SYNC_VIA_API
I/amplify:aws-datastore( 4037): Starting API synchronization mode.
I/amplify:aws-datastore( 4037): Starting processing subscription events.
I/amplify:aws-datastore( 4037): Orchestrator lock released.
E/amplify:aws-datastore( 4037): Failure encountered while attempting to start API sync.
E/amplify:aws-datastore( 4037): DataStoreException{message=Error during subscription., cause=ApiException{message=There is more than one API configured for this plugin with matching endpoint type., cause=null, recoverySuggestion=Please specify the name of API to invoke in the API method.}, recoverySuggestion=Evaluate details.}
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$subscription$3(AppSyncClient.java:331)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.appsync.-$$Lambda$AppSyncClient$797ziDK0io-qXODzROLOA77stS8.accept(Unknown Source:4)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.aws.AWSApiPlugin.subscribe(AWSApiPlugin.java:285)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.ApiCategory.subscribe(ApiCategory.java:91)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.appsync.AppSyncClient.subscription(AppSyncClient.java:335)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.appsync.AppSyncClient.onCreate(AppSyncClient.java:257)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.syncengine.-$$Lambda$scUANamNqt4NIIofrmWYQsBqVJM.subscribe(Unknown Source:7)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.syncengine.SubscriptionProcessor.lambda$subscriptionObservable$6$SubscriptionProcessor(SubscriptionProcessor.java:187)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.syncengine.-$$Lambda$SubscriptionProcessor$w6tohapLGUGmW4mOmsvNOno7GVE.subscribe(Unknown Source:11)
E/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)
E/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.core.Observable.subscribe(Observable.java:13099)
E/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
E/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.core.Observable.subscribe(Observable.java:13099)
E/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
E/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.core.Scheduler$DisposeTask.run(Scheduler.java:614)
E/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65)
E/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56)
E/amplify:aws-datastore( 4037): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/amplify:aws-datastore( 4037): 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
E/amplify:aws-datastore( 4037): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/amplify:aws-datastore( 4037): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/amplify:aws-datastore( 4037): 	at java.lang.Thread.run(Thread.java:764)
E/amplify:aws-datastore( 4037): Caused by: ApiException{message=There is more than one API configured for this plugin with matching endpoint type., cause=null, recoverySuggestion=Please specify the name of API to invoke in the API method.}
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.aws.AWSApiPlugin.selectApiName(AWSApiPlugin.java:579)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.aws.AWSApiPlugin.getSelectedApiName(AWSApiPlugin.java:564)
E/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.aws.AWSApiPlugin.subscribe(AWSApiPlugin.java:283)
E/amplify:aws-datastore( 4037): 	... 19 more
W/amplify:aws-datastore( 4037): API sync failed - transitioning to LOCAL_ONLY.
W/amplify:aws-datastore( 4037): DataStoreException{message=Error during subscription., cause=ApiException{message=There is more than one API configured for this plugin with matching endpoint type., cause=null, recoverySuggestion=Please specify the name of API to invoke in the API method.}, recoverySuggestion=Evaluate details.}
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$subscription$3(AppSyncClient.java:331)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.appsync.-$$Lambda$AppSyncClient$797ziDK0io-qXODzROLOA77stS8.accept(Unknown Source:4)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.aws.AWSApiPlugin.subscribe(AWSApiPlugin.java:285)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.ApiCategory.subscribe(ApiCategory.java:91)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.appsync.AppSyncClient.subscription(AppSyncClient.java:335)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.appsync.AppSyncClient.onCreate(AppSyncClient.java:257)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.syncengine.-$$Lambda$scUANamNqt4NIIofrmWYQsBqVJM.subscribe(Unknown Source:7)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.syncengine.SubscriptionProcessor.lambda$subscriptionObservable$6$SubscriptionProcessor(SubscriptionProcessor.java:187)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.datastore.syncengine.-$$Lambda$SubscriptionProcessor$w6tohapLGUGmW4mOmsvNOno7GVE.subscribe(Unknown Source:11)
W/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)
W/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.core.Observable.subscribe(Observable.java:13099)
W/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
W/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.core.Observable.subscribe(Observable.java:13099)
W/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
W/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.core.Scheduler$DisposeTask.run(Scheduler.java:614)
W/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65)
W/amplify:aws-datastore( 4037): 	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56)
W/amplify:aws-datastore( 4037): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/amplify:aws-datastore( 4037): 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
W/amplify:aws-datastore( 4037): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
W/amplify:aws-datastore( 4037): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/amplify:aws-datastore( 4037): 	at java.lang.Thread.run(Thread.java:764)
W/amplify:aws-datastore( 4037): Caused by: ApiException{message=There is more than one API configured for this plugin with matching endpoint type., cause=null, recoverySuggestion=Please specify the name of API to invoke in the API method.}
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.aws.AWSApiPlugin.selectApiName(AWSApiPlugin.java:579)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.aws.AWSApiPlugin.getSelectedApiName(AWSApiPlugin.java:564)
W/amplify:aws-datastore( 4037): 	at com.amplifyframework.api.aws.AWSApiPlugin.subscribe(AWSApiPlugin.java:283)
W/amplify:aws-datastore( 4037): 	... 19 more
I/amplify:aws-datastore( 4037): Orchestrator transitioning from SYNC_VIA_API to LOCAL_ONLY
I/amplify:aws-datastore( 4037): Setting currentState to LOCAL_ONLY
I/amplify:aws-datastore( 4037): Stopping subscription processor.
I/amplify:aws-datastore( 4037): Stopped subscription processor.

Categories

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

Steps to Reproduce

  1. Create a GraphQL API with a simple model
  2. Modify amplifyconfiguration.dart so that under API you have one GraphQL API configuration block for with authorizationType: AMAZON_COGNITO_USER_POOLS and in a second block under the same api section add a seond GraphQL API configuration block with authorizationType: AWS_IAM (see how it's done in the tracktunes and tracktunesCognito sections in amplifyconfiguration.dart below).
  3. Add a call to Amplify.Datastore.observeQuery(<YOUR MODEL>) at the start of your program and you'll see it crashing (check log lines in VSCode of the Android emulator, giving out the Android/Java-level exception details)

Screenshots

No response

Platforms

  • iOS
  • Android

Android Device/Emulator API Level

API 29

Environment

> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.4, on Debian GNU/Linux 11 (bullseye) 5.10.0-16-amd64, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.69.0)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

Dependencies

> flutter pub deps --no-dev --style=compact
Dart SDK 2.17.5
Flutter SDK 3.0.4
tracktunes_app_aws 0.0.1-alpha.4

dependencies:
- amplify_api 0.6.1 [amplify_api_android amplify_api_ios amplify_core amplify_flutter aws_common collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.6.1 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_datastore 0.6.1 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_flutter 0.6.1 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- amplify_storage_s3 0.6.1 [amplify_storage_s3_android amplify_storage_s3_ios amplify_core aws_common flutter meta plugin_platform_interface]
- cupertino_icons 1.0.5
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_hooks 0.18.5+1 [flutter]
- google_fonts 3.0.1 [flutter http path_provider crypto]
- hooks_riverpod 1.0.4 [collection flutter flutter_hooks flutter_riverpod riverpod state_notifier]
- image 3.2.0 [archive meta xml]
- image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- rflutter_alert 2.0.4 [flutter]

transitive dependencies:
- amplify_api_android 0.6.1 [flutter]
- amplify_api_ios 0.6.1 [amplify_core flutter]
- amplify_auth_cognito_android 0.6.1 [flutter]
- amplify_auth_cognito_ios 0.6.1 [amplify_core flutter]
- amplify_core 0.6.1 [aws_common collection flutter intl json_annotation meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.6.1 [amplify_core collection flutter meta]
- amplify_flutter_android 0.6.1 [flutter]
- amplify_flutter_ios 0.6.1 [amplify_core flutter]
- amplify_storage_s3_android 0.6.1 [flutter]
- amplify_storage_s3_ios 0.6.1 [flutter]
- archive 3.3.0 [crypto path]
- async 2.8.2 [collection meta]
- aws_common 0.1.1 [async collection http meta stream_transform uuid]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.16.0
- cross_file 0.3.3+1 [js meta]
- crypto 3.0.2 [typed_data]
- ffi 2.0.1
- file 6.1.2 [meta path]
- flutter_plugin_android_lifecycle 2.0.6 [flutter]
- flutter_riverpod 1.0.4 [collection flutter meta riverpod state_notifier]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- http 0.13.4 [async http_parser meta path]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- image_picker_android 0.8.5+1 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 2.1.8 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_ios 0.8.5+5 [flutter image_picker_platform_interface]
- image_picker_platform_interface 2.5.0 [cross_file flutter http plugin_platform_interface]
- intl 0.17.0 [clock path]
- js 0.6.4
- json_annotation 4.5.0 [meta]
- material_color_utilities 0.1.4
- meta 1.7.0
- path 1.8.1
- path_provider_android 2.0.16 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.10 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.0 [ffi flutter path path_provider_platform_interface win32]
- petitparser 5.0.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- process 4.2.4 [file path platform]
- riverpod 1.0.3 [collection meta state_notifier]
- sky_engine 0.0.99
- source_span 1.8.2 [collection path term_glyph]
- state_notifier 0.7.2+1 [meta]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- typed_data 1.3.1 [collection]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2
- win32 2.7.0 [ffi]
- xdg_directories 0.2.0+1 [meta path process]
- xml 6.1.0 [collection meta petitparser]

Device

Samsung Galaxy S7 -- emulated

OS

Android 8

CLI Version

9.1.0

Additional Context

Here's the amplifyconfiguration.dart file:

const amplifyconfig = ''' {
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "api": {
        "plugins": {
            "awsAPIPlugin": {
                "tracktunes": {
                    "endpointType": "GraphQL",
                    "endpoint": "https://xxxxxxxxxxxxxxxxxx",
                    "region": "us-east-1",
                    "authorizationType": "AWS_IAM"
                },
                "tracktunesCognito": {
                    "endpointType": "GraphQL",
                    "endpoint": "https://xxxxxxxxxxxxxxxxxx",
                    "region": "us-east-1",
                    "authorizationType": "AMAZON_COGNITO_USER_POOLS"
                },
                "lambdaFunctions": {
                    "endpointType": "REST",
                    "endpoint": "https://xxxxxxxxxxxxxxxxxx",
                    "region": "us-east-1",
                    "authorizationType": "AWS_IAM"
                },
                "lambdaFunctionsCognito": {
                    "endpointType": "REST",
                    "endpoint": "https://xxxxxxxxxxxxxxxxxx",
                    "region": "us-east-1",
                    "authorizationType": "AMAZON_COGNITO_USER_POOLS"
                }
            }
        }
    },
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "xxxxxxxxxxxxxxxxxx",
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "xxxxxxxxxxxxxxxxxx",
                        "AppClientId": "xxxxxxxxxxxxxxxxxx",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH",
                        "socialProviders": [],
                        "usernameAttributes": [
                            "EMAIL"
                        ],
                        "signupAttributes": [
                            "EMAIL"
                        ],
                        "passwordProtectionSettings": {
                            "passwordPolicyMinLength": 8,
                            "passwordPolicyCharacters": []
                        },
                        "mfaConfiguration": "OFF",
                        "mfaTypes": [
                            "SMS"
                        ],
                        "verificationMechanisms": [
                            "EMAIL"
                        ]
                    }
                },
                "AppSync": {
                    "Default": {
                        "ApiUrl": "xxxxxxxxxxxxxxxxxx",
                        "Region": "us-east-1",
                        "AuthMode": "AWS_IAM",
                        "ClientDatabasePrefix": "tracktunes_AWS_IAM"
                    },
                    "tracktunes_AMAZON_COGNITO_USER_POOLS": {
                        "ApiUrl": "xxxxxxxxxxxxxxxxxx",
                        "Region": "us-east-1",
                        "AuthMode": "AMAZON_COGNITO_USER_POOLS",
                        "ClientDatabasePrefix": "tracktunes_AMAZON_COGNITO_USER_POOLS"
                    }
                },
                "S3TransferUtility": {
                    "Default": {
                        "Bucket": "userdata94336-dev",
                        "Region": "us-east-1"
                    }
                }
            }
        }
    },
    "storage": {
        "plugins": {
            "awsS3StoragePlugin": {
                "bucket": "userdata94336-dev",
                "region": "us-east-1",
                "defaultAccessLevel": "guest"
            }
        }
    }
}''';

Metadata

Metadata

Assignees

Labels

datastoreIssues related to the DataStore Categoryfeature-requestA request for a new feature or an enhancement to an existing API or category.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions