web3auth_flutter 6.1.0 web3auth_flutter: ^6.1.0 copied to clipboard
Flutter SDK for Torus Web3Auth (Web3Auth)
Web3Auth Flutter SDK #
Web3Auth is where passwordless auth meets non-custodial key infrastructure for Web3 apps and wallets. By aggregating OAuth (Google, Twitter, Discord) logins, different wallets and innovative Multi Party Computation (MPC) - Web3Auth provides a seamless login experience to every user on your application.
📖 Documentation #
Checkout the official Web3Auth Documentation and SDK Reference to get started!
💡 Features #
- Plug and Play, OAuth based Web3 Authentication Service
- Fully decentralized, non-custodial key infrastructure
- End to end Whitelabelable solution
- Threshold Cryptography based Key Reconstruction
- Multi Factor Authentication Setup & Recovery (Includes password, backup phrase, device factor editing/deletion etc)
- Support for WebAuthn & Passwordless Login
- Support for connecting to multiple wallets
- DApp Active Session Management
...and a lot more
⏪ Requirements #
- For iOS, only iOS 14+ supported since we requires ASWebAuthenticationSession.
- Xcode 11.4+ / 12.x
- Swift 4.x / 5.x
- For iOS build:
platform :ios
needs to be14.0
. Checkios/Podfile
in your Flutter project to change it.
- For Android, API version 26 or newer is supported.
- For Android build: compileSdkVersion needs to be 34.
- Check
android/app/build.gradle
in your Flutter project to change it.
⚡ Installation #
Add web3auth_flutter
as a dependency to your pubspec.yaml
file.
dependencies:
web3auth_flutter: ^6.1.0
or
flutter pub add web3auth_flutter
🌟 Configuration #
Checkout SDK Reference to configure for Android and iOS builds.
🩹 Example #
Checkout the examples for your preferred blockchain and platform in our examples
// Initialization
await Web3AuthFlutter.init(
Web3AuthOptions(
// Get your client it from dashboard.web3auth.io
clientId: 'YOUR_WEB3AUTH_CLIENT_ID',
network: Network.sapphire_devnet,
// Your redirect url, check how to configure.
// Android: https://web3auth.io/docs/sdk/pnp/flutter/install#android-configuration
// iOS: https://web3auth.io/docs/sdk/pnp/flutter/install#ios-configuration
redirectUrl: redirectUrl,
),
);
// Call initialize() function to get privKey and user information without relogging in
// user if a user has an active session. If no active session is present, the
// function throws an error.
await Web3AuthFlutter.initialize();
// Login
await Web3AuthFlutter.login(LoginParams(loginProvider: Provider.google));
// Logout
await Web3AuthFlutter.logout();
Triggering UserCancellation on Android #
On Android, if you want to trigger exception for user closing the browser tab, you have to use
WidgetsBindingObserver
mixin with your your login screen.
class LoginScreen extends State<MyApp> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
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 user cancellation on Android.
if (state == AppLifecycleState.resumed) {
Web3AuthFlutter.setCustomTabsClosed();
}
}
@override
Widget build(BuildContext context) {
// Your UI code
}
Future<void> _login() async {
try {
await Web3AuthFlutter.login(LoginParams(loginProvider: Provider.google));
} on UserCancelledException {
log("User cancelled.");
} on UnKnownException {
log("Unknown exception occurred");
} catch (e) {
log(e.toString());
}
}
}
🌐 Demo #
Checkout the Web3Auth Demo to see how Web3Auth can be used in an application.
Have a look at our Web3Auth PnP Flutter Quick Start to help you quickly integrate a basic instance of Web3Auth Plug and Play in your Flutter app.
Further checkout the example folder within this repository, which contains a sample app.
💬 Troubleshooting and Support #
- Have a look at our Community Portal to see if anyone has any questions or issues you might be having. Feel free to create new topics and we'll help you out as soon as possible.
- Checkout our Troubleshooting Documentation Page to know the common issues and solutions.
- For Priority Support, please have a look at our Pricing Page for the plan that suits your needs.