2017-09-19 16:07:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests;
|
|
|
|
|
2020-11-28 18:21:29 +00:00
|
|
|
use DateTimeImmutable;
|
|
|
|
use Lcobucci\JWT\Configuration;
|
2017-09-19 16:07:32 +01:00
|
|
|
|
|
|
|
trait TestToken
|
|
|
|
{
|
2023-02-18 09:34:57 +00:00
|
|
|
public function getToken(): string
|
2017-09-19 16:07:32 +01:00
|
|
|
{
|
2020-11-28 18:21:29 +00:00
|
|
|
$config = $this->app->make(Configuration::class);
|
|
|
|
|
|
|
|
return $config->builder()
|
2024-10-25 20:40:52 +01:00
|
|
|
->issuedAt(new DateTimeImmutable)
|
2020-11-28 18:21:29 +00:00
|
|
|
->withClaim('client_id', 'https://quill.p3k.io')
|
2024-07-13 14:52:57 +01:00
|
|
|
->withClaim('me', 'http://jonnybarnes.localhost')
|
|
|
|
->withClaim('scope', ['create', 'update'])
|
2020-11-28 18:21:29 +00:00
|
|
|
->getToken($config->signer(), $config->signingKey())
|
|
|
|
->toString();
|
2017-09-19 16:07:32 +01:00
|
|
|
}
|
|
|
|
|
2023-02-18 09:34:57 +00:00
|
|
|
public function getTokenWithIncorrectScope(): string
|
2017-09-19 16:07:32 +01:00
|
|
|
{
|
2020-11-28 18:21:29 +00:00
|
|
|
$config = $this->app->make(Configuration::class);
|
|
|
|
|
|
|
|
return $config->builder()
|
2024-10-25 20:40:52 +01:00
|
|
|
->issuedAt(new DateTimeImmutable)
|
2020-11-28 18:21:29 +00:00
|
|
|
->withClaim('client_id', 'https://quill.p3k.io')
|
|
|
|
->withClaim('me', 'https://jonnybarnes.localhost')
|
|
|
|
->withClaim('scope', 'view')
|
|
|
|
->getToken($config->signer(), $config->signingKey())
|
|
|
|
->toString();
|
2017-09-19 16:07:32 +01:00
|
|
|
}
|
2017-12-18 15:51:02 +00:00
|
|
|
|
|
|
|
public function getTokenWithNoScope()
|
|
|
|
{
|
2020-11-28 18:21:29 +00:00
|
|
|
$config = $this->app->make(Configuration::class);
|
|
|
|
|
|
|
|
return $config->builder()
|
2024-10-25 20:40:52 +01:00
|
|
|
->issuedAt(new DateTimeImmutable)
|
2020-11-28 18:21:29 +00:00
|
|
|
->withClaim('client_id', 'https://quill.p3k.io')
|
|
|
|
->withClaim('me', 'https://jonnybarnes.localhost')
|
|
|
|
->getToken($config->signer(), $config->signingKey())
|
|
|
|
->toString();
|
2017-12-18 15:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getInvalidToken()
|
|
|
|
{
|
|
|
|
$token = $this->getToken();
|
|
|
|
|
|
|
|
return substr($token, 0, -5);
|
|
|
|
}
|
2017-09-19 16:07:32 +01:00
|
|
|
}
|