kreait / firebase-tokens-php

A PHP library to work with Firebase tokens
MIT License
223 stars 33 forks source link

Add tenant support #31

Closed jeromegamez closed 3 years ago

jeromegamez commented 3 years ago

How to test

$ composer require kreait/firebase-tokens:dev-tenant-awareness

Custom Token Generation

<?php

use Kreait\Firebase\JWT\CustomTokenGenerator;

$clientEmail = '...';
$privateKey = '...';
$tenantId = '...';

$generator = CustomTokenGenerator::withClientEmailAndPrivateKey($clientEmail, $privateKey);

$tenantAwareGenerator = $generator->withTenantId($tenantId);

$token = $tenantAwareGenerator->createCustomToken('uid', ['first_claim' => 'first_value' /* ... */]);

ID Token verification

<?php

use Kreait\Firebase\JWT\Error\IdTokenVerificationFailed;
use Kreait\Firebase\JWT\IdTokenVerifier;

$projectId = '...';
$tenantId = '...';
$idToken = 'eyJhb...'; // An ID token given to your backend by a Client application

$verifier = IdTokenVerifier::createWithProjectId($projectId);
$tenantAwareVerifier = $verifier->withExpectedTenantId($tenantId);

$token = $tenantAwareVerifier->verifyIdToken($idToken);

Todo

:octocat: