|
17 | 17 |
|
18 | 18 | use function array_key_exists;
|
19 | 19 | use function current;
|
20 |
| -use function implode; |
21 | 20 | use function in_array;
|
22 | 21 | use function is_array;
|
23 | 22 | use function trigger_error;
|
@@ -494,19 +493,21 @@ public function getToken(Signer $signer = null, Key $key = null)
|
494 | 493 | $signer->modifyHeader($this->headers);
|
495 | 494 | }
|
496 | 495 |
|
497 |
| - $payload = [ |
498 |
| - $this->encoder->base64UrlEncode($this->encoder->jsonEncode($this->convertItems($this->headers))), |
499 |
| - $this->encoder->base64UrlEncode($this->encoder->jsonEncode($this->convertItems($this->claims))) |
500 |
| - ]; |
| 496 | + $headers = new DataSet( |
| 497 | + $this->headers, |
| 498 | + $this->encoder->base64UrlEncode($this->encoder->jsonEncode($this->convertItems($this->headers))) |
| 499 | + ); |
501 | 500 |
|
502 |
| - $signature = $this->createSignature($payload, $signer, $key); |
503 |
| - $payload[] = $signature->toString(); |
| 501 | + $claims = new DataSet( |
| 502 | + $this->claims, |
| 503 | + $this->encoder->base64UrlEncode($this->encoder->jsonEncode($this->convertItems($this->claims))) |
| 504 | + ); |
504 | 505 |
|
505 | 506 | return new Token(
|
506 |
| - new DataSet($this->headers, $payload[0]), |
507 |
| - new DataSet($this->claims, $payload[1]), |
508 |
| - $signature, |
509 |
| - $payload, |
| 507 | + $headers, |
| 508 | + $claims, |
| 509 | + $this->createSignature($headers->toString() . '.' . $claims->toString(), $signer, $key), |
| 510 | + ['', ''], |
510 | 511 | $this->claimFactory
|
511 | 512 | );
|
512 | 513 | }
|
@@ -534,17 +535,17 @@ private function convertItems(array $items)
|
534 | 535 | }
|
535 | 536 |
|
536 | 537 | /**
|
537 |
| - * @param string[] $payload |
| 538 | + * @param string $payload |
538 | 539 | *
|
539 | 540 | * @return Signature
|
540 | 541 | */
|
541 |
| - private function createSignature(array $payload, Signer $signer = null, Key $key = null) |
| 542 | + private function createSignature($payload, Signer $signer = null, Key $key = null) |
542 | 543 | {
|
543 | 544 | if ($signer === null || $key === null) {
|
544 | 545 | return Signature::fromEmptyData();
|
545 | 546 | }
|
546 | 547 |
|
547 |
| - $hash = $signer->sign(implode('.', $payload), $key)->hash(); |
| 548 | + $hash = $signer->sign($payload, $key)->hash(); |
548 | 549 |
|
549 | 550 | return new Signature($hash, $this->encoder->base64UrlEncode($hash));
|
550 | 551 | }
|
|
0 commit comments