generated from Setono/SyliusPluginSkeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It works. On with state, nonce and token validation
- Loading branch information
Showing
12 changed files
with
162 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusAgeVerificationPlugin\Token; | ||
|
||
final class DecodedToken | ||
{ | ||
public function __construct( | ||
public string $iss, | ||
public string $aud, | ||
public string $nonce, | ||
/** @var array{country: string, is_over_15?: bool, is_over_16?: bool, is_over_18?: bool, is_over_21?: bool} $ageVerification */ | ||
public array $ageVerification, | ||
) { | ||
} | ||
|
||
/** | ||
* Returns the age this user is over or null if the user is not over any age | ||
*/ | ||
public function olderThan(): ?int | ||
{ | ||
return match (true) { | ||
$this->ageVerification['is_over_21'] ?? null === true => 21, | ||
$this->ageVerification['is_over_18'] ?? null === true => 18, | ||
$this->ageVerification['is_over_16'] ?? null === true => 16, | ||
$this->ageVerification['is_over_15'] ?? null === true => 15, | ||
default => null, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusAgeVerificationPlugin\Token; | ||
|
||
use CuyZ\Valinor\MapperBuilder; | ||
use Firebase\JWT\JWK; | ||
use Firebase\JWT\JWT; | ||
use Setono\SyliusAgeVerificationPlugin\OpenIdConfiguration\OpenIdConfiguration; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class TokenDecoder implements TokenDecoderInterface | ||
{ | ||
public function decode(string $token, OpenIdConfiguration $openIdConfiguration): DecodedToken | ||
{ | ||
$data = (array) JWT::decode($token, JWK::parseKeySet($openIdConfiguration->keys, 'RS256')); | ||
Assert::keyExists($data, 'http://ageverification.criipto.com'); | ||
$data['ageVerification'] = (array) $data['http://ageverification.criipto.com']; | ||
|
||
return (new MapperBuilder()) | ||
->allowSuperfluousKeys() | ||
->mapper() | ||
->map(DecodedToken::class, $data) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusAgeVerificationPlugin\Token; | ||
|
||
use Setono\SyliusAgeVerificationPlugin\OpenIdConfiguration\OpenIdConfiguration; | ||
|
||
interface TokenDecoderInterface | ||
{ | ||
public function decode(string $token, OpenIdConfiguration $openIdConfiguration): DecodedToken; | ||
} |