Skip to content

Commit da20452

Browse files
committed
Initial commit
0 parents  commit da20452

23 files changed

+778
-0
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[Makefile]
16+
indent_style = tab
17+
18+
[.travis.yml]
19+
indent_size = 2

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.php diff=php
2+
3+
/.editorconfig export-ignore
4+
/.gitattributes export-ignore
5+
/.gitignore export-ignore
6+
/.php_cs export-ignore

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/build
2+
/vendor
3+
4+
/.php_cs.cache
5+
/composer.lock
6+
/phpunit.xml
7+
8+
/tests/credentials.json

.php_cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude(['build', 'vendor'])
5+
->in(__DIR__);
6+
7+
return PhpCsFixer\Config::create()
8+
->setUsingCache(true)
9+
->setRules([
10+
'@Symfony' => true,
11+
'header_comment' => ['header' => ''],
12+
'phpdoc_align' => false,
13+
'phpdoc_order' => true,
14+
'ordered_imports' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
])
17+
->setFinder($finder);

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CHANGELOG
2+
3+
## Unreleased
4+
5+
- Initial release

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Jérôme Gamez, https://github.com/jeromegamez <jerome@gamez.name>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.DEFAULT_GOAL:= help
2+
.PHONY: tests coverage view-coverage cs docs view-docs tag
3+
4+
tests: ## Executes the test suite
5+
vendor/bin/phpunit
6+
7+
coverage: ## Executes the test suite and generates code coverage reports
8+
@vendor/bin/phpunit --coverage-html=build/coverage
9+
10+
view-coverage: ## Shows the code coverage report
11+
open build/coverage/index.html
12+
13+
cs: ## Fixes coding standard problems
14+
@vendor/bin/php-cs-fixer fix || true
15+
16+
docs: ## Builds the documentation
17+
$(MAKE) -C docs html
18+
19+
view-docs: ## Shows the documentation
20+
open docs/_build/html/index.html
21+
22+
tag: ## Creates a new signed git tag
23+
$(if $(TAG),,$(error TAG is not defined. Pass via "make tag TAG=2.0.1"))
24+
@echo Tagging $(TAG)
25+
chag update $(TAG)
26+
git add --all
27+
git commit -m 'Release $(TAG)'
28+
git tag -s $(TAG) -m 'Release $(TAG)'
29+
30+
help:
31+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}'

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Firebase Tokens
2+
3+
A library to work with [Google Firebase](https://firebase.google.com>) tokens. You can use it to
4+
- [create custom tokens](https://firebase.google.com/docs/auth/admin/create-custom-tokens)
5+
- [verify ID Tokens](https://firebase.google.com/docs/auth/admin/verify-id-tokens)
6+
7+
## Installation
8+
9+
```
10+
composer require kreait/firebase-tokens
11+
```
12+
13+
## Create a custom token
14+
15+
```php
16+
use Firebase\Auth\Token\Generator;
17+
18+
$generator = new Generator($clientEmail, $privateKey);
19+
20+
$uid = 'a-uid';
21+
$claims = ['foo' => 'bar'];
22+
23+
$token = $generator->createCustomToken($uid, $claims); // Returns a Lcobucci\JWT\Token instance
24+
25+
echo $token; // "eyJ0eXAiOiJKV1..."
26+
```
27+
28+
## Verify an ID token
29+
30+
```php
31+
use Firebase\Auth\Token\Verifier;
32+
33+
$verifier = new Verifier($projectId);
34+
35+
$idTokenString = 'eyJhbGciOiJSUzI1...';
36+
37+
$token = $verifier->verifyIdToken($idTokenString);
38+
39+
$uid = $token->getClaim('sub');
40+
41+
echo $uid; // "a-uid"
42+
```

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "kreait/firebase-tokens",
3+
"description": "A library to work with Firebase tokens",
4+
"type": "library",
5+
"keywords": ["firebase", "google", "token", "authentication", "auth"],
6+
"homepage": "https://github.com/kreait/firebase-token-php",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Jérôme Gamez",
11+
"homepage": "https://github.com/jeromegamez"
12+
}
13+
],
14+
"require": {
15+
"lcobucci/jwt": "^3.2"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "^6.0",
19+
"friendsofphp/php-cs-fixer": "^2.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Firebase\\Auth\\Token\\": "src"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"Firebase\\Auth\\Token\\Tests\\": "tests"
29+
}
30+
},
31+
"config": {
32+
"platform": {
33+
"php": "7.0"
34+
}
35+
}
36+
}

phpunit.xml.dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.0/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
beStrictAboutOutputDuringTests="true"
6+
beStrictAboutTodoAnnotatedTests="true"
7+
verbose="true"
8+
colors="true">
9+
<testsuite name="Firebase Token Tests">
10+
<directory suffix="Test.php">tests</directory>
11+
</testsuite>
12+
13+
<filter>
14+
<whitelist processUncoveredFilesFromWhitelist="true">
15+
<directory suffix=".php">src</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

0 commit comments

Comments
 (0)