remit2any_auth 0.0.8 copy "remit2any_auth: ^0.0.8" to clipboard
remit2any_auth: ^0.0.8 copied to clipboard

A Flutter package for Remit2Any authentication.

Remit2Any Auth Flutter SDK #

A Flutter package for seamless AWS Cognito authentication via WebView for Remit2Any.

Features #

  • WebView-based sign-in with Remit2Any
  • Secure token storage using flutter_secure_storage
  • Fetch user profile from Cognito
  • Background token refresh
  • Automatic camera and microphone permission requests for US KYC
  • Consistent authentication state handling across WebView interactions

Installation #

Add to your pubspec.yaml:

dependencies:
  remit2any_auth:
    path: ../remit2any_auth # or use your published version

Required Permissions #

For camera and microphone access in WebViews (especially for US KYC), ensure your app has the following permissions:

Android - Add to android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

iOS - Add to ios/Runner/Info.plist:

<key>NSCameraUsageDescription</key>
<string>This app needs camera access to capture documents for identity verification and KYC compliance.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs microphone access for identity verification processes and KYC compliance.</string>

Configuration #

Set your Cognito client IDs in config/environment_config.dart:

  • Replace your_dev_cognito_client_id with your development Cognito client ID
  • Replace your_prod_cognito_client_id with your production Cognito client ID

Usage #

Basic Setup #

import 'package:remit2any_auth/remit2any_auth.dart';

// Set environment (optional, defaults to dev)
Remit2AnyEnvironmentConfig.setEnvironment(Environment.prod); // or Environment.dev

// Create auth instance
final auth = Remit2AnyAuth();

Authentication #

// Sign in with WebView (returns tokens map)
final tokens = await auth.signIn(context, email: 'user@example.com'); // email is optional
if (tokens != null) {
  // Tokens contain: accessToken, refreshToken, idToken, email, userId
  print('Access Token: ${tokens['accessToken']}');
  print('User Email: ${tokens['email']}');
}

// Get current user information
final UserInfo? user = await auth.getUser();
if (user != null) {
  print('Username: ${user.username}');
  print('Email: ${user.email}');
  print('User ID: ${user.sub}');
  print('Picture: ${user.picture}');
}

// Get stored user data
final String? email = await auth.getStoredEmail();
final String? userId = await auth.getStoredUserId();

// Sign out (clears local tokens and Cognito session)
await auth.signOut(context);

Token Management #

// Manual token refresh
await auth.refreshTokens();

// Start automatic token refresh (refreshes every 30 minutes)
auth.startTokenRefreshLoop();

WebView Pages #

// Open US KYC documents page (with camera/microphone permissions for "uskyc" URLs)
final result = await auth.openUsKyc(context);
// Returns: null (normal completion) or {'loggedOut': true} (if not authenticated or user logs out)

// Open transfer page with optional USD amount
final result = await auth.openTransfer(context, usdAmount: 250.0); // defaults to 100.0
// Returns: null (normal completion) or {'loggedOut': true} (if not authenticated or user logs out)

// Open wallet page
final result = await auth.openWalletDeposit(context);
// Returns: null (normal completion) or {'loggedOut': true} (if not authenticated or user logs out)

// Open transactions page
final result = await auth.openTransactions(context);
// Returns: null (normal completion) or {'loggedOut': true} (if not authenticated or user logs out)

// Handle authentication state from WebView results
if (result != null && result['loggedOut'] == true) {
  // User is not authenticated or logged out from webview
  // Redirect to login screen or handle accordingly
  print('User needs to authenticate');
}

// Check if US KYC is completed
final bool isKycCompleted = await auth.isUsKycCompleted();

Environment Configuration #

// Set development environment
Remit2AnyEnvironmentConfig.setEnvironment(Environment.dev);

// Set production environment  
Remit2AnyEnvironmentConfig.setEnvironment(Environment.prod);

// Check current environment
if (Remit2AnyEnvironmentConfig.isDev) {
  print('Running in development mode');
}

// Get current URLs
print('Auth URL: ${Remit2AnyEnvironmentConfig.authUrl}');
print('Base URL: ${Remit2AnyEnvironmentConfig.baseUrl}');

Example #

See the example/ app for a working demo.

Security #

  • Tokens are stored securely using flutter_secure_storage.
  • Only trusted domains are used for WebView.

Flutter Package Publishing #

Prerequisites #

  1. Dart/Flutter SDK: Ensure you have the latest stable version installed
  2. pub.dev Account: Create an account at pub.dev
  3. Google Account: Link your Google account to pub.dev
  4. Package Name: Ensure your package name is unique on pub.dev

Version Management #

Semantic Versioning

Follow semantic versioning (MAJOR.MINOR.PATCH):

  • MAJOR: Breaking changes
  • MINOR: New features (backward compatible)
  • PATCH: Bug fixes (backward compatible)

Update Version in pubspec.yaml

name: remit2any_auth
description: A Flutter package for Remit2Any authentication
version: 1.0.0  # Update this before publishing

Pre-Publishing Checklist #

  1. Update Documentation

    • Ensure README.md is complete and accurate
    • Update CHANGELOG.md with new changes
    • Verify all code examples work
  2. Code Quality

    # Run static analysis
    dart analyze
       
    # Run tests
    flutter test
       
    # Check for issues
    flutter doctor
    
  3. Package Validation

    # Validate package structure
    dart pub publish --dry-run
    
  4. Test the Package

    # Test in a local project
    cd example
    flutter pub get
    flutter run
    

Publishing Steps #

1. Prepare for Publishing

# Navigate to package directory
cd remit2any_auth

# Update version in pubspec.yaml
# Edit pubspec.yaml and increment version number

# Update CHANGELOG.md
# Add entry for new version

2. Validate Package

# Run dry-run to check for issues
dart pub publish --dry-run

# Fix any issues reported

3. Publish to pub.dev

# Publish the package
dart pub publish

# Follow the prompts to authenticate

4. Verify Publication

  • Check pub.dev for your package
  • Verify all files are uploaded correctly
  • Test installation in a new project

Post-Publishing #

1. Update Dependencies

After publishing, update the example app to use the published version:

# In example/pubspec.yaml
dependencies:
  remit2any_auth: ^1.0.0  # Use published version

2. Tag Release

# Create git tag
git tag v1.0.0
git push origin v1.0.0

3. Update Documentation

  • Update any references to use the published version
  • Update installation instructions in README

Publishing Checklist #

  • ❌ Update version in pubspec.yaml
  • ❌ Update CHANGELOG.md
  • ❌ Run dart analyze (no issues)
  • ❌ Run flutter test (all tests pass)
  • ❌ Run dart pub publish --dry-run (no issues)
  • ❌ Test package in example app
  • ❌ Publish with dart pub publish
  • ❌ Verify package on pub.dev
  • ❌ Create git tag
  • ❌ Update documentation

Troubleshooting #

Common Issues

  1. Package Name Already Taken

    • Choose a unique package name
    • Check availability on pub.dev
  2. Authentication Issues

    • Ensure you're logged into pub.dev
    • Verify Google account is linked
  3. Validation Errors

    • Fix all dart analyze issues
    • Ensure all dependencies are compatible
  4. Version Conflicts

    • Check for version conflicts in dependencies
    • Update dependencies if needed

Rollback Procedure

If you need to rollback a published version:

  1. Publish a new version with fixes
  2. Update documentation to reflect changes
  3. Communicate changes to users

Continuous Integration #

Consider setting up CI/CD for automated publishing:

# .github/workflows/publish.yml
name: Publish Package
on:
  push:
    tags:
      - 'v*'
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dart-lang/setup-dart@v1
      - run: dart pub get
      - run: dart analyze
      - run: flutter test
      - run: dart pub publish --force

License #

MIT

0
likes
0
points
309
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for Remit2Any authentication.

License

unknown (license)

Dependencies

flutter, flutter_inappwebview, flutter_secure_storage, http, permission_handler, url_launcher

More

Packages that depend on remit2any_auth