Skip to content

Commit da5191d

Browse files
committed
Making the issuer configurable.
So far, the issuer was generated using `'https://' . $_SERVER['HTTP_HOST']`. While this value is fine most of the time, it can cause trouble in: - development environments (where the protocol is `http://`) - long-lived PHP environments (like Swoole, ReactPHP...) where `$_SERVER['HTTP_HOST']` might not exist I'm trying here to make the issuer configurable.
1 parent cd4b1e4 commit da5191d

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/IdTokenResponse.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ class IdTokenResponse extends BearerTokenResponse
2121
protected ClaimExtractor $claimExtractor;
2222

2323
private Configuration $config;
24+
private ?string $issuer;
2425

2526
public function __construct(
2627
IdentityRepositoryInterface $identityRepository,
2728
ClaimExtractor $claimExtractor,
28-
Configuration $config
29+
Configuration $config,
30+
string $issuer = null,
2931
) {
3032
$this->identityRepository = $identityRepository;
3133
$this->claimExtractor = $claimExtractor;
3234
$this->config = $config;
35+
$this->issuer = $issuer;
3336
}
3437

3538
protected function getBuilder(
@@ -41,7 +44,7 @@ protected function getBuilder(
4144
return $this->config
4245
->builder()
4346
->permittedFor($accessToken->getClient()->getIdentifier())
44-
->issuedBy('https://' . $_SERVER['HTTP_HOST'])
47+
->issuedBy($this->issuer ?? 'https://' . $_SERVER['HTTP_HOST'])
4548
->issuedAt($dateTimeImmutableObject)
4649
->expiresAt($dateTimeImmutableObject->add(new DateInterval('PT1H')))
4750
->relatedTo($userEntity->getIdentifier());

src/Laravel/PassportServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function makeAuthorizationServer(): AuthorizationServer
5555
app(config('openid.signer')),
5656
InMemory::file($cryptKey->getKeyPath()),
5757
),
58+
app('request')->getSchemeAndHttpHost(),
5859
);
5960

6061
return new AuthorizationServer(

tests/Factories/IdTokenResponseFactory.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,30 @@ private function build(
1616
IdentityRepositoryInterface $identityRepository,
1717
ClaimExtractor $claimExtractor,
1818
?Configuration $config = null,
19+
?string $issuer = null,
1920
): BearerTokenResponse {
2021
return new IdTokenResponse(
2122
$identityRepository,
2223
$claimExtractor,
2324
$config ?? ConfigutationFactory::default(),
25+
$issuer,
2426
);
2527
}
2628

2729
public static function default(
2830
IdentityRepositoryInterface $identityRepository,
2931
ClaimExtractor $claimExtractor,
32+
?string $issuer = null,
3033
): BearerTokenResponse {
31-
return (new static())->build($identityRepository, $claimExtractor);
34+
return (new static())->build($identityRepository, $claimExtractor, null, $issuer);
3235
}
3336

3437
public static function withConfig(
3538
IdentityRepositoryInterface $identityRepository,
3639
ClaimExtractor $claimExtractor,
37-
Configuration $config
40+
Configuration $config,
41+
?string $issuer = null,
3842
): BearerTokenResponse {
39-
return (new static())->build($identityRepository, $claimExtractor, $config);
43+
return (new static())->build($identityRepository, $claimExtractor, $config, $issuer);
4044
}
4145
}

0 commit comments

Comments
 (0)