Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/release.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash

set -e
if (( "$#" == 0 ))
then
Expand Down
14 changes: 10 additions & 4 deletions src/Jwt/AbstractJwt.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,32 @@ public function __construct(
private readonly RefreshTokenConstraint $refreshTokenConstraint
) {}

public function builderRefreshToken(string $sub): UnencryptedToken
public function builderRefreshToken(string $sub, ?\Closure $callable = null): UnencryptedToken
{
return $this->getJwtFacade()->issue(
$this->getSigner(),
$this->getSigningKey(),
function (Builder $builder, \DateTimeImmutable $immutable) use ($sub) {
function (Builder $builder, \DateTimeImmutable $immutable) use ($sub, $callable) {
$builder = $builder->identifiedBy($sub);
$builder = $builder->expiresAt($this->getRefreshExpireAt($immutable));
if ($callable !== null) {
$builder = $callable($builder);
}
return $builder->relatedTo('refresh');
}
);
}

public function builderAccessToken(string $sub): UnencryptedToken
public function builderAccessToken(string $sub, ?\Closure $callable = null): UnencryptedToken
{
return $this->getJwtFacade()->issue(
$this->getSigner(),
$this->getSigningKey(),
function (Builder $builder, \DateTimeImmutable $immutable) use ($sub) {
function (Builder $builder, \DateTimeImmutable $immutable) use ($sub, $callable) {
$builder = $builder->identifiedBy($sub);
if ($callable !== null) {
$builder = $callable($builder);
}
return $builder->expiresAt($this->getExpireAt($immutable));
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/Jwt/JwtInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

interface JwtInterface
{
public function builderAccessToken(string $sub): UnencryptedToken;
public function builderAccessToken(string $sub, ?\Closure $callable = null): UnencryptedToken;

public function builderRefreshToken(string $sub): UnencryptedToken;
public function builderRefreshToken(string $sub, ?\Closure $callable = null): UnencryptedToken;

public function parserAccessToken(string $accessToken): UnencryptedToken;

Expand Down
Loading