Skip to content
Open
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
14 changes: 10 additions & 4 deletions src/Apple/AppleToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,29 @@
class AppleToken
{
private Configuration $jwtConfig;
private string $teamId;
private string $clientId;
private string $keyId;

public function __construct(Configuration $jwtConfig)
public function __construct(Configuration $jwtConfig, ?string $teamId = null, ?string $clientId = null, ?string $keyId = null)
{
$this->jwtConfig = $jwtConfig;
$this->teamId = $teamId ?? config('services.apple.team_id');
$this->clientId = $clientId ?? config('services.apple.client_id');
$this->keyId = $keyId ?? config('services.apple.key_id');
}

public function generate(): string
{
$now = CarbonImmutable::now();

$token = $this->jwtConfig->builder()
->issuedBy(config('services.apple.team_id'))
->issuedBy($this->teamId)
->issuedAt($now)
->expiresAt($now->addHour())
->permittedFor(Provider::URL)
->relatedTo(config('services.apple.client_id'))
->withHeader('kid', config('services.apple.key_id'))
->relatedTo($this->clientId)
->withHeader('kid', $this->keyId)
->getToken($this->jwtConfig->signer(), $this->jwtConfig->signingKey());

return $token->toString();
Expand Down
4 changes: 2 additions & 2 deletions src/Apple/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function getJwtConfig()
);

if (!empty($this->privateKey)) {
$appleToken = new AppleToken($this->getJwtConfig());
$appleToken = new AppleToken($this->getJwtConfig(), $this->getConfig('team_id', ''), $this->clientId, $this->getConfig('key_id', ''));
$this->clientSecret = $appleToken->generate();
config()->set('services.apple.client_secret', $this->clientSecret);
}
Expand Down Expand Up @@ -365,6 +365,6 @@ public function refreshToken($refreshToken): ResponseInterface
*/
public static function additionalConfigKeys()
{
return ['private_key', 'passphrase', 'signer'];
return ['private_key', 'passphrase', 'signer', 'team_id', 'key_id'];
}
}
Loading