Skip to content

Commit

Permalink
feat: add isEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
keenthekeen committed Sep 14, 2022
1 parent adc95f0 commit 82fe5a4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/VestaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateTimeImmutable;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Response;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Configuration as JwtConfiguration;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Signer\Key\InMemory;
Expand All @@ -22,7 +23,12 @@ public function __construct()
$this->jwtConfig = JwtConfiguration::forSymmetricSigner(new Sha256(), InMemory::plainText(config('vesta-client.secret')));
}

protected function getJwtBuilder(string $expireTime = '+2 hour'): \Lcobucci\JWT\Builder
public function isEnabled(): bool
{
return (bool) config('vesta-client.secret');
}

protected function getJwtBuilder(?string $expireTime = '+2 hour'): Builder
{
$now = new DateTimeImmutable();

Expand All @@ -31,7 +37,7 @@ protected function getJwtBuilder(string $expireTime = '+2 hour'): \Lcobucci\JWT\
->permittedFor('Vesta')
->issuedAt($now)
->canOnlyBeUsedAfter($now->modify('-1 minute'))
->expiresAt($now->modify($expireTime));
->expiresAt($now->modify($expireTime ?? '+2 hour'));
}

public function generateApiIdToken(?string $email, array $targets, array $fields, ?string $expireTime = null): string
Expand Down

0 comments on commit 82fe5a4

Please sign in to comment.