From f73a5587dc33ac051644800c5a3060be818e597e Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 28 Nov 2020 19:02:37 +0000 Subject: [PATCH] No longer need our own token exception --- app/Exceptions/InvalidTokenException.php | 13 -------- app/Http/Controllers/MicropubController.php | 2 -- .../Controllers/MicropubMediaController.php | 1 - app/Services/TokenService.php | 1 - tests/Feature/TokenServiceTest.php | 31 ++++++++++--------- 5 files changed, 17 insertions(+), 31 deletions(-) delete mode 100644 app/Exceptions/InvalidTokenException.php diff --git a/app/Exceptions/InvalidTokenException.php b/app/Exceptions/InvalidTokenException.php deleted file mode 100644 index 8184cfa7..00000000 --- a/app/Exceptions/InvalidTokenException.php +++ /dev/null @@ -1,13 +0,0 @@ -expectException(InvalidTokenException::class); - $this->expectExceptionMessage('Token failed validation'); + $this->expectException(RequiredConstraintsViolated::class); $data = [ 'me' => 'https://example.org', 'client_id' => 'https://quill.p3k.io', 'scope' => 'post' ]; - $signer = new Sha256(); - $token = (new Builder())->set('me', $data['me']) - ->set('client_id', $data['client_id']) - ->set('scope', $data['scope']) - ->set('date_issued', time()) - ->set('nonce', bin2hex(random_bytes(8))) - ->sign($signer, 'r4ndomk3y') - ->getToken(); + + $config = resolve(Configuration::class); + + $token = $config->builder() + ->issuedAt(new DateTimeImmutable()) + ->withClaim('client_id', $data['client_id']) + ->withClaim('me', $data['me']) + ->withClaim('scope', $data['scope']) + ->withClaim('nonce', bin2hex(random_bytes(8))) + ->getToken($config->signer(), InMemory::plainText('r4andomk3y')) + ->toString(); $service = new TokenService(); - $token = $service->validateToken($token); + $service->validateToken($token); } }