Generate keys pair if they aren't exists

This commit is contained in:
ErickSkrauch
2019-08-02 19:16:34 +03:00
parent 967d8b11a0
commit 6ad66b28cf
3 changed files with 26 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ use Exception;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Parser;
use Lcobucci\JWT\Token;
use Webmozart\Assert\Assert;
use yii\base\Component as BaseComponent;
class Component extends BaseComponent {
@@ -39,6 +40,13 @@ class Component extends BaseComponent {
*/
private $algorithmManager;
public function init(): void {
parent::init();
Assert::notEmpty($this->hmacKey, 'hmacKey must be set');
Assert::notEmpty($this->privateKeyPath, 'privateKeyPath must be set');
Assert::notEmpty($this->publicKeyPath, 'publicKeyPath must be set');
}
public function create(array $payloads = [], array $headers = []): Token {
$now = Carbon::now();
$builder = (new Builder())