added predis and eseye back in.

This commit is contained in:
2020-12-25 11:28:41 +00:00
parent 0ddd298350
commit 017f72b42e
670 changed files with 60992 additions and 10 deletions

View File

@@ -0,0 +1,4 @@
# Contributing
This repository is a sub repository of [the JWT Framework](https://github.com/web-token/jwt-framework) project and is READ ONLY.
Please do not submit any Pull Requests here. It will be automatically closed.

View File

@@ -0,0 +1 @@
patreon: FlorentMorselli

View File

@@ -0,0 +1,3 @@
Please do not submit any Pull Requests here. It will be automatically closed.
You should submit it here: https://github.com/web-token/jwt-framework/pulls

View File

@@ -0,0 +1,157 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use InvalidArgumentException;
use function is_string;
use Jose\Component\Core\Algorithm as JoseAlgorithm;
use Jose\Component\Signature\Algorithm;
abstract class AbstractBuilder
{
/**
* @var JWT
*/
protected $jwt;
/**
* @var JoseAlgorithm[]
*/
protected $algorithms = [];
public function __construct()
{
$this->jwt = new JWT();
$this->algorithms = (new AlgorithmProvider($this->getAlgorithmMap()))
->getAvailableAlgorithms()
;
}
public function payload(array $payload): self
{
$clone = clone $this;
$clone->jwt->claims->replace($payload);
return $clone;
}
public function iss(string $iss, bool $inHeader = false): self
{
return $this->claim('iss', $iss, $inHeader);
}
public function sub(string $sub, bool $inHeader = false): self
{
return $this->claim('sub', $sub, $inHeader);
}
public function aud(string $aud, bool $inHeader = false): self
{
$audience = $this->jwt->claims->has('aud') ? $this->jwt->claims->get('aud') : [];
$audience[] = $aud;
return $this->claim('aud', $audience, $inHeader);
}
public function jti(string $jti, bool $inHeader = false): self
{
return $this->claim('jti', $jti, $inHeader);
}
public function exp(int $exp, bool $inHeader = false): self
{
return $this->claim('exp', $exp, $inHeader);
}
public function iat(?int $iat = null, bool $inHeader = false): self
{
$iat = $iat ?? time();
return $this->claim('iat', $iat, $inHeader);
}
public function nbf(?int $nbf = null, bool $inHeader = false): self
{
$nbf = $nbf ?? time();
return $this->claim('nbf', $nbf, $inHeader);
}
/**
* @param Algorithm\SignatureAlgorithm|string $alg
*
* @throws InvalidArgumentException if the algorithm is not a string or an instance of Jose\Component\Core\Algorithm
*/
public function alg($alg): self
{
$clone = clone $this;
switch (true) {
case $alg instanceof JoseAlgorithm:
$clone->algorithms[] = $alg;
$clone->jwt->header->set('alg', $alg->name());
break;
case is_string($alg):
$clone->jwt->header->set('alg', $alg);
break;
default:
throw new InvalidArgumentException('Invalid parameter "alg". Shall be a string or an algorithm instance.');
}
return $clone;
}
public function cty(string $cty): self
{
return $this->header('cty', $cty);
}
public function typ(string $typ): self
{
return $this->header('typ', $typ);
}
public function crit(array $crit): self
{
return $this->header('crit', $crit);
}
/**
* @param mixed $value
*/
public function claim(string $key, $value, bool $inHeader = false): self
{
$clone = clone $this;
$clone->jwt->claims->set($key, $value);
if ($inHeader) {
$clone->jwt->header->set($key, $value);
}
return $clone;
}
/**
* @param mixed $value
*/
public function header(string $key, $value): self
{
$clone = clone $this;
$clone->jwt->header->set($key, $value);
return $clone;
}
abstract protected function getAlgorithmMap(): array;
}

View File

@@ -0,0 +1,287 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use function in_array;
use InvalidArgumentException;
use function is_array;
use function is_callable;
use function is_int;
use function is_string;
use Jose\Component\Checker;
use Jose\Component\Core\Algorithm;
use Jose\Component\Core\JWK;
use Jose\Component\Core\JWKSet;
abstract class AbstractLoader
{
/**
* @var string
*/
protected $token;
/**
* @var JWKSet
*/
protected $jwkset;
/**
* @var Checker\HeaderChecker[]
*/
protected $headerCheckers = [];
/**
* @var Checker\ClaimChecker[]
*/
protected $claimCheckers = [];
/**
* @var string[]
*/
protected $allowedAlgorithms = [];
/**
* @var Algorithm[]
*/
protected $algorithms = [];
/**
* @var string[]
*/
protected $mandatoryClaims = [];
protected function __construct(string $token)
{
$this->token = $token;
$this->jwkset = new JWKSet([]);
$this->claimCheckers = [];
$this->algorithms = (new AlgorithmProvider($this->getAlgorithmMap()))
->getAvailableAlgorithms()
;
}
/**
* @param string[] $mandatoryClaims
*/
public function mandatory(array $mandatoryClaims): self
{
$clone = clone $this;
$clone->mandatoryClaims = $mandatoryClaims;
return $clone;
}
public function aud(string $aud, bool $inHeader = false): self
{
return $this->claim('aud', new Checker\AudienceChecker($aud, true), $inHeader);
}
public function iss(string $iss, bool $inHeader = false): self
{
return $this->claim('iss', new Checker\IssuerChecker([$iss], true), $inHeader);
}
public function jti(string $jti, bool $inHeader = false): self
{
return $this->claim('jti', $jti, $inHeader);
}
public function sub(string $sub, bool $inHeader = false): self
{
return $this->claim('sub', $sub, $inHeader);
}
/**
* @param null|array|callable|Checker\ClaimChecker $checker
*/
public function claim(string $key, $checker, bool $inHeader = false): self
{
$clone = clone $this;
if (false === $checker) {
unset($clone->claimCheckers[$key]);
return $clone;
}
switch (true) {
case $checker instanceof Checker\ClaimChecker:
break;
case is_callable($checker):
$checker = new CallableChecker($key, $checker);
break;
case is_array($checker):
$checker = new CallableChecker($key, static function ($value) use ($checker) {return in_array($value, $checker, true); });
break;
default:
$checker = new CallableChecker($key, static function ($value) use ($checker) {return $value === $checker; });
}
$clone->claimCheckers[$key] = $checker;
if ($inHeader) {
return $clone->header($key, $checker);
}
return $clone;
}
/**
* @param false|int $leeway
*
* @throws InvalidArgumentException if the leeway is negative, not an integer or not false
*/
public function exp($leeway = 0, bool $inHeader = false): self
{
if (false === $leeway) {
$clone = clone $this;
unset($clone->claimCheckers['exp']);
return $clone;
}
if (!is_int($leeway) or $leeway < 0) {
throw new InvalidArgumentException('First parameter for "exp" claim is invalid. Set false to disable or a positive integer.');
}
return $this->claim('exp', new Checker\ExpirationTimeChecker($leeway), $inHeader);
}
/**
* @param false|int $leeway
*
* @throws InvalidArgumentException if the leeway is negative, not an integer or not false
*/
public function nbf($leeway = 0, bool $inHeader = false): self
{
if (false === $leeway) {
$clone = clone $this;
unset($clone->claimCheckers['nbf']);
return $clone;
}
if (!is_int($leeway) or $leeway < 0) {
throw new InvalidArgumentException('First parameter for "nbf" claim is invalid. Set false to disable or a positive integer.');
}
return $this->claim('nbf', new Checker\NotBeforeChecker($leeway, true), $inHeader);
}
/**
* @param false|int $leeway
*
* @throws InvalidArgumentException if the leeway is negative, not an integer or not false
*/
public function iat($leeway = 0, bool $inHeader = false): self
{
if (false === $leeway) {
$clone = clone $this;
unset($clone->claimCheckers['iat']);
return $clone;
}
if (!is_int($leeway) or $leeway < 0) {
throw new InvalidArgumentException('First parameter for "iat" claim is invalid. Set false to disable or a positive integer.');
}
return $this->claim('iat', new Checker\IssuedAtChecker($leeway, true), $inHeader);
}
/**
* @param Algorithm|string $alg
*
* @throws InvalidArgumentException if the algorithm is not a string or an instance of Jose\Component\Core\Algorithm
*/
public function alg($alg): self
{
$clone = clone $this;
switch (true) {
case is_string($alg):
$clone->allowedAlgorithms[] = $alg;
return $clone;
case $alg instanceof Algorithm:
$clone->algorithms[$alg->name()] = $alg;
$clone->allowedAlgorithms[] = $alg->name();
return $clone;
default:
throw new InvalidArgumentException('Invalid parameter "alg". Shall be a string or an algorithm instance.');
}
}
/**
* @param Algorithm[]|string[] $algs
*/
public function algs($algs): self
{
$clone = clone $this;
foreach ($algs as $alg) {
$clone = $clone->alg($alg);
}
return $clone;
}
/**
* @param array|callable|Checker\HeaderChecker|false|mixed $checker
*/
public function header(string $key, $checker): self
{
$clone = clone $this;
if (false === $checker) {
unset($clone->headerCheckers[$key]);
return $clone;
}
switch (true) {
case $checker instanceof Checker\HeaderChecker:
break;
case is_callable($checker):
$checker = new CallableChecker($key, $checker);
break;
case is_array($checker):
$checker = new CallableChecker($key, static function ($value) use ($checker) {return in_array($value, $checker, true); });
break;
default:
$checker = new CallableChecker($key, static function ($value) use ($checker) {return $value === $checker; });
}
$clone->headerCheckers[$key] = $checker;
return $clone;
}
public function key(JWK $jwk): self
{
$clone = clone $this;
$jwkset = $this->jwkset->with($jwk);
$clone->jwkset = $jwkset;
return $clone;
}
public function keyset(JWKSet $jwkset): self
{
$clone = clone $this;
$clone->jwkset = $jwkset;
return $clone;
}
abstract protected function getAlgorithmMap(): array;
}

View File

@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use Jose\Component\Core\Algorithm;
use Throwable;
final class AlgorithmProvider
{
/**
* @var string[]
*/
private $algorithmClasses;
/**
* @var Algorithm[]
*/
private $algorithms = [];
public function __construct(array $algorithmClasses)
{
$this->algorithmClasses = $algorithmClasses;
foreach ($algorithmClasses as $algorithmClass) {
$this->addClass($algorithmClass);
}
}
public function getAlgorithmClasses(): array
{
return $this->algorithmClasses;
}
public function getAvailableAlgorithms(): array
{
return $this->algorithms;
}
private function addClass(string $algorithmClass): void
{
if (class_exists($algorithmClass)) {
try {
$this->algorithms[] = new $algorithmClass();
} catch (Throwable $throwable) {
//does nothing
}
}
}
}

27
vendor/web-token/jwt-easy/Build.php vendored Normal file
View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
class Build
{
public static function jws(): JWSBuilder
{
return new JWSBuilder();
}
public static function jwe(): JWEBuilder
{
return new JWEBuilder();
}
}

View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use Jose\Component\Checker\ClaimChecker;
use Jose\Component\Checker\HeaderChecker;
use Jose\Component\Checker\InvalidClaimException;
use Jose\Component\Checker\InvalidHeaderException;
final class CallableChecker implements ClaimChecker, HeaderChecker
{
/**
* @var string
*/
private $key;
/**
* @var callable
*/
private $callable;
public function __construct(string $key, callable $callable)
{
$this->key = $key;
$this->callable = $callable;
}
/**
* @param mixed $value
*
* @throws InvalidClaimException if the claim is invalid
*/
public function checkClaim($value): void
{
$callable = $this->callable;
$isValid = $callable($value);
if (!$isValid) {
throw new InvalidClaimException(sprintf('Invalid claim "%s"', $this->key), $this->key, $value);
}
}
public function supportedClaim(): string
{
return $this->key;
}
/**
* {@inheritdoc}
*/
public function checkHeader($value): void
{
$callable = $this->callable;
$isValid = $callable($value);
if (!$isValid) {
throw new InvalidHeaderException(sprintf('Invalid header "%s"', $this->key), $this->key, $value);
}
}
public function supportedHeader(): string
{
return $this->key;
}
public function protectedHeaderOnly(): bool
{
return true;
}
}

View File

@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use function in_array;
use function is_string;
use Jose\Component\Checker\HeaderChecker;
use Jose\Component\Checker\InvalidHeaderException;
/**
* This class is a header parameter checker.
* When the "enc" header parameter is present, it will check if the value is within the allowed ones.
*/
final class ContentEncryptionAlgorithmChecker implements HeaderChecker
{
private const HEADER_NAME = 'enc';
/**
* @var bool
*/
private $protectedHeader = false;
/**
* @var string[]
*/
private $supportedAlgorithms;
/**
* @param string[] $supportedAlgorithms
*/
public function __construct(array $supportedAlgorithms, bool $protectedHeader = false)
{
$this->supportedAlgorithms = $supportedAlgorithms;
$this->protectedHeader = $protectedHeader;
}
/**
* {@inheritdoc}
*
* @throws InvalidHeaderException if the header is invalid
*/
public function checkHeader($value): void
{
if (!is_string($value)) {
throw new InvalidHeaderException('"enc" must be a string.', self::HEADER_NAME, $value);
}
if (!in_array($value, $this->supportedAlgorithms, true)) {
throw new InvalidHeaderException('Unsupported algorithm.', self::HEADER_NAME, $value);
}
}
public function supportedHeader(): string
{
return self::HEADER_NAME;
}
public function protectedHeaderOnly(): bool
{
return $this->protectedHeader;
}
}

149
vendor/web-token/jwt-easy/Decrypt.php vendored Normal file
View File

@@ -0,0 +1,149 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use function count;
use InvalidArgumentException;
use function is_string;
use Jose\Component\Checker;
use Jose\Component\Core\Algorithm;
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Core\Util\JsonConverter;
use Jose\Component\Encryption\Algorithm\ContentEncryption;
use Jose\Component\Encryption\Algorithm\KeyEncryption;
use Jose\Component\Encryption\Compression\CompressionMethod;
use Jose\Component\Encryption\Compression\CompressionMethodManager;
use Jose\Component\Encryption\Compression\Deflate;
use Jose\Component\Encryption\JWEDecrypter;
use Jose\Component\Encryption\JWETokenSupport;
use Jose\Component\Encryption\Serializer\CompactSerializer;
class Decrypt extends AbstractLoader
{
/**
* @var string[]
*/
protected $allowedContentEncryptionAlgorithms = [];
/**
* @var CompressionMethod[]
*/
private $compressionMethods;
private function __construct(string $token)
{
parent::__construct($token);
$this->compressionMethods = [
new Deflate(),
];
}
public static function token(string $token): self
{
return new self($token);
}
/**
* @param Algorithm|string $enc
*
* @throws InvalidArgumentException if the encryption algorithm is invalid
*/
public function enc($enc): self
{
$clone = clone $this;
switch (true) {
case is_string($enc):
$clone->allowedContentEncryptionAlgorithms[] = $enc;
return $clone;
case $enc instanceof Algorithm:
$clone->algorithms[$enc->name()] = $enc;
$clone->allowedContentEncryptionAlgorithms[] = $enc->name();
return $clone;
default:
throw new InvalidArgumentException('Invalid parameter "enc". Shall be a string or an algorithm instance.');
}
}
/**
* @param Algorithm[]|string[] $encs
*/
public function encs($encs): self
{
$clone = clone $this;
foreach ($encs as $enc) {
$clone = $clone->enc($enc);
}
return $clone;
}
public function run(): JWT
{
if (0 !== count($this->allowedAlgorithms)) {
$this->headerCheckers[] = new Checker\AlgorithmChecker($this->allowedAlgorithms, true);
}
if (0 !== count($this->allowedContentEncryptionAlgorithms)) {
$this->headerCheckers[] = new ContentEncryptionAlgorithmChecker($this->allowedContentEncryptionAlgorithms, true);
}
$jwe = (new CompactSerializer())->unserialize($this->token);
$headerChecker = new Checker\HeaderCheckerManager($this->headerCheckers, [new JWETokenSupport()]);
$headerChecker->check($jwe, 0);
$verifier = new JWEDecrypter(
new AlgorithmManager($this->algorithms),
new AlgorithmManager($this->algorithms),
new CompressionMethodManager($this->compressionMethods)
);
$verifier->decryptUsingKeySet($jwe, $this->jwkset, 0);
$jwt = new JWT();
$jwt->header->replace($jwe->getSharedProtectedHeader());
$jwt->claims->replace(JsonConverter::decode($jwe->getPayload()));
$claimChecker = new Checker\ClaimCheckerManager($this->claimCheckers);
$claimChecker->check($jwt->claims->all(), $this->mandatoryClaims);
return $jwt;
}
protected function getAlgorithmMap(): array
{
return [
KeyEncryption\A128GCMKW::class,
KeyEncryption\A192GCMKW::class,
KeyEncryption\A256GCMKW::class,
KeyEncryption\A128KW::class,
KeyEncryption\A192KW::class,
KeyEncryption\A256KW::class,
KeyEncryption\Dir::class,
KeyEncryption\ECDHES::class,
KeyEncryption\ECDHESA128KW::class,
KeyEncryption\ECDHESA192KW::class,
KeyEncryption\ECDHESA256KW::class,
KeyEncryption\PBES2HS256A128KW::class,
KeyEncryption\PBES2HS384A192KW::class,
KeyEncryption\PBES2HS512A256KW::class,
KeyEncryption\RSA15::class,
KeyEncryption\RSAOAEP::class,
KeyEncryption\RSAOAEP256::class,
ContentEncryption\A128GCM::class,
ContentEncryption\A192GCM::class,
ContentEncryption\A256GCM::class,
ContentEncryption\A128CBCHS256::class,
ContentEncryption\A192CBCHS384::class,
ContentEncryption\A256CBCHS512::class,
];
}
}

141
vendor/web-token/jwt-easy/JWEBuilder.php vendored Normal file
View File

@@ -0,0 +1,141 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use InvalidArgumentException;
use function is_string;
use Jose\Component\Core\Algorithm;
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Core\JWK;
use Jose\Component\Core\Util\JsonConverter;
use Jose\Component\Encryption\Algorithm\ContentEncryption;
use Jose\Component\Encryption\Algorithm\KeyEncryption;
use Jose\Component\Encryption\Compression\CompressionMethod;
use Jose\Component\Encryption\Compression\CompressionMethodManager;
use Jose\Component\Encryption\Compression\Deflate;
use Jose\Component\Encryption\JWEBuilder as JoseBuilder;
use Jose\Component\Encryption\Serializer\CompactSerializer;
class JWEBuilder extends AbstractBuilder
{
/**
* @var CompressionMethod[]
*/
private $compressionMethods;
public function __construct()
{
parent::__construct();
$this->compressionMethods = [
new Deflate(),
];
}
/**
* @param Algorithm|string $enc
*
* @throws InvalidArgumentException if the header parameter "enc" is invalid
*/
public function enc($enc): self
{
$clone = clone $this;
switch (true) {
case $enc instanceof Algorithm:
$clone->algorithms[] = $enc;
$clone->jwt->header->set('enc', $enc->name());
break;
case is_string($enc):
$clone->jwt->header->set('enc', $enc);
break;
default:
throw new InvalidArgumentException('Invalid algorithm');
}
return $clone;
}
/**
* @param CompressionMethod|string $zip
*
* @throws InvalidArgumentException if the header parameter "zip" is invalid
*/
public function zip($zip): self
{
$clone = clone $this;
switch (true) {
case $zip instanceof CompressionMethod:
$clone->compressionMethods[] = $zip;
$clone->jwt->header->set('zip', $zip->name());
break;
case is_string($zip):
$clone->jwt->header->set('zip', $zip);
break;
default:
throw new InvalidArgumentException('Invalid compression method');
}
return $clone;
}
public function encrypt(JWK $jwk): string
{
$builder = new JoseBuilder(
new AlgorithmManager($this->algorithms),
new AlgorithmManager($this->algorithms),
new CompressionMethodManager($this->compressionMethods)
);
$jwe = $builder
->create()
->withPayload(JsonConverter::encode($this->jwt->claims->all()))
->withSharedProtectedHeader($this->jwt->header->all())
->addRecipient($jwk)
->build()
;
return (new CompactSerializer())->serialize($jwe);
}
protected function getAlgorithmMap(): array
{
return [
KeyEncryption\A128GCMKW::class,
KeyEncryption\A192GCMKW::class,
KeyEncryption\A256GCMKW::class,
KeyEncryption\A128KW::class,
KeyEncryption\A192KW::class,
KeyEncryption\A256KW::class,
KeyEncryption\Dir::class,
KeyEncryption\ECDHES::class,
KeyEncryption\ECDHESA128KW::class,
KeyEncryption\ECDHESA192KW::class,
KeyEncryption\ECDHESA256KW::class,
KeyEncryption\PBES2HS256A128KW::class,
KeyEncryption\PBES2HS384A192KW::class,
KeyEncryption\PBES2HS512A256KW::class,
KeyEncryption\RSA15::class,
KeyEncryption\RSAOAEP::class,
KeyEncryption\RSAOAEP256::class,
ContentEncryption\A128GCM::class,
ContentEncryption\A192GCM::class,
ContentEncryption\A256GCM::class,
ContentEncryption\A128CBCHS256::class,
ContentEncryption\A192CBCHS384::class,
ContentEncryption\A256CBCHS512::class,
];
}
}

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Core\JWK;
use Jose\Component\Core\Util\JsonConverter;
use Jose\Component\Signature\Algorithm;
use Jose\Component\Signature\JWSBuilder as JoseBuilder;
use Jose\Component\Signature\Serializer\CompactSerializer;
class JWSBuilder extends AbstractBuilder
{
public function sign(JWK $jwk): string
{
$builder = new JoseBuilder(new AlgorithmManager($this->algorithms));
$jws = $builder
->create()
->withPayload(JsonConverter::encode($this->jwt->claims->all()))
->addSignature($jwk, $this->jwt->header->all())
->build()
;
return (new CompactSerializer())->serialize($jws);
}
protected function getAlgorithmMap(): array
{
return [
Algorithm\HS256::class,
Algorithm\HS384::class,
Algorithm\HS512::class,
Algorithm\RS256::class,
Algorithm\RS384::class,
Algorithm\RS512::class,
Algorithm\PS256::class,
Algorithm\PS384::class,
Algorithm\PS512::class,
Algorithm\ES256::class,
Algorithm\ES384::class,
Algorithm\ES512::class,
Algorithm\EdDSA::class,
];
}
}

33
vendor/web-token/jwt-easy/JWT.php vendored Normal file
View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
final class JWT
{
/**
* @var ParameterBag
*/
public $claims;
/**
* @var ParameterBag
*/
public $header;
public function __construct()
{
$this->claims = new ParameterBag();
$this->header = new ParameterBag();
}
}

21
vendor/web-token/jwt-easy/LICENSE vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-2019 Spomky-Labs
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.

27
vendor/web-token/jwt-easy/Load.php vendored Normal file
View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
class Load
{
public static function jws(string $jws): Validate
{
return Validate::token($jws);
}
public static function jwe(string $jwe): Decrypt
{
return Decrypt::token($jwe);
}
}

View File

@@ -0,0 +1,116 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use function array_key_exists;
use ArrayIterator;
use function call_user_func_array;
use function count;
use Countable;
use InvalidArgumentException;
use IteratorAggregate;
class ParameterBag implements IteratorAggregate, Countable
{
/**
* @var array
*/
private $parameters = [];
/**
* @return mixed
*/
public function __call(string $name, array $arguments)
{
if (method_exists($this, $name)) {
return call_user_func_array([$this, $name], $arguments);
}
if (0 === count($arguments)) {
return $this->get($name);
}
array_unshift($arguments, $name);
return call_user_func_array([$this, 'set'], $arguments);
}
public function all(): array
{
return $this->parameters;
}
public function keys(): array
{
return array_keys($this->parameters);
}
public function replace(array $parameters): void
{
$this->parameters = $parameters;
}
/**
* @throws InvalidArgumentException if the parameters are invalid
*/
public function add(array $parameters): void
{
$replaced = array_replace($this->parameters, $parameters);
if (null === $replaced) {
throw new InvalidArgumentException('Invalid parameters');
}
$this->parameters = $replaced;
}
/**
* @throws InvalidArgumentException if the selected parameter is missing
*
* @return mixed
*/
public function get(string $key)
{
if (!array_key_exists($key, $this->parameters)) {
throw new InvalidArgumentException(sprintf('Parameter "%s" is missing', $key));
}
return $this->parameters[$key];
}
/**
* @param mixed $value The value
*/
public function set(string $key, $value): void
{
$this->parameters[$key] = $value;
}
public function has(string $key): bool
{
return array_key_exists($key, $this->parameters);
}
public function remove(string $key): void
{
unset($this->parameters[$key]);
}
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->parameters);
}
public function count(): int
{
return count($this->parameters);
}
}

15
vendor/web-token/jwt-easy/README.md vendored Normal file
View File

@@ -0,0 +1,15 @@
Easy Toolset For JWT-Framework
===============================
This repository is a sub repository of [the JWT Framework](https://github.com/web-token/jwt-framework) project and is READ ONLY.
**Please do not submit any Pull Request here.**
You should go to [the main repository](https://github.com/web-token/jwt-framework) instead.
# Documentation
The official documentation is available as https://web-token.spomky-labs.com/
# Licence
This software is release under [MIT licence](LICENSE).

View File

@@ -0,0 +1,168 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy\Tests;
use BadFunctionCallException;
use function get_class;
use Jose\Component\Core\JWK;
use Jose\Component\Encryption\Algorithm\ContentEncryption;
use Jose\Component\Encryption\Algorithm\KeyEncryption;
use Jose\Component\Signature\Algorithm;
use Jose\Easy\AlgorithmProvider;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;
/**
* @group easy
*
* @internal
* @covers \Jose\Easy\AlgorithmProvider
*/
final class AlgorithmProviderTest extends TestCase
{
private const ALL_ALGORITHMS = [
Algorithm\HS256::class,
Algorithm\HS384::class,
Algorithm\HS512::class,
Algorithm\RS256::class,
Algorithm\RS384::class,
Algorithm\RS512::class,
Algorithm\PS256::class,
Algorithm\PS384::class,
Algorithm\PS512::class,
Algorithm\ES256::class,
Algorithm\ES384::class,
Algorithm\ES512::class,
Algorithm\EdDSA::class,
KeyEncryption\A128GCMKW::class,
KeyEncryption\A192GCMKW::class,
KeyEncryption\A256GCMKW::class,
KeyEncryption\A128KW::class,
KeyEncryption\A192KW::class,
KeyEncryption\A256KW::class,
KeyEncryption\Dir::class,
KeyEncryption\ECDHES::class,
KeyEncryption\ECDHESA128KW::class,
KeyEncryption\ECDHESA192KW::class,
KeyEncryption\ECDHESA256KW::class,
KeyEncryption\PBES2HS256A128KW::class,
KeyEncryption\PBES2HS384A192KW::class,
KeyEncryption\PBES2HS512A256KW::class,
KeyEncryption\RSA15::class,
KeyEncryption\RSAOAEP::class,
KeyEncryption\RSAOAEP256::class,
ContentEncryption\A128GCM::class,
ContentEncryption\A192GCM::class,
ContentEncryption\A256GCM::class,
ContentEncryption\A128CBCHS256::class,
ContentEncryption\A192CBCHS384::class,
ContentEncryption\A256CBCHS512::class,
];
/**
* @test
*
* @throws ExpectationFailedException
*/
public function itReturnsAllAlgorithmClasses(): void
{
$algorithmProvider = new AlgorithmProvider(self::ALL_ALGORITHMS);
static::assertSame(self::ALL_ALGORITHMS, $algorithmProvider->getAlgorithmClasses());
}
/**
* @test
*
* @throws Exception
* @throws ExpectationFailedException
*/
public function itReturnsTheAvailableAlgorithms(): void
{
$algorithmProvider = new AlgorithmProvider(self::ALL_ALGORITHMS);
foreach ($algorithmProvider->getAvailableAlgorithms() as $algorithm) {
static::assertContains(get_class($algorithm), self::ALL_ALGORITHMS);
}
}
/**
* @test
*
* @throws ExpectationFailedException
* @throws \Exception
*/
public function itAllowsNonExistingClasses(): void
{
$nonExistingClassName = 'NonExistingClass'.bin2hex(random_bytes(31));
$algorithmProvider = new AlgorithmProvider([$nonExistingClassName]);
static::assertSame([$nonExistingClassName], $algorithmProvider->getAlgorithmClasses());
static::assertSame([], $algorithmProvider->getAvailableAlgorithms());
}
/**
* @test
*
* @throws ExpectationFailedException
*/
public function itCanHandleClassesWithExceptions(): void
{
$test = [$this->createAlgorithmClassWithExceptionMock()];
$algorithmProvider = new AlgorithmProvider($test);
static::assertSame($test, $algorithmProvider->getAlgorithmClasses());
static::assertSame([], $algorithmProvider->getAvailableAlgorithms());
}
private function createAlgorithmClassWithExceptionMock(): string
{
$mockClass = new class() implements Algorithm\SignatureAlgorithm {
/** @var bool */
private static $throw;
public function __construct()
{
if (null === self::$throw) {
self::$throw = true;
return;
}
throw new BadFunctionCallException('should not be called');
}
public function name(): string
{
throw new BadFunctionCallException('should not be called');
}
public function allowedKeyTypes(): array
{
throw new BadFunctionCallException('should not be called');
}
public function sign(JWK $key, string $input): string
{
throw new BadFunctionCallException('should not be called');
}
public function verify(JWK $key, string $input, string $signature): bool
{
throw new BadFunctionCallException('should not be called');
}
};
return get_class($mockClass);
}
}

View File

@@ -0,0 +1,141 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy\Tests;
use Jose\Component\Core\JWK;
use Jose\Component\Encryption\Algorithm\ContentEncryption\A256CCM_16_128;
use Jose\Component\Encryption\Algorithm\KeyEncryption\RSAOAEP512;
use Jose\Easy\Build;
use Jose\Easy\Load;
use PHPUnit\Framework\TestCase;
/**
* @group easy
*
* @internal
* @covers \Jose\Easy\Build
* @covers \Jose\Easy\JWEBuilder
* @covers \Jose\Easy\JWT
*/
class EncryptionTest extends TestCase
{
/**
* @test
*/
public function jweCanBeCreated(): void
{
$time = time();
$jwe = Build::jwe()
->exp($time + 3600)
->iat($time)
->nbf($time)
->jti('0123456789', true)
->iss('issuer')
->aud('audience1')
->aud('audience2')
->sub('subject')
->alg('RSA-OAEP-256')
->enc('A256GCM')
->zip('DEF')
->claim('is_root', true)
->claim('roles', ['ROLE1' => true, 'ROLE2' => 0.007])
->crit(['alg', 'enc'])
->encrypt($this->rsaKey())
;
$jwt = Load::jwe($jwe)
->algs(['RSA-OAEP', 'RSA-OAEP-256'])
->encs(['A128GCM', 'A256GCM'])
->exp()
->iat()
->nbf()
->aud('audience1')
->iss('issuer')
->sub('subject')
->jti('0123456789')
->key($this->rsaKey())
->run()
;
static::assertEquals($time, $jwt->claims->iat());
static::assertEquals($time, $jwt->claims->nbf());
static::assertEquals($time + 3600, $jwt->claims->exp());
static::assertEquals('0123456789', $jwt->claims->jti());
static::assertEquals('issuer', $jwt->claims->iss());
static::assertEquals('subject', $jwt->claims->sub());
static::assertEquals(['audience1', 'audience2'], $jwt->claims->aud());
static::assertEquals(true, $jwt->claims->is_root());
static::assertEquals(['ROLE1' => true, 'ROLE2' => 0.007], $jwt->claims->roles());
static::assertEquals(['jti' => '0123456789', 'alg' => 'RSA-OAEP-256', 'enc' => 'A256GCM', 'crit' => ['alg', 'enc'], 'zip' => 'DEF'], $jwt->header->all());
static::assertEquals('RSA-OAEP-256', $jwt->header->alg());
static::assertEquals('A256GCM', $jwt->header->enc());
static::assertEquals('0123456789', $jwt->header->jti());
}
/**
* @test
*/
public function jweCanBeCreatedWithCustomAlgorithm(): void
{
$time = time();
$jwe = Build::jwe()
->exp($time + 3600)
->iat($time)
->nbf($time)
->jti('0123456789')
->alg(new RSAOAEP512())
->enc(new A256CCM_16_128())
->encrypt($this->rsaKey())
;
$jwt = Load::jwe($jwe)
->algs(['RSA-OAEP', new RSAOAEP512()])
->encs(['A128GCM', new A256CCM_16_128()])
->exp()
->iat()
->nbf()
->aud('audience1')
->iss('issuer')
->sub('subject')
->jti('0123456789')
->key($this->rsaKey())
->run()
;
static::assertEquals($time, $jwt->claims->iat());
static::assertEquals($time, $jwt->claims->nbf());
static::assertEquals($time + 3600, $jwt->claims->exp());
static::assertEquals('0123456789', $jwt->claims->jti());
static::assertEquals('RSA-OAEP-512', $jwt->header->alg());
static::assertEquals('A256CCM-16-128', $jwt->header->enc());
}
private function rsaKey(): JWK
{
return new JWK([
'kty' => 'RSA',
'kid' => 'bilbo.baggins@hobbiton.example',
'use' => 'enc',
'n' => 'n4EPtAOCc9AlkeQHPzHStgAbgs7bTZLwUBZdR8_KuKPEHLd4rHVTeT-O-XV2jRojdNhxJWTDvNd7nqQ0VEiZQHz_AJmSCpMaJMRBSFKrKb2wqVwGU_NsYOYL-QtiWN2lbzcEe6XC0dApr5ydQLrHqkHHig3RBordaZ6Aj-oBHqFEHYpPe7Tpe-OfVfHd1E6cS6M1FZcD1NNLYD5lFHpPI9bTwJlsde3uhGqC0ZCuEHg8lhzwOHrtIQbS0FVbb9k3-tVTU4fg_3L_vniUFAKwuCLqKnS2BYwdq_mzSnbLY7h_qixoR7jig3__kRhuaxwUkRz5iaiQkqgc5gHdrNP5zw',
'e' => 'AQAB',
'd' => 'bWUC9B-EFRIo8kpGfh0ZuyGPvMNKvYWNtB_ikiH9k20eT-O1q_I78eiZkpXxXQ0UTEs2LsNRS-8uJbvQ-A1irkwMSMkK1J3XTGgdrhCku9gRldY7sNA_AKZGh-Q661_42rINLRCe8W-nZ34ui_qOfkLnK9QWDDqpaIsA-bMwWWSDFu2MUBYwkHTMEzLYGqOe04noqeq1hExBTHBOBdkMXiuFhUq1BU6l-DqEiWxqg82sXt2h-LMnT3046AOYJoRioz75tSUQfGCshWTBnP5uDjd18kKhyv07lhfSJdrPdM5Plyl21hsFf4L_mHCuoFau7gdsPfHPxxjVOcOpBrQzwQ',
'p' => '3Slxg_DwTXJcb6095RoXygQCAZ5RnAvZlno1yhHtnUex_fp7AZ_9nRaO7HX_-SFfGQeutao2TDjDAWU4Vupk8rw9JR0AzZ0N2fvuIAmr_WCsmGpeNqQnev1T7IyEsnh8UMt-n5CafhkikzhEsrmndH6LxOrvRJlsPp6Zv8bUq0k',
'q' => 'uKE2dh-cTf6ERF4k4e_jy78GfPYUIaUyoSSJuBzp3Cubk3OCqs6grT8bR_cu0Dm1MZwWmtdqDyI95HrUeq3MP15vMMON8lHTeZu2lmKvwqW7anV5UzhM1iZ7z4yMkuUwFWoBvyY898EXvRD-hdqRxHlSqAZ192zB3pVFJ0s7pFc',
'dp' => 'B8PVvXkvJrj2L-GYQ7v3y9r6Kw5g9SahXBwsWUzp19TVlgI-YV85q1NIb1rxQtD-IsXXR3-TanevuRPRt5OBOdiMGQp8pbt26gljYfKU_E9xn-RULHz0-ed9E9gXLKD4VGngpz-PfQ_q29pk5xWHoJp009Qf1HvChixRX59ehik',
'dq' => 'CLDmDGduhylc9o7r84rEUVn7pzQ6PF83Y-iBZx5NT-TpnOZKF1pErAMVeKzFEl41DlHHqqBLSM0W1sOFbwTxYWZDm6sI6og5iTbwQGIC3gnJKbi_7k_vJgGHwHxgPaX2PnvP-zyEkDERuf-ry4c_Z11Cq9AqC2yeL6kdKT1cYF8',
'qi' => '3PiqvXQN0zwMeE-sBvZgi289XP9XCQF3VWqPzMKnIgQp7_Tugo6-NZBKCQsMf3HaEGBjTVJs_jcK8-TRXvaKe-7ZMaQj8VfBdYkssbu0NKDDhjJ-GtiseaDVWt7dcH0cfwxgFUHpQh7FoCrjFJ6h6ZEpMF6xmujs4qMpPz8aaI4',
]);
}
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy\Tests;
use Jose\Easy\ParameterBag;
use PHPUnit\Framework\TestCase;
/**
* @group easy
*
* @internal
* @covers \Jose\Easy\ParameterBag
*/
class ParameterBagTest extends TestCase
{
/**
* @test
*/
public function basicCalls(): void
{
$bag = new ParameterBag();
$bag->iss('iss');
$bag->alg('alg');
$bag->aud(['aud']);
static::assertEquals(['aud'], $bag->aud());
static::assertEquals('iss', $bag->get('iss'));
static::assertEquals('alg', $bag->get('alg'));
}
}

View File

@@ -0,0 +1,268 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy\Tests;
use Exception;
use InvalidArgumentException;
use Jose\Component\Checker\InvalidClaimException;
use Jose\Component\Core\JWK;
use Jose\Component\Signature\Algorithm\HS1;
use Jose\Easy\Build;
use Jose\Easy\Load;
use PHPUnit\Framework\TestCase;
/**
* @group easy
*
* @covers \Jose\Easy\Build
* @covers \Jose\Easy\JWSBuilder
* @covers \Jose\Easy\JWT
* @covers \Jose\Easy\Validate
*
* @internal
*/
class SignatureTest extends TestCase
{
/**
* @test
*/
public function jwsCanBeCreated(): void
{
$time = time();
$jws = Build::jws()
->exp($time + 3600)
->iat($time)
->nbf($time)
->jti('0123456789', true)
->alg('RS512')
->iss('issuer')
->aud('audience1')
->aud('audience2')
->sub('subject')
->claim('is_root', true)
->claim('roles', ['ROLE1' => true, 'ROLE2' => 0.007])
->crit(['alg'])
->sign($this->rsaKey())
;
$jwt = Load::jws($jws)
->algs(['RS256', 'RS512'])
->exp()
->iat()
->nbf()
->aud('audience1')
->iss('issuer')
->sub('subject')
->jti('0123456789')
->key($this->rsaKey())
->run()
;
static::assertEquals($time, $jwt->claims->iat());
static::assertEquals($time, $jwt->claims->nbf());
static::assertEquals($time + 3600, $jwt->claims->exp());
static::assertEquals('0123456789', $jwt->claims->jti());
static::assertEquals('issuer', $jwt->claims->iss());
static::assertEquals('subject', $jwt->claims->sub());
static::assertEquals(['audience1', 'audience2'], $jwt->claims->aud());
static::assertEquals(true, $jwt->claims->is_root());
static::assertEquals(['ROLE1' => true, 'ROLE2' => 0.007], $jwt->claims->roles());
static::assertEquals(['jti' => '0123456789', 'alg' => 'RS512', 'crit' => ['alg']], $jwt->header->all());
static::assertEquals('RS512', $jwt->header->alg());
static::assertEquals('0123456789', $jwt->header->jti());
}
/**
* @test
*/
public function invalidSignatureRejectsTheToken(): void
{
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid signature');
$time = time();
$jws = Build::jws()
->exp($time + 3600)
->iat($time)
->nbf($time)
->jti('0123456789', true)
->alg('HS256')
->iss('issuer')
->aud('audience1')
->aud('audience2')
->sub('subject')
->claim('is_root', true)
->claim('roles', ['ROLE1' => true, 'ROLE2' => 0.007])
->crit(['alg'])
->sign(new JWK(['kty' => 'oct', 'k' => 'foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo']))
;
Load::jws($jws)
->algs(['HS256'])
->exp()
->iat()
->nbf()
->aud('audience1')
->iss('issuer')
->sub('subject')
->jti('0123456789')
->key(new JWK(['kty' => 'oct', 'k' => 'BARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBAR']))
->run()
;
}
/**
* @test
*/
public function algorithmIsNotAllowed(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The algorithm "none" is not supported.');
$time = time();
$jws = Build::jws()
->exp($time + 3600)
->iat($time)
->nbf($time)
->jti('0123456789', true)
->alg('none')
->iss('issuer')
->aud('audience1')
->aud('audience2')
->sub('subject')
->claim('is_root', true)
->claim('roles', ['ROLE1' => true, 'ROLE2' => 0.007])
->crit(['alg'])
->sign($this->noneKey())
;
Load::jws($jws)
->algs(['HS256'])
->exp()
->iat()
->nbf()
->aud('audience1')
->iss('issuer')
->sub('subject')
->jti('0123456789')
->key(new JWK(['kty' => 'oct', 'k' => 'BARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBARBAR']))
->run()
;
}
/**
* @test
*/
public function tokenExpired(): void
{
$this->expectException(InvalidClaimException::class);
$this->expectExceptionMessage('The token expired.');
$time = time();
$jws = Build::jws()
->exp($time - 1)
->iat($time)
->nbf($time)
->jti('0123456789', true)
->alg('RS256')
->iss('issuer')
->aud('audience1')
->aud('audience2')
->sub('subject')
->claim('is_root', true)
->claim('roles', ['ROLE1' => true, 'ROLE2' => 0.007])
->crit(['alg'])
->sign($this->rsaKey())
;
Load::jws($jws)
->algs(['RS256'])
->exp()
->iat()
->nbf()
->aud('audience1')
->iss('issuer')
->sub('subject')
->jti('0123456789')
->key($this->rsaKey())
->run()
;
}
/**
* @test
*/
public function jwsCanBeCreatedWithCustomAlgorithm(): void
{
$time = time();
$jws = Build::jws()
->exp($time + 3600)
->iat($time)
->nbf($time)
->jti('0123456789')
->alg(new HS1())
->sign($this->octKey())
;
$jwt = Load::jws($jws)
->algs(['RS256', new HS1()])
->exp()
->iat()
->nbf()
->aud('audience1')
->iss('issuer')
->sub('subject')
->jti('0123456789')
->key($this->octKey())
->run()
;
static::assertEquals($time, $jwt->claims->iat());
static::assertEquals($time, $jwt->claims->nbf());
static::assertEquals($time + 3600, $jwt->claims->exp());
static::assertEquals('0123456789', $jwt->claims->jti());
static::assertEquals('HS1', $jwt->header->alg());
}
private function rsaKey(): JWK
{
return new JWK([
'kty' => 'RSA',
'kid' => 'bilbo.baggins@hobbiton.example',
'use' => 'sig',
'n' => 'n4EPtAOCc9AlkeQHPzHStgAbgs7bTZLwUBZdR8_KuKPEHLd4rHVTeT-O-XV2jRojdNhxJWTDvNd7nqQ0VEiZQHz_AJmSCpMaJMRBSFKrKb2wqVwGU_NsYOYL-QtiWN2lbzcEe6XC0dApr5ydQLrHqkHHig3RBordaZ6Aj-oBHqFEHYpPe7Tpe-OfVfHd1E6cS6M1FZcD1NNLYD5lFHpPI9bTwJlsde3uhGqC0ZCuEHg8lhzwOHrtIQbS0FVbb9k3-tVTU4fg_3L_vniUFAKwuCLqKnS2BYwdq_mzSnbLY7h_qixoR7jig3__kRhuaxwUkRz5iaiQkqgc5gHdrNP5zw',
'e' => 'AQAB',
'd' => 'bWUC9B-EFRIo8kpGfh0ZuyGPvMNKvYWNtB_ikiH9k20eT-O1q_I78eiZkpXxXQ0UTEs2LsNRS-8uJbvQ-A1irkwMSMkK1J3XTGgdrhCku9gRldY7sNA_AKZGh-Q661_42rINLRCe8W-nZ34ui_qOfkLnK9QWDDqpaIsA-bMwWWSDFu2MUBYwkHTMEzLYGqOe04noqeq1hExBTHBOBdkMXiuFhUq1BU6l-DqEiWxqg82sXt2h-LMnT3046AOYJoRioz75tSUQfGCshWTBnP5uDjd18kKhyv07lhfSJdrPdM5Plyl21hsFf4L_mHCuoFau7gdsPfHPxxjVOcOpBrQzwQ',
'p' => '3Slxg_DwTXJcb6095RoXygQCAZ5RnAvZlno1yhHtnUex_fp7AZ_9nRaO7HX_-SFfGQeutao2TDjDAWU4Vupk8rw9JR0AzZ0N2fvuIAmr_WCsmGpeNqQnev1T7IyEsnh8UMt-n5CafhkikzhEsrmndH6LxOrvRJlsPp6Zv8bUq0k',
'q' => 'uKE2dh-cTf6ERF4k4e_jy78GfPYUIaUyoSSJuBzp3Cubk3OCqs6grT8bR_cu0Dm1MZwWmtdqDyI95HrUeq3MP15vMMON8lHTeZu2lmKvwqW7anV5UzhM1iZ7z4yMkuUwFWoBvyY898EXvRD-hdqRxHlSqAZ192zB3pVFJ0s7pFc',
'dp' => 'B8PVvXkvJrj2L-GYQ7v3y9r6Kw5g9SahXBwsWUzp19TVlgI-YV85q1NIb1rxQtD-IsXXR3-TanevuRPRt5OBOdiMGQp8pbt26gljYfKU_E9xn-RULHz0-ed9E9gXLKD4VGngpz-PfQ_q29pk5xWHoJp009Qf1HvChixRX59ehik',
'dq' => 'CLDmDGduhylc9o7r84rEUVn7pzQ6PF83Y-iBZx5NT-TpnOZKF1pErAMVeKzFEl41DlHHqqBLSM0W1sOFbwTxYWZDm6sI6og5iTbwQGIC3gnJKbi_7k_vJgGHwHxgPaX2PnvP-zyEkDERuf-ry4c_Z11Cq9AqC2yeL6kdKT1cYF8',
'qi' => '3PiqvXQN0zwMeE-sBvZgi289XP9XCQF3VWqPzMKnIgQp7_Tugo6-NZBKCQsMf3HaEGBjTVJs_jcK8-TRXvaKe-7ZMaQj8VfBdYkssbu0NKDDhjJ-GtiseaDVWt7dcH0cfwxgFUHpQh7FoCrjFJ6h6ZEpMF6xmujs4qMpPz8aaI4',
]);
}
private function octKey(): JWK
{
return new JWK([
'kty' => 'oct',
'k' => 'foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo',
]);
}
private function noneKey(): JWK
{
return new JWK([
'kty' => 'none',
]);
}
}

75
vendor/web-token/jwt-easy/Validate.php vendored Normal file
View File

@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Easy;
use function count;
use Exception;
use Jose\Component\Checker;
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Core\Util\JsonConverter;
use Jose\Component\Signature\Algorithm;
use Jose\Component\Signature\JWSTokenSupport;
use Jose\Component\Signature\JWSVerifier;
use Jose\Component\Signature\Serializer\CompactSerializer;
class Validate extends AbstractLoader
{
public static function token(string $token): self
{
return new self($token);
}
public function run(): JWT
{
if (0 !== count($this->allowedAlgorithms)) {
$this->headerCheckers[] = new Checker\AlgorithmChecker($this->allowedAlgorithms, true);
}
$jws = (new CompactSerializer())->unserialize($this->token);
$headerChecker = new Checker\HeaderCheckerManager($this->headerCheckers, [new JWSTokenSupport()]);
$headerChecker->check($jws, 0);
$verifier = new JWSVerifier(new AlgorithmManager($this->algorithms));
if (!$verifier->verifyWithKeySet($jws, $this->jwkset, 0)) {
throw new Exception('Invalid signature');
}
$jwt = new JWT();
$jwt->header->replace($jws->getSignature(0)->getProtectedHeader());
$jwt->claims->replace(JsonConverter::decode($jws->getPayload()));
$claimChecker = new Checker\ClaimCheckerManager($this->claimCheckers);
$claimChecker->check($jwt->claims->all(), $this->mandatoryClaims);
return $jwt;
}
protected function getAlgorithmMap(): array
{
return [
Algorithm\HS256::class,
Algorithm\HS384::class,
Algorithm\HS512::class,
Algorithm\RS256::class,
Algorithm\RS384::class,
Algorithm\RS512::class,
Algorithm\PS256::class,
Algorithm\PS384::class,
Algorithm\PS512::class,
Algorithm\ES256::class,
Algorithm\ES384::class,
Algorithm\ES512::class,
Algorithm\EdDSA::class,
];
}
}

57
vendor/web-token/jwt-easy/composer.json vendored Normal file
View File

@@ -0,0 +1,57 @@
{
"name": "web-token/jwt-easy",
"description": "Easy toolset to use the JWT Framework.",
"type": "library",
"license": "MIT",
"keywords": ["JWS", "JWT", "JWE", "JWA", "JWK", "JWKSet", "Jot", "Jose", "RFC7515", "RFC7516", "RFC7517", "RFC7518", "RFC7519", "RFC7520", "Bundle", "Symfony"],
"homepage": "https://github.com/web-token",
"authors": [
{
"name": "Florent Morselli",
"homepage": "https://github.com/Spomky"
},{
"name": "All contributors",
"homepage": "https://github.com/web-token/jwt-framework/contributors"
}
],
"autoload": {
"psr-4": {
"Jose\\Easy\\": ""
}
},
"require": {
"web-token/jwt-encryption": "^2.1",
"web-token/jwt-signature": "^2.1",
"web-token/jwt-checker": "^2.1"
},
"suggest": {
"web-token/jwt-encryption-algorithm-aescbc": "Adds AES-CBC based encryption algorithms",
"web-token/jwt-encryption-algorithm-aesgcm": "Adds AES-GCM based encryption algorithms",
"web-token/jwt-encryption-algorithm-aesgcmkw": "Adds AES-GCM Key Wrapping based encryption algorithms",
"web-token/jwt-encryption-algorithm-aeskw": "Adds AES Key Wrapping based encryption algorithms",
"web-token/jwt-encryption-algorithm-dir": "Adds Direct encryption algorithm",
"web-token/jwt-encryption-algorithm-ecdh-es": "Adds ECDH-ES based encryption algorithms",
"web-token/jwt-encryption-algorithm-pbes2": "Adds PBES2 based encryption algorithms",
"web-token/jwt-encryption-algorithm-rsa": "Adds RSA based encryption algorithms",
"web-token/jwt-signature-algorithm-ecdsa": "Adds ECDSA based signature algorithms",
"web-token/jwt-signature-algorithm-eddsa": "Adds EdDSA based signature algorithms",
"web-token/jwt-signature-algorithm-none": "Adds none signature algorithms",
"web-token/jwt-signature-algorithm-hmac": "Adds HMAC based signature algorithms",
"web-token/jwt-signature-algorithm-rsa": "Adds RSA based signature algorithms"
},
"require-dev": {
"phpunit/phpunit": "^8.0"
},
"extra": {
"branch-alias": {
"v1.0": "1.0.x-dev",
"v1.1": "1.1.x-dev",
"v1.2": "1.2.x-dev",
"v1.3": "1.3.x-dev",
"v2.0": "2.0.x-dev"
}
},
"config": {
"sort-packages": true
}
}

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./</directory>
<exclude>
<directory>./vendor</directory>
<directory>./Tests</directory>
<directory suffix="Test.php">./src</directory>
</exclude>
</whitelist>
</filter>
</phpunit>