simplici_auth 1.0.4 copy "simplici_auth: ^1.0.4" to clipboard
simplici_auth: ^1.0.4 copied to clipboard

A Flutter package for integrating SimpliciAuth with Google OAuth in Flutter applications. Provides webview-based authentication with customizable configuration and comprehensive OAuth handling.

Simplici Auth Flutter #

A Flutter package for integrating SimpliciAuth with Google OAuth in Flutter applications. This package provides webview-based authentication with customizable configuration and comprehensive OAuth handling.

Features #

  • 🔐 Google OAuth Integration: Complete Google OAuth 2.0 flow with authorization code exchange
  • 🌐 WebView Authentication: Secure webview-based authentication
  • 📱 Cross-Platform: Works on iOS, Android, and Web
  • 🎨 Customizable UI: Fullscreen webview with custom styling
  • 🔄 Token Management: Automatic token exchange and refresh handling
  • 📊 User Data: Complete user profile information retrieval
  • Hook System: Integration with window.handleHooks for custom flows
  • 🛡️ Error Handling: Comprehensive error handling and logging

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  simplici_auth: ^1.0.0

Then run:

flutter pub get

Usage #

Basic Usage #

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:simplici_auth/simplici_auth.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  
  // Hide system UI for fullscreen experience
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
  
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        scaffoldBackgroundColor: Colors.transparent,
      ),
      home: SimpliciAuthWebView(
        config: SimpliciAuthConfig(
          instanceId: "your-instance-id",
          environment: "beta", // or "production"
          isCombinedInput: true,
          autoNavigate: true,
          platform: "ios",
          onAuthSuccess: (data) {
            print("Authentication successful: $data");
          },
          onAuthError: (error) {
            print("Authentication error: $error");
          },
        ),
      ),
    );
  }
}

Advanced Usage with Custom Configuration #

class CustomAuthScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Authentication')),
      body: SimpliciAuthWebView(
        config: SimpliciAuthConfig(
          instanceId: "your-instance-id",
          environment: "production",
          isCombinedInput: false,
          autoNavigate: false,
          platform: "android",
          baseUrl: "https://auth.yourdomain.com",
          userAgent: "Custom UserAgent",
          debugMode: true,
          showLoadingOverlay: true,
          onAuthSuccess: (data) {
            // Handle successful authentication
            print("User authenticated: ${data['email']}");
          },
          onAuthError: (error) {
            // Handle authentication errors
            showDialog(
              context: context,
              builder: (context) => AlertDialog(
                title: Text("Authentication Error"),
                content: Text(error),
                actions: [
                  TextButton(
                    onPressed: () => Navigator.of(context).pop(),
                    child: Text("OK"),
                  ),
                ],
              ),
            );
          },
          onStepChanged: (data) {
            // Handle authentication step changes
            print("Auth step changed: $data");
          },
          onAuthComplete: (data) {
            // Handle authentication completion
            Navigator.of(context).pushReplacement(
              MaterialPageRoute(builder: (context) => HomePage()),
            );
          },
        ),
      ),
    );
  }
}

Configuration Options #

The SimpliciAuthConfig class provides comprehensive configuration options:

Required Parameters #

  • instanceId - Your SimpliciAuth instance ID

Optional Parameters #

  • environment - Environment ("beta" or "production", default: "beta")
  • isCombinedInput - Use combined input UI (default: true)
  • autoNavigate - Enable auto navigation (default: true)
  • platform - Target platform ("ios", "android", "web", default: "ios")
  • baseUrl - Custom base URL (default: "https://auth.beta.satschel.com")
  • userAgent - Custom user agent string
  • debugMode - Enable debug logging (default: false)
  • showLoadingOverlay - Show loading overlay (default: false)

Callback Functions #

  • onAuthSuccess - Called when authentication succeeds
  • onAuthError - Called when authentication fails
  • onStepChanged - Called when authentication step changes
  • onAuthComplete - Called when authentication flow completes

Configuration #

The package automatically handles:

  • Google OAuth Configuration: Receives instance details from the webcomponent
  • Token Exchange: Exchanges authorization codes for access tokens
  • User Information: Retrieves user profile data from Google
  • Hook Integration: Calls window.handleHooks with authentication data

Data Flow #

  1. Instance Details: Webcomponent sends Google OAuth configuration
  2. Authorization: User authenticates via Google OAuth
  3. Code Exchange: Authorization code is exchanged for access token
  4. Hook Call: window.handleHooks is called with authentication data
  5. User Data: Complete user information is retrieved and set as sso_user_data

Response Format #

The package sets sso_user_data with the following structure:

{
  "provider": "google",
  "access_token": "ya29.a0...",
  "code": "4/0AfJohX...",
  "redirect_url": "com.googleusercontent.apps...",
  "instanceId": "686792efe1934dbaa5b8c988",
  "type": "embeded",
  "responseType": "json",
  "refresh_token": "1//04...",
  "expires_in": 3599,
  "email": "user@example.com",
  "userId": "686d0c009e6a67af37701b79",
  "firstName": "John",
  "lastName": "Doe",
  "hook_result": {
    "statusCode": 200,
    "message": "ok",
    "data": { ... }
  }
}

Requirements #

  • Flutter SDK: >=1.17.0
  • Dart SDK: ^3.8.1

Dependencies #

  • webview_flutter: ^4.2.2
  • flutter_inappwebview: ^6.0.0
  • http: ^1.1.0

Platform Support #

Platform Support
Android
iOS
Web
macOS
Linux
Windows

Example #

Check out the example directory for a complete implementation.

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Support #

If you have any questions or need help, please open an issue on GitHub.

1
likes
0
points
425
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for integrating SimpliciAuth with Google OAuth in Flutter applications. Provides webview-based authentication with customizable configuration and comprehensive OAuth handling.

Repository (GitHub)
View/report issues

Topics

#authentication #oauth #google #webview #simplici

License

unknown (license)

Dependencies

flutter, flutter_inappwebview, http, webview_flutter

More

Packages that depend on simplici_auth