This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Storable and Rotatable JWKSet added * Tests added * Documentation updated
- Loading branch information
Showing
19 changed files
with
704 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2016 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace Jose\Object; | ||
|
||
use Assert\Assertion; | ||
|
||
/** | ||
* Class RotatableJWK. | ||
*/ | ||
final class RotatableJWK extends StorableJWK implements RotatableJWKInterface | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
protected $ttl; | ||
|
||
public function __construct($filename, array $parameters, $ttl) | ||
{ | ||
Assertion::integer($ttl); | ||
Assertion::greaterThan($ttl, 0, 'The parameter TTL must be at least 0.'); | ||
$this->ttl = $ttl; | ||
parent::__construct($filename, $parameters); | ||
} | ||
|
||
/** | ||
* @return \Jose\Object\JWKInterface | ||
*/ | ||
protected function getJWK() | ||
{ | ||
if (file_exists($this->getFilename())) { | ||
$mtime = filemtime($this->getFilename()); | ||
if ($mtime + $this->ttl <= time()) { | ||
unlink($this->getFilename()); | ||
} | ||
} | ||
|
||
return parent::getJWK(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2016 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace Jose\Object; | ||
|
||
/** | ||
* Interface RotatableJWKInterface. | ||
*/ | ||
interface RotatableJWKInterface extends StorableJWKInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2016 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace Jose\Object; | ||
|
||
use Assert\Assertion; | ||
|
||
/** | ||
* Class RotatableJWKSet. | ||
*/ | ||
final class RotatableJWKSet extends StorableJWKSet implements RotatableJWKSetInterface | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
protected $ttl; | ||
|
||
/** | ||
* RotatableJWKSet constructor. | ||
* | ||
* @param string $filename | ||
* @param array $parameters | ||
* @param int $nb_keys | ||
* @param int $ttl | ||
*/ | ||
public function __construct($filename, array $parameters, $nb_keys, $ttl) | ||
{ | ||
Assertion::integer($ttl); | ||
Assertion::greaterThan($ttl, 0, 'The parameter TTL must be at least 0.'); | ||
$this->ttl = $ttl; | ||
parent::__construct($filename, $parameters, $nb_keys); | ||
} | ||
|
||
/** | ||
* @return \Jose\Object\JWKSetInterface | ||
*/ | ||
protected function getJWKSet() | ||
{ | ||
$mtime = $this->getLastModificationTime(); | ||
if (null !== $mtime) { | ||
if ($mtime + $this->ttl <= time()) { | ||
$keys = $this->jwkset->getKeys(); | ||
unset($keys[count($keys) - 1]); | ||
$this->jwkset = new JWKSet(); | ||
$this->jwkset->addKey($this->createJWK()); | ||
foreach ($keys as $key) { | ||
$this->jwkset->addKey($key); | ||
} | ||
$this->save(); | ||
} | ||
} | ||
|
||
return parent::getJWKSet(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2016 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace Jose\Object; | ||
|
||
/** | ||
* Interface RotatableJWKSetInterface. | ||
*/ | ||
interface RotatableJWKSetInterface extends StorableJWKSetInterface | ||
{ | ||
} |
Oops, something went wrong.