firebase_verify_token_dart 2.1.3 copy "firebase_verify_token_dart: ^2.1.3" to clipboard
firebase_verify_token_dart: ^2.1.3 copied to clipboard

Package to verify a firebase jwt token across multiple Firebase projects

Firebase Verify Token #

Firebase Verify Token

A Dart/Flutter plugin to verify Firebase JWT tokens, supporting multiple Firebase projects across any platform.

Pub Version Pub Likes Pub Points GitHub license


📱 Supported Platforms #

Android iOS macOS Web Linux Windows
✔️ ✔️ ✔️ ✔️ ✔️ ✔️

🔍 Overview #

firebase_verify_token_dart verifies Firebase JWT tokens entirely in Dart without relying on backend services. It performs:

  • Project ID validation against a whitelist
  • Issuer check to ensure token is from Firebase
  • Expiration check
  • JWT structure validation

⚙️ Installation #

Add the dependency:

dependencies:
  firebase_verify_token_dart: ^latest
copied to clipboard

Then run:

flutter pub get
copied to clipboard

🚀 Quick Start #

1. Import the package #

import 'package:firebase_verify_token/firebase_verify_token.dart';
copied to clipboard

2. Initialize with your Firebase project IDs #

FirebaseVerifyToken.projectIds = [
  'project-id-1',
  'project-id-2',
];
copied to clipboard

🔐 Token Verification #

✅ Basic Verification #

final isValid = await FirebaseVerifyToken.verify('your-firebase-jwt-token');

if (isValid) {
  // Token is valid
}
copied to clipboard

🧠 With Callback (for project ID and duration) #

await FirebaseVerifyToken.verify(
  'your-firebase-jwt-token',
  onVerifySuccessful: ({required bool status, String? projectId, int? duration}) {
    if (status) {
      print('Valid token for project: $projectId in ${duration}ms');
    } else {
      print('Invalid token (checked in ${duration}ms)');
    }
  },
);
copied to clipboard

📘 API Reference #

Method Description
Future<bool> FirebaseVerifyToken.verify(String token, { void Function({required bool status, String? projectId, int? duration})? onVerifySuccessful }) Verifies the JWT token and optionally provides project ID and verification duration.
String FirebaseVerifyToken.getUserID(String token) Extracts the user ID (sub claim) from a JWT without verifying it.
String? FirebaseVerifyToken.getProjectID(String token) Extracts the Firebase project ID (aud claim) from a JWT without verifying it.

🔄 Complete Example #

import 'package:firebase_verify_token/firebase_verify_token.dart';

void main() async {
  // Set your Firebase project IDs
  FirebaseVerifyToken.projectIds = ['cbes-c64d6', 'test-1'];

  // Sample Firebase JWT token
  const token = 'eyJhbGciOiJSUzI1NiIsImtpZCI6ImE4Z...'; // shortened for clarity

  // Verify the token with callback
  await FirebaseVerifyToken.verify(
    token,
    onVerifySuccessful: ({
      required bool status,
      String? projectId,
      required int duration,
    }) {
      if (status) {
        print('✅ Token verified for project: \$projectId (\$duration ms)');
      } else {
        print('❌ Token verification failed (\$duration ms)');
      }
    },
  );
}
copied to clipboard

💡 Common Use Cases #

  • 🔐 Cross-project auth: Accept users from multiple Firebase projects
  • 🔑 Secure APIs: Verify Firebase tokens server-side or client-side
  • 🌐 Multi-app integration: Authenticate users across a shared ecosystem

🤝 Contributing #

Issues and pull requests are welcome!
Open an issue
Submit a PR


📃 License #

MIT — See LICENSE

3
likes
160
points
98
downloads

Publisher

verified publisherenzodesimone.dev

Weekly Downloads

2024.10.26 - 2025.09.20

Package to verify a firebase jwt token across multiple Firebase projects

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

http, intl, jose_plus, ntp_dart

More

Packages that depend on firebase_verify_token_dart