Skip to content

Commit 3372103

Browse files
committed
fix: add headers to token
1 parent 0df3486 commit 3372103

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/SSOTokenGenerator.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ class SSOTokenGenerator
3636
*
3737
* @return string Encoded token.
3838
*/
39-
public static function createSignedTokenFromData(string $privateKey, array $tokenData, Signer $signer = null): string
39+
public static function createSignedTokenFromData(string $privateKey, array $tokenData, Signer $signer = null, array $headers = []): string
4040
{
4141

4242
$config = Configuration::forSymmetricSigner($signer ?: new Sha256(), InMemory::plainText($privateKey));
43-
return self::buildToken($config, $tokenData)->toString();
43+
return self::buildToken($config, $tokenData, $headers)->toString();
4444
}
4545

4646
/**
4747
* @param Configuration $config
4848
* @param array $tokenData
4949
* @return Token
5050
*/
51-
private static function buildToken(Configuration $config, array $tokenData): Token
51+
private static function buildToken(Configuration $config, array $tokenData, array $headers = []): Token
5252
{
5353
$builder = $config->builder();
5454
$token = $builder
@@ -72,12 +72,16 @@ private static function buildToken(Configuration $config, array $tokenData): Tok
7272
// Remove all set keys as they throw an exception when used with withClaim
7373
$claims = array_filter(
7474
$tokenData,
75-
fn ($key) => !in_array($key, RegisteredClaims::ALL),
75+
static fn ($key) => !in_array($key, RegisteredClaims::ALL),
7676
ARRAY_FILTER_USE_KEY
7777
);
7878

7979
foreach ($claims as $claim => $value) {
80-
$token = $token->withClaim($claim, $value);
80+
$token = $token->withClaim($claim, $value);
81+
}
82+
83+
foreach ($headers as $header => $value) {
84+
$token = $token->withHeader($header, $value);
8185
}
8286

8387
return $token->getToken($config->signer(), $config->signingKey());

0 commit comments

Comments
 (0)