Skip to content

Commit

Permalink
Merge pull request #7 from byjg/bump
Browse files Browse the repository at this point in the history
Upgrade firebase/php-jwt component
  • Loading branch information
byjg committed May 21, 2023
2 parents b26045f + b9da40b commit 65df051
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 58 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: PHPUnit
on:
push:
branches:
- master
tags:
- "*.*.*"
pull_request:
branches:
- master
schedule:
- cron: "0 8 * * 1"

jobs:
Build:
runs-on: 'ubuntu-latest'
container: 'byjg/php:${{ matrix.php-version }}-cli'
strategy:
matrix:
php-version:
- "8.1"
- "8.0"
- "7.4"
- "7.3"
- "7.2"
- "7.1"

steps:
- uses: actions/checkout@v2
- run: composer install
- run: ./vendor/bin/phpunit

Documentation:
runs-on: 'ubuntu-latest'
needs: Build
if: github.ref == 'refs/heads/master'
env:
DOC_GITHUB_TOKEN: '${{ secrets.DOC_TOKEN }}'
steps:
- uses: actions/checkout@v2
- run: curl https://opensource.byjg.com/add-doc.sh | bash /dev/stdin php jwt-wrapper
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor
composer.lock

.idea
.phpunit.result.cache
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug current Script in Console",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9003,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "PHPUnit Debug",
"type": "php",
"request": "launch",
"program": "${workspaceFolder}/vendor/bin/phpunit",
"cwd": "${workspaceFolder}",
"port": 9003,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
}
]
}
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2017 Joao Gilberto Magalhaes

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Jwt-Wrapper for Firebase Jwt

[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg.com-brightgreen.svg)](http://opensource.byjg.com)
[![Build Status](https://travis-ci.org/byjg/jwt-wrapper.svg?branch=master)](https://travis-ci.org/byjg/jwt-wrapper)
[![Build Status](https://github.com/byjg/jwt-wrapper/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/jwt-wrapper/actions/workflows/phpunit.yml)
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/jwt-wrapper/)
[![GitHub license](https://img.shields.io/github/license/byjg/jwt-wrapper.svg)](https://opensource.byjg.com/opensource/licensing.html)
[![GitHub release](https://img.shields.io/github/release/byjg/jwt-wrapper.svg)](https://github.com/byjg/jwt-wrapper/releases/)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/byjg/jwt-wrapper/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/byjg/jwt-wrapper/?branch=master)

A very simple wrapper for create, encode, decode JWT Tokens and abstract the PHP JWT Component
Expand Down Expand Up @@ -177,4 +180,3 @@ http://localhost:8080/client.html

----
[Open source ByJG](http://opensource.byjg.com)

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
},
"license": "MIT",
"require": {
"firebase/php-jwt": "^5.0",
"firebase/php-jwt": "^6.4",
"ext-openssl": "*"
},
"require-dev": {
"phpunit/phpunit": "5.7.*|7.4.*"
"phpunit/phpunit": "5.7.*|7.4.*|9.5.*"
}
}
8 changes: 8 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ and open the template in the editor.
<!-- see http://www.phpunit.de/wiki/Documentation -->
<phpunit bootstrap="./vendor/autoload.php"
colors="true"
testdox="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
stopOnFailure="false">

<php>
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
<ini name="error_reporting" value="E_ALL" />
</php>

<filter>
<whitelist>
<directory>./src</directory>
Expand Down
6 changes: 2 additions & 4 deletions src/JwtWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ByJG\Util;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class JwtWrapper
{
Expand Down Expand Up @@ -97,10 +98,7 @@ public function extractData($bearer = null)

$jwtData = JWT::decode(
$bearer,
$this->jwtKey->getPublicKey(),
[
$this->jwtKey->getAlghoritm()
]
new Key($this->jwtKey->getPublicKey(), $this->jwtKey->getAlghoritm())
);

if (isset($jwtData->iss) && $jwtData->iss != $this->serverName) {
Expand Down
50 changes: 20 additions & 30 deletions tests/JwtWrapperHashTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

use ByJG\Util\JwtWrapper;
use ByJG\Util\JwtWrapperException;
use Firebase\JWT\BeforeValidException;
use Firebase\JWT\ExpiredException;
use Firebase\JWT\SignatureInvalidException;
use PHPUnit\Framework\TestCase;

class JwtWrapperHashTest extends TestCase
Expand All @@ -19,15 +23,15 @@ class JwtWrapperHashTest extends TestCase
*/
protected $jwtKey;

protected function setUp()
protected function setUp(): void
{
$this->jwtKey = \ByJG\Util\JwtKeySecret::getInstance("secrect_key_for_test", false);

unset($_SERVER["HTTP_AUTHORIZATION"]);
$this->object = new JwtWrapper($this->server, $this->jwtKey);
}

protected function tearDown()
protected function tearDown(): void
{
$this->object = null;
unset($_SERVER["HTTP_AUTHORIZATION"]);
Expand Down Expand Up @@ -100,12 +104,10 @@ public function testSuccessfulFlow2()

}

/**
* @throws \ByJG\Util\JwtWrapperException
* @expectedException \ByJG\Util\JwtWrapperException
*/
public function testTokenWrongServerSameSecret()
{
$this->expectException(JwtWrapperException::class);

$jwt = $this->object->createJwtData($this->dataToToken);
$token = $this->object->generateToken($jwt);

Expand All @@ -114,12 +116,10 @@ public function testTokenWrongServerSameSecret()
$jwtWrapper->extractData($token);
}

/**
* @throws \ByJG\Util\JwtWrapperException
* @expectedException \Firebase\JWT\SignatureInvalidException
*/
public function testTokenWrongSecret()
{
$this->expectException(SignatureInvalidException::class);

$jwt = $this->object->createJwtData($this->dataToToken);
$token = $this->object->generateToken($jwt);

Expand All @@ -128,12 +128,10 @@ public function testTokenWrongSecret()
$jwtWrapper->extractData($token);
}

/**
* @throws \ByJG\Util\JwtWrapperException
* @expectedException \Firebase\JWT\ExpiredException
*/
public function testExpiredToken()
{
$this->expectException(ExpiredException::class);

$jwt = $this->object->createJwtData($this->dataToToken,1);
$token = $this->object->generateToken($jwt);

Expand All @@ -142,42 +140,34 @@ public function testExpiredToken()
$this->object->extractData($token);
}

/**
* @throws \ByJG\Util\JwtWrapperException
* @expectedException \Firebase\JWT\BeforeValidException
*/
public function testNotBeforeToken()
{
$this->expectException(BeforeValidException::class);

$jwt = $this->object->createJwtData($this->dataToToken,60, 60);
$token = $this->object->generateToken($jwt);

$this->object->extractData($token);
}

/**
* @throws \ByJG\Util\JwtWrapperException
* @expectedException \ByJG\Util\JwtWrapperException
*/
public function testGetEmptyAuthorizationBearer()
{
$this->expectException(JwtWrapperException::class);

$this->object->extractData();
}

/**
* @throws \ByJG\Util\JwtWrapperException
* @expectedException UnexpectedValueException
*/
public function testGetInvalidTokenSequence()
{
$this->expectException(UnexpectedValueException::class);

$this->object->extractData("invalidtoken");
}

/**
* @throws \ByJG\Util\JwtWrapperException
* @expectedException DomainException
*/
public function testGetInvalidToken()
{
$this->expectException(DomainException::class);

$this->object->extractData("invalidtoken.hasthree.parts");
}
}
8 changes: 3 additions & 5 deletions tests/JwtWrapperSecretTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class JwtWrapperSecretTest extends JwtWrapperHashTest
/**
* @throws \ByJG\Util\JwtWrapperException
*/
protected function setUp()
protected function setUp(): void
{
$private = <<<TEXT
-----BEGIN RSA PRIVATE KEY-----
Expand Down Expand Up @@ -59,12 +59,10 @@ protected function setUp()
}


/**
* @throws \ByJG\Util\JwtWrapperException
* @expectedException \Firebase\JWT\SignatureInvalidException
*/
public function testTokenWrongSecret()
{
$this->expectException(\Firebase\JWT\SignatureInvalidException::class);

$jwt = $this->object->createJwtData($this->dataToToken);
$token = $this->object->generateToken($jwt);

Expand Down

0 comments on commit 65df051

Please sign in to comment.