| @@ 9-43 (lines=35) @@ | ||
| 6 | use Emarref\Jwt\Exception\InvalidIssuerException; |
|
| 7 | use Emarref\Jwt\Token; |
|
| 8 | ||
| 9 | class IssuerVerifier implements VerifierInterface |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var string |
|
| 13 | */ |
|
| 14 | private $issuer; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @param string $issuer |
|
| 18 | */ |
|
| 19 | public function __construct($issuer = null) |
|
| 20 | { |
|
| 21 | if (null !== $issuer && !is_string($issuer)) { |
|
| 22 | throw new \InvalidArgumentException('Cannot verify invalid issuer value.'); |
|
| 23 | } |
|
| 24 | ||
| 25 | $this->issuer = $issuer; |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * @param Token $token |
|
| 30 | * @throws InvalidIssuerException |
|
| 31 | */ |
|
| 32 | public function verify(Token $token) |
|
| 33 | { |
|
| 34 | /** @var Claim\Issuer $issuerClaim */ |
|
| 35 | $issuerClaim = $token->getPayload()->findClaimByName(Claim\Issuer::NAME); |
|
| 36 | ||
| 37 | $issuer = (null === $issuerClaim) ? null : $issuerClaim->getValue(); |
|
| 38 | ||
| 39 | if ($this->issuer !== $issuer) { |
|
| 40 | throw new InvalidIssuerException; |
|
| 41 | } |
|
| 42 | } |
|
| 43 | } |
|
| 44 | ||
| @@ 9-43 (lines=35) @@ | ||
| 6 | use Emarref\Jwt\Exception\InvalidSubjectException; |
|
| 7 | use Emarref\Jwt\Token; |
|
| 8 | ||
| 9 | class SubjectVerifier implements VerifierInterface |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var string |
|
| 13 | */ |
|
| 14 | private $subject; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @param string $subject |
|
| 18 | */ |
|
| 19 | public function __construct($subject = null) |
|
| 20 | { |
|
| 21 | if (null !== $subject && !is_string($subject)) { |
|
| 22 | throw new \InvalidArgumentException('Cannot verify invalid subject value.'); |
|
| 23 | } |
|
| 24 | ||
| 25 | $this->subject = $subject; |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * @param Token $token |
|
| 30 | * @throws InvalidSubjectException |
|
| 31 | */ |
|
| 32 | public function verify(Token $token) |
|
| 33 | { |
|
| 34 | /** @var Claim\Subject $subjectClaim */ |
|
| 35 | $subjectClaim = $token->getPayload()->findClaimByName(Claim\Subject::NAME); |
|
| 36 | ||
| 37 | $subject = (null === $subjectClaim) ? null : $subjectClaim->getValue(); |
|
| 38 | ||
| 39 | if ($this->subject !== $subject) { |
|
| 40 | throw new InvalidSubjectException; |
|
| 41 | } |
|
| 42 | } |
|
| 43 | } |
|
| 44 | ||