Skip to content

Commit

Permalink
Merge pull request #15 from moufmouf/configurable-iss
Browse files Browse the repository at this point in the history
Making the issuer configurable.
  • Loading branch information
ronvanderheijden authored Apr 19, 2024
2 parents cd4b1e4 + da5191d commit 81f3d70
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/IdTokenResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ class IdTokenResponse extends BearerTokenResponse
protected ClaimExtractor $claimExtractor;

private Configuration $config;
private ?string $issuer;

public function __construct(
IdentityRepositoryInterface $identityRepository,
ClaimExtractor $claimExtractor,
Configuration $config
Configuration $config,
string $issuer = null,
) {
$this->identityRepository = $identityRepository;
$this->claimExtractor = $claimExtractor;
$this->config = $config;
$this->issuer = $issuer;
}

protected function getBuilder(
Expand All @@ -41,7 +44,7 @@ protected function getBuilder(
return $this->config
->builder()
->permittedFor($accessToken->getClient()->getIdentifier())
->issuedBy('https://' . $_SERVER['HTTP_HOST'])
->issuedBy($this->issuer ?? 'https://' . $_SERVER['HTTP_HOST'])
->issuedAt($dateTimeImmutableObject)
->expiresAt($dateTimeImmutableObject->add(new DateInterval('PT1H')))
->relatedTo($userEntity->getIdentifier());
Expand Down
1 change: 1 addition & 0 deletions src/Laravel/PassportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function makeAuthorizationServer(): AuthorizationServer
app(config('openid.signer')),
InMemory::file($cryptKey->getKeyPath()),
),
app('request')->getSchemeAndHttpHost(),
);

return new AuthorizationServer(
Expand Down
10 changes: 7 additions & 3 deletions tests/Factories/IdTokenResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,30 @@ private function build(
IdentityRepositoryInterface $identityRepository,
ClaimExtractor $claimExtractor,
?Configuration $config = null,
?string $issuer = null,
): BearerTokenResponse {
return new IdTokenResponse(
$identityRepository,
$claimExtractor,
$config ?? ConfigutationFactory::default(),
$issuer,
);
}

public static function default(
IdentityRepositoryInterface $identityRepository,
ClaimExtractor $claimExtractor,
?string $issuer = null,
): BearerTokenResponse {
return (new static())->build($identityRepository, $claimExtractor);
return (new static())->build($identityRepository, $claimExtractor, null, $issuer);
}

public static function withConfig(
IdentityRepositoryInterface $identityRepository,
ClaimExtractor $claimExtractor,
Configuration $config
Configuration $config,
?string $issuer = null,
): BearerTokenResponse {
return (new static())->build($identityRepository, $claimExtractor, $config);
return (new static())->build($identityRepository, $claimExtractor, $config, $issuer);
}
}

0 comments on commit 81f3d70

Please sign in to comment.