···
use chillerlan\OAuth\Core\OAuth2Interface;
use chillerlan\OAuth\Core\OAuth2Provider;
9
-
use chillerlan\OAuth\Core\PARTrait;
use chillerlan\OAuth\Core\PKCETrait;
use chillerlan\OAuth\OAuthOptions;
use chillerlan\OAuth\Storage\SessionStorage;
···
use GuzzleHttp\Psr7\HttpFactory;
class BskyProvider extends OAuth2Provider implements \chillerlan\OAuth\Core\PAR, \chillerlan\OAuth\Core\PKCE {
17
-
use \chillerlan\OAuth\Core\PARTrait;
use \chillerlan\OAuth\Core\PKCETrait;
public const IDENTIFIER = 'BSKYPROVIDER';
···
$this->parAuthorizationURL = (string)$pds->withPath('/oauth/par');
55
+
public function getParRequestUri(array $body):UriInterface{
56
+
// send the request with the same method and parameters as the token requests
57
+
// @link https://datatracker.ietf.org/doc/html/rfc9126#name-request
58
+
$response = $this->sendAccessTokenRequest($this->parAuthorizationURL, $body);
59
+
$status = $response->getStatusCode();
60
+
$json = MessageUtil::decodeJSON($response, true);
62
+
// something went horribly wrong
63
+
if($status !== 201){
65
+
// @link https://datatracker.ietf.org/doc/html/rfc9126#section-2.3
66
+
if(isset($json['error'], $json['error_description'])){
67
+
throw new ProviderException(sprintf('PAR error: "%s" (%s)', $json['error'], $json['error_description']));
70
+
throw new ProviderException(sprintf('PAR request error: (HTTP/%s)', $status)); // @codeCoverageIgnore
73
+
$url = QueryUtil::merge($this->authorizationURL, $this->getParAuthorizationURLRequestParams($json));
75
+
return $this->uriFactory->createUri($url);
78
+
protected function getParAuthorizationURLRequestParams(array $response):array{
80
+
if(!isset($response['request_uri'])){
81
+
throw new ProviderException('PAR response error: "request_uri" missing');
85
+
'client_id' => $this->options->key,
86
+
'request_uri' => $response['request_uri'],