This commit is contained in:
2025-10-20 14:10:54 +02:00
parent 75ca8fd840
commit d2c1970ef8
732 changed files with 101915 additions and 2 deletions

View File

@@ -0,0 +1,103 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Token;
use Pshowsso\Scope68f5e85e9608b\Firebase\JWT\JWT;
use Pshowsso\Scope68f5e85e9608b\Firebase\JWT\Key;
use InvalidArgumentException;
class AppleAccessToken extends AccessToken
{
/**
* @var string
*/
protected $idToken;
/**
* @var string
*/
protected $email;
/**
* @var boolean
*/
protected $isPrivateEmail;
/**
* Constructs an access token.
*
* @param Key[] $keys Valid Apple JWT keys
* @param array $options An array of options returned by the service provider
* in the access token request. The `access_token` option is required.
* @throws InvalidArgumentException if `access_token` is not provided in `$options`.
*
* @throws \Exception
*/
public function __construct(array $keys, array $options = [])
{
if (array_key_exists('refresh_token', $options)) {
if (empty($options['id_token'])) {
throw new InvalidArgumentException('Required option not passed: "id_token"');
}
$decoded = null;
$last = end($keys);
foreach ($keys as $key) {
try {
try {
$decoded = JWT::decode($options['id_token'], $key);
} catch (\UnexpectedValueException $e) {
$decodeMethodReflection = new \ReflectionMethod(JWT::class, 'decode');
$decodeMethodParameters = $decodeMethodReflection->getParameters();
// Backwards compatibility for firebase/php-jwt >=5.2.0 <=5.5.1 supported by PHP 5.6
if (array_key_exists(2, $decodeMethodParameters) && 'allowed_algs' === $decodeMethodParameters[2]->getName()) {
$decoded = JWT::decode($options['id_token'], $key, ['RS256']);
} else {
$headers = (object) ['alg' => 'RS256'];
$decoded = JWT::decode($options['id_token'], $key, $headers);
}
}
break;
} catch (\Exception $exception) {
if ($last === $key) {
throw $exception;
}
}
}
if (null === $decoded) {
throw new \Exception('Got no data within "id_token"!');
}
$payload = json_decode(json_encode($decoded), \true);
$options['resource_owner_id'] = $payload['sub'];
if (isset($payload['email_verified']) && $payload['email_verified']) {
$options['email'] = $payload['email'];
}
if (isset($payload['is_private_email'])) {
$this->isPrivateEmail = $payload['is_private_email'];
}
}
parent::__construct($options);
if (isset($options['id_token'])) {
$this->idToken = $options['id_token'];
}
if (isset($options['email'])) {
$this->email = $options['email'];
}
}
/**
* @return string
*/
public function getIdToken()
{
return $this->idToken;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @return boolean
*/
public function isPrivateEmail()
{
return $this->isPrivateEmail;
}
}