friendship ended with social-app. php is my new best friend

write own PARTrait lol

Changed files
+35 -2
lib
+35 -2
lib/bskyProvider.php
···
use chillerlan\OAuth\Core\OAuth2Interface;
use chillerlan\OAuth\Core\OAuth2Provider;
-
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 {
-
use \chillerlan\OAuth\Core\PARTrait;
use \chillerlan\OAuth\Core\PKCETrait;
public const IDENTIFIER = 'BSKYPROVIDER';
···
$this->parAuthorizationURL = (string)$pds->withPath('/oauth/par');
return $this;
}
}
?>
···
use chillerlan\OAuth\Core\OAuth2Interface;
use chillerlan\OAuth\Core\OAuth2Provider;
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 {
use \chillerlan\OAuth\Core\PKCETrait;
public const IDENTIFIER = 'BSKYPROVIDER';
···
$this->parAuthorizationURL = (string)$pds->withPath('/oauth/par');
return $this;
+
}
+
+
public function getParRequestUri(array $body):UriInterface{
+
// send the request with the same method and parameters as the token requests
+
// @link https://datatracker.ietf.org/doc/html/rfc9126#name-request
+
$response = $this->sendAccessTokenRequest($this->parAuthorizationURL, $body);
+
$status = $response->getStatusCode();
+
$json = MessageUtil::decodeJSON($response, true);
+
+
// something went horribly wrong
+
if($status !== 201){
+
+
// @link https://datatracker.ietf.org/doc/html/rfc9126#section-2.3
+
if(isset($json['error'], $json['error_description'])){
+
throw new ProviderException(sprintf('PAR error: "%s" (%s)', $json['error'], $json['error_description']));
+
}
+
+
throw new ProviderException(sprintf('PAR request error: (HTTP/%s)', $status)); // @codeCoverageIgnore
+
}
+
+
$url = QueryUtil::merge($this->authorizationURL, $this->getParAuthorizationURLRequestParams($json));
+
+
return $this->uriFactory->createUri($url);
+
}
+
+
protected function getParAuthorizationURLRequestParams(array $response):array{
+
+
if(!isset($response['request_uri'])){
+
throw new ProviderException('PAR response error: "request_uri" missing');
+
}
+
+
return [
+
'client_id' => $this->options->key,
+
'request_uri' => $response['request_uri'],
+
];
}
}
?>