Skip to content

Commit

Permalink
Avoid setting empty claims
Browse files Browse the repository at this point in the history
… and remove duplicate (and unneeded) "main" claims: Firebase expects all claims to be bundled in a "claims" claim.
  • Loading branch information
jeromegamez committed Feb 19, 2017
1 parent 9abb9a4 commit 44dbe40
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## Unreleased

- Fixed [https://github.com/kreait/firebase-php/issues/65](kreait/firebase-php#65):
invalid custom token when no claims are given.

## 1.1.0 - 2017-02-18

- Replaced `StaticKeyStore` with `HttpKeyStore`, which fetches frech Google Public Keys
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

A library to work with [Google Firebase](https://firebase.google.com>) tokens. You can use it to
[create custom tokens](https://firebase.google.com/docs/auth/admin/create-custom-tokens) and
[verify ID Tokens](https://firebase.google.com/docs/auth/admin/verify-id-tokens).
[verify ID Tokens](https://firebase.google.com/docs/auth/admin/verify-id-tokens).

## Installation

Expand Down
6 changes: 2 additions & 4 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ public function __construct(
*/
public function createCustomToken($uid, array $claims = []): Token
{
foreach ($claims as $key => $value) {
$this->builder->set($key, $value);
if (count($claims)) {
$this->builder->set('claims', $claims);
}

$this->builder->set('claims', $claims);

$this->builder->set('uid', (string) $uid);

$now = time();
Expand Down
7 changes: 7 additions & 0 deletions tests/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ public function testCreateCustomToken()

$this->assertInstanceOf(Token::class, $token);
}

public function testCreateCustomTokenWithEmptyClaims()
{
$token = $this->generator->createCustomToken('some-uid');

$this->assertInstanceOf(Token::class, $token);
}
}

0 comments on commit 44dbe40

Please sign in to comment.