Skip to content

About

No description, website, or topics provided.

Resources

Stars

38 stars

Watchers

4 watching

Forks

Repository files navigation

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 be 14.0. Check ios/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: ^8.0.0

or

flutter pub add web3auth_flutter

Native SDK requirements (Auth v11)

Platform Native dependency
Android com.github.Web3Auth:web3auth-android-sdk:11.0.0 (JitPack)
iOS Web3Auth 13.0.0+ via Swift Package Manager — citadel AuthSessionManager

🌟 Configuration

Checkout SDK Reference to configure for Android and iOS builds.

🔁 Migration: v7 → v8 (Auth v10 → v11)

Flutter remains a thin MethodChannel wrapper — citadel session tokens, /start audit fields, MFA refresh, and Wallet Services v6 rehydration live in the native SDKs. Wallet v6 uses citadel sessionId + accessToken in the WebView hash (not a session-service key mirror).

Area v7 v8
Auth / dashboard URLs /v10 /v11
Wallet Services URL /v5 /v6
Android native 10.0.1 11.0.0
iOS native 12.0.1 (CocoaPods) 13.0.0 via SPM (citadel)
MFALevel.DEFAULT present removed
Login audit — loginSource defaults to web3auth-flutter; optional recordId
Session APIs — getAccessToken, getIdentityToken, refreshSession, getUserInfoAsync
Whitelabel — tncLink, privacyPolicy
Options — citadelServerUrl, nullable sessionTime, wsEmbedDappClientId

TESTING / DEVELOPMENT build envs still use unversioned develop hosts.

🩹 Example

Checkout the examples for your preferred blockchain and platform in our examples

// Initialization
await Web3AuthFlutter.init(
  Web3AuthOptions(
    // Get your client id from dashboard.web3auth.io
    clientId: 'YOUR_WEB3AUTH_CLIENT_ID',
    web3AuthNetwork: Web3AuthNetwork.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,
    isFlutterAnalytics: true,
  ),
);

// Restore citadel session without re-login. Throws if no active session.
await Web3AuthFlutter.initialize();

// Login (loginSource defaults to web3auth-flutter on /start)
await Web3AuthFlutter.connectTo(
  LoginParams(authConnection: AuthConnection.google),
);

// Citadel tokens (native AuthSessionManager)
final accessToken = await Web3AuthFlutter.getAccessToken();
await Web3AuthFlutter.refreshSession();

// 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.

About

No description, website, or topics provided.

Resources

Stars

38 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages