PHPackages                             firebase/token-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. firebase/token-generator

AbandonedArchivedLibrary[Authentication &amp; Authorization](/categories/authentication)

firebase/token-generator
========================

A simple library to generate JWT tokens for authenticating to a Firebase.

v3.0.0(10y ago)107764.3k—4.2%36[2 PRs](https://github.com/firebase/firebase-token-generator-php/pulls)3MITPHPPHP &gt;=5.4

Since Sep 4Pushed 7y ago42 watchersCompare

[ Source](https://github.com/firebase/firebase-token-generator-php)[ Packagist](https://packagist.org/packages/firebase/token-generator)[ Docs](https://github.com/firebase/firebase-token-generator-php)[ RSS](/packages/firebase-token-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (3)

Status: Archived
================

[](#status-archived)

This repository has been archived and is no longer maintained.

[![status: inactive](https://camo.githubusercontent.com/64a50b81eccd3654cd0ae31b8853fbdadc8a107f0c535983d4c1abe29ec183e9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374617475732d696e6163746976652d7265642e737667)](https://camo.githubusercontent.com/64a50b81eccd3654cd0ae31b8853fbdadc8a107f0c535983d4c1abe29ec183e9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374617475732d696e6163746976652d7265642e737667)

Firebase Token Generator - PHP
==============================

[](#firebase-token-generator---php)

**WARNING: This token generator is compatible with versions 1.x.x and 2.x.x of the Firebase SDK. If you are using the 3.x.x SDK, please refer to the documentation [here](https://firebase.google.com/docs/auth/server#use_a_jwt_library).**

[Firebase Custom Login](https://www.firebase.com/docs/web/guide/simple-login/custom.html)gives you complete control over user authentication by allowing you to authenticate users with secure JSON Web Tokens (JWTs). The auth payload stored in those tokens is available for use in your Firebase [security rules](https://www.firebase.com/docs/security/api/rule/). This is a token generator library for PHP which allows you to easily create those JWTs.

Dependencies
------------

[](#dependencies)

The Firebase PHP token generator library depends on [PHP-JWT](https://github.com/firebase/php-jwt).

A Note About Security
---------------------

[](#a-note-about-security)

**IMPORTANT:** Because token generation requires your Firebase Secret, you should only generate tokens on *trusted servers*. Never embed your Firebase Secret directly into your application and never share your Firebase Secret with a connected client.

Installation
------------

[](#installation)

Using composer:

```
composer require firebase/token-generator

```

Generating Tokens
-----------------

[](#generating-tokens)

To generate tokens, you'll need your Firebase Secret which you can find by entering your Firebase URL into a browser and clicking the "Secrets" tab on the left-hand navigation menu.

Once you've downloaded the library and grabbed your Firebase Secret, you can generate a token with this snippet of PHP code:

```
use Firebase\Token\TokenException;
use Firebase\Token\TokenGenerator;

try {
    $generator = new TokenGenerator('');
    $token = $generator
        ->setData(array('uid' => 'exampleID'))
        ->create();
} catch (TokenException $e) {
    echo "Error: ".$e->getMessage();
}

echo $token;
```

The payload passed to `setData()` is made available for use within your security rules via the [`auth` variable](https://www.firebase.com/docs/security/api/rule/auth.html). This is how you pass trusted authentication details (e.g. the client's user ID) to your Firebase security rules. The payload can contain any data of your choosing, however it must contain a "uid" key, which must be a string of less than 256 characters. The generated token must be less than 1024 characters in total.

Token Options
-------------

[](#token-options)

Token options can be set to modify how Firebase treats the token. Available options are:

- **expires** (number or DateTime) - A timestamp (as number of seconds since the epoch) or a `DateTime`denoting the time after which this token should no longer be valid.
- **notBefore** (number or DateTime) - A timestamp (as number of seconds since the epoch) or a `DateTime`denoting the time before which this token should be rejected by the server.
- **admin** (boolean) - Set to `True` if you want to disable all security rules for this client. This will provide the client with read and write access to your entire Firebase database.
- **debug** (boolean) - Set to `True` to enable debug output from your security rules. You should generally *not* leave this set to `True` in production (as it slows down the rules implementation and gives your users visibility into your rules), but it can be helpful for debugging.

Here is an example of how to set options:

```
use Firebase\Token\TokenGenerator;

$generator = new TokenGenerator('');

// Using setOption()
$token = $generator
    ->setOption('admin', true)
    ->setOption('debug', true)
    ->setData(array('uid' => 'exampleID'))
    ->create();

// Using setOptions()
$token = $generator
    ->setOptions(array(
        'admin' => true,
        'debug' => true
    ))
    ->setData(array('uid' => 'exampleID'))
    ->create();
```

Changelog
---------

[](#changelog)

#### 3.0.0 - 2015-11-18

[](#300---2015-11-18)

- Update PHP-JWT to &gt;= 3.0
- Remove deprecated `Services_FirebaseTokenGenerator` and update tests
- Thanks to [@jeromegamez](https://github.com/jeromegamez) for the above contributions!

#### 2.1.0 - 2015-06-22

[](#210---2015-06-22)

- Update the minimum required PHP version to &gt;= 5.4.
- [Major package overhaul including API improvements](https://github.com/firebase/firebase-token-generator-php/pull/18)thanks to [@jeromegamez](https://github.com/jeromegamez)!

#### 2.0.1 - 2015-04-02

[](#201---2015-04-02)

- Specifying the PHP-JWT version more specifically.

#### 2.0.0 - 2014-09-15

[](#200---2014-09-15)

- Additional validation to ensure tokens contain a "uid" field unless they have the "admin" option set to `true`.

#### 1.0.0 - 2014-09-04

[](#100---2014-09-04)

- Initial release

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~110 days

Total

5

Last Release

3834d ago

Major Versions

1.0.0 → 2.0.02014-09-15

v2.1.0 → v3.0.02015-11-19

PHP version history (2 changes)1.0.0PHP &gt;=5.2.0

v2.1.0PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/315ac8ecd2e700ed1b16dd74da5c13607f2ac6b5d834c3d47fde6a92b1ee0b50?d=identicon)[firebase](/maintainers/firebase)

---

Top Contributors

[![jeromegamez](https://avatars.githubusercontent.com/u/67554?v=4)](https://github.com/jeromegamez "jeromegamez (25 commits)")[![anantn](https://avatars.githubusercontent.com/u/37190?v=4)](https://github.com/anantn "anantn (9 commits)")[![robertdimarco](https://avatars.githubusercontent.com/u/136118?v=4)](https://github.com/robertdimarco "robertdimarco (9 commits)")[![ktamas77](https://avatars.githubusercontent.com/u/1231708?v=4)](https://github.com/ktamas77 "ktamas77 (2 commits)")[![startupandrew](https://avatars.githubusercontent.com/u/737418?v=4)](https://github.com/startupandrew "startupandrew (1 commits)")[![tonytaing](https://avatars.githubusercontent.com/u/769002?v=4)](https://github.com/tonytaing "tonytaing (1 commits)")[![aleemb](https://avatars.githubusercontent.com/u/46616?v=4)](https://github.com/aleemb "aleemb (1 commits)")[![Vijar](https://avatars.githubusercontent.com/u/759766?v=4)](https://github.com/Vijar "Vijar (1 commits)")[![katowulf](https://avatars.githubusercontent.com/u/959972?v=4)](https://github.com/katowulf "katowulf (1 commits)")[![mikelehen](https://avatars.githubusercontent.com/u/206364?v=4)](https://github.com/mikelehen "mikelehen (1 commits)")[![samtstern](https://avatars.githubusercontent.com/u/8466666?v=4)](https://github.com/samtstern "samtstern (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/firebase-token-generator/health.svg)

```
[![Health](https://phpackages.com/badges/firebase-token-generator/health.svg)](https://phpackages.com/packages/firebase-token-generator)
```

###  Alternatives

[google/auth

Google Auth Library for PHP

1.4k272.7M162](/packages/google-auth)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[robsontenorio/laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel

5161.1M3](/packages/robsontenorio-laravel-keycloak-guard)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[wp-graphql/wp-graphql-jwt-authentication

JWT Authentication for WPGraphQL

361118.4k1](/packages/wp-graphql-wp-graphql-jwt-authentication)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
