When launching SSO login with Android and returning back UrlLauncherException gets thrown by Amplify Auth instead of UserCancelledException.
Below is minimal sample Flutter code to reproduce the issue.
<queries>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="text/plain" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
</queries>
import 'dart:convert';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _initialized = false;
@override
void initState() {
super.initState();
_init();
}
void _init() async {
final amplifyConfig = {
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"IdentityManager": {"Default": {}},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {"PoolId": 'PoolId', "Region": 'Region'},
},
},
"CognitoUserPool": {
"Default": {
"PoolId": 'PoolId',
"AppClientId": 'AppClientId',
"Region": 'Region',
},
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"OAuth": {
"WebDomain": ' WebDomain',
"AppClientId": 'AppClientId',
"SignInRedirectURI": 'SignInRedirectURI',
"SignOutRedirectURI": 'SignOutRedirectURI',
"ResponseType": "code",
"Scopes": [
"openid",
"email",
"profile",
"aws.cognito.signin.user.admin",
],
},
},
},
},
},
},
};
final authPlugin = AmplifyAuthCognito();
await Amplify.addPlugin(authPlugin);
try {
await Amplify.configure(jsonEncode(amplifyConfig));
setState(() {
_initialized = true;
});
} catch (e) {
// no-op
}
}
void _signInSSO() async {
try {
final result = await Amplify.Auth.signInWithWebUI(
provider: AuthProvider.google,
);
if (result.isSignedIn) {
// Handle successful sign-in
}
} on UserCancelledException {
if (mounted) {
const snackBar = SnackBar(content: Text('User cancelled'));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
} catch (e) {
if (mounted) {
final snackBar = SnackBar(content: Text('Error occurred $e'));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (!_initialized)
ElevatedButton(onPressed: _init, child: Text("Init"))
else
ElevatedButton(
onPressed: _signInSSO,
child: const Text('Sign in with Google'),
),
],
),
),
);
}
}
Description
When launching SSO login with Android and returning back UrlLauncherException gets thrown by Amplify Auth instead of UserCancelledException.
This happens only when running on release mode with
--releaseflag.Issue does not reproduce when running with debug or profile mode.
Categories
Steps to Reproduce
Below is minimal sample Flutter code to reproduce the issue.
AndroidManifest.xml
main.dart
Screenshots
No response
Platforms
Flutter Version
3.35.3
Amplify Flutter Version
2.6.5
Deployment Method
Custom Pipeline
Schema