Optare ID Flutter SDK

Official Flutter SDK for Optare ID - a modern identity and access management platform.

Features

  • ✅ OAuth 2.0 with PKCE (Proof Key for Code Exchange)
  • ✅ Secure token storage (Keychain/Keystore)
  • ✅ Automatic token refresh
  • ✅ Deep link handling
  • ✅ User profile management
  • ✅ License & entitlement verification
  • ✅ Cross-platform (iOS & Android)

Installation

Add to your pubspec.yaml:

dependencies:
  optareid_flutter: ^0.1.3

Platform Setup

iOS

Add the following to your ios/Runner/Info.plist:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>myapp</string>  <!-- Your URL scheme -->
    </array>
  </dict>
</array>

Android

Add the following to your android/app/src/main/AndroidManifest.xml:

<intent-filter>
  <action android:name="android.intent.action.VIEW"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <data android:scheme="myapp" android:host="callback"/>
</intent-filter>

Quick Start

1. Initialize the SDK

import 'package:optareid_flutter/optareid_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  await OptareAuth.init(
    clientId: 'your-client-id',
    redirectUri: 'myapp://callback',
  );
  
  runApp(const MyApp());
}

2. Add Login Button

ElevatedButton(
  onPressed: () async {
    await OptareAuth.login();
  },
  child: const Text('Sign in with Optare'),
)

3. Check Authentication Status

if (OptareAuth.isAuthenticated) {
  final user = OptareAuth.currentUser;
  print('Logged in as ${user?.name}');
}

4. Access User Data

final user = await OptareAuth.getUser();
print('User ID: ${user?.id}');
print('Email: ${user?.email}');
print('Organization: ${user?.organizationId}');
print('Licenses: ${user?.licenses}');

5. Check Licenses & Entitlements

if (OptareAuth.hasLicense('premium-plan')) {
  // User has premium access
}

if (OptareAuth.hasEntitlement('ai-features')) {
  // User can access AI features
}

6. Logout

await OptareAuth.logout();

API Reference

OptareAuth

Method Description
init() Initialize the SDK with your client configuration
login() Start the OAuth login flow
logout() Logout and clear the session
getUser() Get the current user profile
updateProfile() Update user's name, avatar, metadata
getOrganizations() List all organizations user belongs to
getLicenses() Get licenses with server-side validation
refreshTokens() Manually refresh the access token
hasLicense(slug) Check if user has a product license
hasEntitlement(name) Check if user has an entitlement

OptareUser

Property Type Description
id String Unique user identifier
email String? User's email address
name String? User's display name
picture String? Profile picture URL
organizationId String? Organization ID
licenses List<String> Product licenses
entitlements List<String> Feature entitlements

Configuration Options

await OptareAuth.init(
  clientId: 'your-client-id',        // Required: OAuth client ID
  redirectUri: 'myapp://callback',   // Required: Deep link URI
  issuer: 'https://id.optare.one',   // Optional: Optare ID server URL
  scopes: ['openid', 'email', 'profile'], // Optional: OAuth scopes
  storage: SecureTokenStorage(),     // Optional: Custom token storage
);

Error Handling

try {
  await OptareAuth.login();
} on OptareAuthException catch (e) {
  print('Auth error: ${e.message}');
} on OptareNetworkException catch (e) {
  print('Network error: ${e.message}');
} on OptareException catch (e) {
  print('General error: ${e.message}');
}

Support

License

MIT License - see LICENSE for details.

Libraries

optareid_flutter
Optare ID Flutter SDK