Skip to content

Commit 44dbe40

Browse files
committed
Avoid setting empty claims
… and remove duplicate (and unneeded) "main" claims: Firebase expects all claims to be bundled in a "claims" claim.
1 parent 9abb9a4 commit 44dbe40

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## Unreleased
4+
5+
- Fixed [https://github.com/kreait/firebase-php/issues/65](kreait/firebase-php#65):
6+
invalid custom token when no claims are given.
7+
38
## 1.1.0 - 2017-02-18
49

510
- Replaced `StaticKeyStore` with `HttpKeyStore`, which fetches frech Google Public Keys

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

1010
## Installation
1111

src/Generator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ public function __construct(
5353
*/
5454
public function createCustomToken($uid, array $claims = []): Token
5555
{
56-
foreach ($claims as $key => $value) {
57-
$this->builder->set($key, $value);
56+
if (count($claims)) {
57+
$this->builder->set('claims', $claims);
5858
}
5959

60-
$this->builder->set('claims', $claims);
61-
6260
$this->builder->set('uid', (string) $uid);
6361

6462
$now = time();

tests/GeneratorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,11 @@ public function testCreateCustomToken()
2424

2525
$this->assertInstanceOf(Token::class, $token);
2626
}
27+
28+
public function testCreateCustomTokenWithEmptyClaims()
29+
{
30+
$token = $this->generator->createCustomToken('some-uid');
31+
32+
$this->assertInstanceOf(Token::class, $token);
33+
}
2734
}

0 commit comments

Comments
 (0)