PlatformException - Cognito
Bug Description
I'm trying to set up just the AmplifyAuthCognito() plugin, but I'm having difficulty as a PlatformException (most likely a bad amplifyconfiguration.dart was keeping me from getting anywhere. I looked at issues #100 and #153 (#100 was much closer to my situation), and I wasn't able to replicate the fixes from those configurations in mine.
To Reproduce
I used the Amplify CLI and the tutorial and I currently have Auth set up; amplify status outputs
| Category | Resource name | Operation | Provider plugin |
| -------- | ----------------- | --------- | ----------------- |
| Auth | <value> | No Change | awscloudformation |
This is what my config looks like within amplifyconfiguration.dart.
const amplifyconfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "<value>",
"Region": "us-east-2"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "us-east-2_<value>",
"AppClientId": "<value>",
"AppClientSecret": "<value>",
"Region": "us-east-2"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH"
}
}
}
}
}
}''';
I'm then running the following test code:
class _MyHomePageState extends State<MyHomePage> {
bool _amplifyConfigured = false;
Amplify amplifyInstance = Amplify();
@override
initState() {
super.initState();
_configureAmplify();
}
void _configureAmplify() async {
AmplifyAuthCognito authPlugin = AmplifyAuthCognito();
amplifyInstance.addPlugin(
authPlugins: [authPlugin]
);
// Once Plugins are added, configure Amplify
await amplifyInstance.configure(amplifyconfig);
try {
setState(() {
_amplifyConfigured = true;
});
} catch (e) {
print(e);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: LoginPage(),
);
}
}
with my .yaml file including:
dependencies:
flutter:
sdk: flutter
amplify_core: '<1.0.0'
amplify_auth_cognito: '<1.0.0'
amplify_analytics_pinpoint: '<1.0.0'
Expected behavior No error, but unfortunately I'm seeing:
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: PlatformException(AmplifyException, Failed to Configure Amplify, The operation couldn’t be completed. (Amplify.ConfigurationError error 0.), null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
<asynchronous suspension>
#2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
#3 MethodChannelAmplifyCore.configure (package:amplify_core_plugin_interface/method_channel_amplify.dart:25:21)
#4 Amplify.configure (package:amplify_core/amplify_core.dart:71:35)
#5 _MyHomePageState._configureAmplify (package:mobile/main.dart:65:27)
#6 _MyHomePageState.initState (package:mobile/main.dart:55:5)
#7 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4765:58)
#8 ComponentElement.mount (package:flutter/src/widgets/framework.da<…>
Platform Amplify Flutter current supports iOS and Android. This issue is reproducible in (check all that apply): [] Android [x] iOS
Smartphone:
- Device: iPhone SE Emulator
- OS: iOS 14
@arealguru I'm unable to reproduce this issue, but we are continuing to investigate. We have a couple of follow-up questions:
- Is this reproducible on an Android device?
- Which versions of the libraries are you actually using? These should be visible in the pubspec.lock file.
Hi, yesterday got the same exception on Android side. Found some mistakes in the amplifyconfig file but iOS didn't show up this exception, which is weird. Our team created the config file manually. The detailed message indicates the user agent has been set, and Oauth related error. If one has the exception above I suggest look at the official config:
The wrong config file:
const amplifyconfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CognitoUserPool": {
"Default": {
"PoolId": "ap-northeast-1_RqSQCb4zW",
"AppClientId": "548cm6u147musag0f1a1ee8i4j",
"AppClientSecret": "14rjh2knh2tqah8vcuv33n57048oe1qgipf83287tfravfip78s1",
"Region": "ap-northeast-1"
}
},
"Auth": {
"Default": {
"OAuth": {
"WebDomain": "nodesfly-dev.auth.ap-northeast-1.amazoncognito.com",
"AppClientId": "548cm6u147musag0f1a1ee8i4j",
"AppClientSecret": "14rjh2knh2tqah8vcuv33n57048oe1qgipf83287tfravfip78s1",
"Scopes": [
"phone",
"email",
"openid",
"profile",
"aws.cognito.signin.user.admin"
]
},
"authenticationFlowType": "USER_SRP_AUTH"
}
}
}
}
}
}''';
So what I did was:
- remove the UserAgent and Version in the awsCognitoAuthPlugin section
- remove the whole OAuth block
and all exceptions are gone.
dependencies: amplify_core: '<1.0.0' amplify_auth_cognito: '<1.0.0'
Thanks for the suggestion @scdplzop, I have removed the UserAgent and Version in the awsCognitoAuthPlugin, and I never had the OAuth block in.
It is now working! Had to completely clean all my caches and relaunch the emulator, and it was able to work. Thanks everyone.
Works for both android and iOS.
I've had this problem for days except it says plugin error 2 instead of 0. I put endless hours into this and finally fixed it by deleting the auth and analytics folders in pods.
I've had this problem for days except it says plugin error 2 instead of 0. I put endless hours into this and finally fixed it by deleting the auth and analytics folders in pods.
I am getting error 2 ...deleting the folders didn't fix my issue
Hi we are taking a look into this issue and actively working on a fix. Currently if you add one of our plugins to pubspec without adding it via the amplify cli as well the above issue will occur.
@fjnoyp Is it related to the hotreload function?
Hey @SalahAdDin @arealguru @jareddplzop @Josiah-Turnquist
I cannot reproduce this issue anymore
Feel free to test using the latest build and let us know if you got any issues
Regards Mo