When asking for help in this category, please make sure to provide the following details:
-
SDK Version: 6.2.0
-
Platform: Android
-
Browser Console Screenshots:
-
If the issue is related to Custom Authentication, please include the following information (optional):
- Verifier Name: w3a-aggregate-verifier
- JWKS Endpoint:
- Sample idToken (JWT): NA
import 'dart:collection';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:web3auth_flutter/enums.dart';
import 'package:web3auth_flutter/input.dart';
import 'package:web3auth_flutter/web3auth_flutter.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> with WidgetsBindingObserver {
int _counter = 0;
@override
void initState() {
super.initState();
initPlatformState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
@override
void didChangeAppLifecycleState(final AppLifecycleState state) {
// This is important to trigger the on Android.
if (state == AppLifecycleState.resumed) {
Web3AuthFlutter.setCustomTabsClosed();
}
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
final themeMap = HashMap<String, String>();
themeMap['primary'] = "#eb5424";
Uri redirectUrl;
if (Platform.isAndroid) {
redirectUrl = Uri.parse('w3a://com.whitelabel.ncw');
} else if (Platform.isIOS) {
redirectUrl = Uri.parse('com.whitelabel.ncw://openlogin');
} else {
throw UnKnownException('Unknown platform');
}
final loginConfig = HashMap<String, LoginConfigItem>();
loginConfig['jwt'] = LoginConfigItem(
verifier: 'w3a-aggregate-verifier',
verifierSubIdentifier: "w3a-auth0-verifier",
typeOfLogin: TypeOfLogin.jwt,
clientId: "ULYgWJWUwabs7n8WMLvzE9s34YW4PxGf",
);
loginConfig['email_passwordless'] = LoginConfigItem(
verifier: 'w3a-aggregate-verifier',
verifierSubIdentifier: "w3a-email-verifier",
typeOfLogin: TypeOfLogin.email_passwordless,
clientId:
"BL-eRKwPFAahBn9p_EN3hXjAeF36zc94iHPtgU3k_c9QKBJlDtiE7G8gB5GThBzOlaO-X7PtUWhL1TIBO5OY6Ds",
);
await Web3AuthFlutter.init(
Web3AuthOptions(
clientId:
'BL-eRKwPFAahBn9p_EN3hXjAeF36zc94iHPtgU3k_c9QKBJlDtiE7G8gB5GThBzOlaO-X7PtUWhL1TIBO5OY6Ds',
network: Network.sapphire_devnet,
redirectUrl: redirectUrl,
whiteLabel: WhiteLabelData(
appName: "White Label NCW",
logoLight:
"https://www.vectorlogo.zone/logos/flutterio/flutterio-icon.svg",
logoDark:
"https://cdn.icon-icons.com/icons2/2389/PNG/512/flutter_logo_icon_145273.png",
defaultLanguage: Language.en,
mode: ThemeModes.auto,
appUrl: "https://web3auth.io",
useLogoLoader: true,
theme: themeMap,
),
loginConfig: loginConfig,
// 259200 allows user to stay authenticated for 3 days with Web3Auth.
// Default is 86400, which is 1 day.
sessionTime: 86400 * 30,
),
);
try {
await Web3AuthFlutter.initialize();
} catch (e) {
print(e.toString());
}
}
void _withAuth0(String connection, {String? email}) {
final loginParam = email != null || connection == 'email'
? LoginParams(
loginProvider: Provider.email_passwordless,
mfaLevel: MFALevel.NONE,
extraLoginOptions: ExtraLoginOptions(
login_hint: email,
display: Display.popup,
),
)
: LoginParams(
loginProvider: Provider.jwt,
mfaLevel: MFALevel.NONE,
extraLoginOptions: ExtraLoginOptions(
domain: 'https://dev-nhcp41mypd0msufj.us.auth0.com',
verifierIdField: 'email',
connection: connection,
isVerifierIdCaseSensitive: false,
),
);
print('here');
Web3AuthFlutter.login(loginParam)
.then((response) {
Clipboard.setData(
ClipboardData(text: response.userInfo?.idToken ?? ''),
);
print(response.privKey);
})
.catchError((e) {
print('error: $e');
});
}
void _incrementCounter() {
setState(() {
_counter++;
});
}
@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>[
const Text('You have pushed the button this many times:'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _withAuth0('google-oauth2'),
// onPressed: () => _withAuth0('facebook'),
// onPressed: () => _withAuth0('apple'),
// onPressed: () => _withAuth0('email', email: 'ritikfbd@gmail.com'),
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
when running on android after authentication from auth0 the web3auth loading page shows indefinitely.