friendship ended with social-app. php is my new best friend
1<?php
2namespace Smallnest\Bsky;
3
4require_once('config.php');
5require_once('vendor/autoload.php');
6
7use chillerlan\OAuth\Core\OAuth2Interface;
8use chillerlan\OAuth\Core\OAuth2Provider;
9use chillerlan\OAuth\Core\PARTrait;
10use chillerlan\OAuth\Core\PKCETrait;
11use chillerlan\OAuth\OAuthOptions;
12use chillerlan\OAuth\Storage\SessionStorage;
13use GuzzleHttp\Client;
14use GuzzleHttp\Psr7\HttpFactory;
15
16class BskyProvider extends OAuth2Provider implements \chillerlan\OAuth\Core\PAR, \chillerlan\OAuth\Core\PKCE {
17 use \chillerlan\OAuth\Core\PARTrait;
18 use \chillerlan\OAuth\Core\PKCETrait;
19
20 public const IDENTIFIER = 'BSKYPROVIDER';
21 public const SCOPE_ATPROTO = 'atproto';
22 public const SCOPE_TRANSITION_GENERIC = 'transition:generic';
23 public const AUTH_METHOD = self::AUTH_METHOD_HEADER;
24
25 protected string $authorizationURL = 'https://bsky.app/oauth/authorize';
26 protected string $accessTokenURL = 'https://bsky.app/oauth/token';
27 protected string $apiURL = 'https://bsky.app/xrpc';
28 protected string $parAuthorizationURL = 'https://bsky.app/oauth/par';
29
30 public const DEFAULT_SCOPES = [
31 self::SCOPE_ATPROTO,
32 self::SCOPE_TRANSITION_GENERIC,
33 ];
34
35 public function setPds(UriInterface|string $pds):static{
36 if(!$pds instanceof UriInterface){
37 $pds = $this->uriFactory->createUri($pds);
38 }
39
40 // throw if the host is empty
41 if($pds->getHost() === ''){
42 throw new OAuthException('invalid PDS URL');
43 }
44
45 // enforce https and remove unnecessary parts
46 $pds = $pds->withScheme('https')->withQuery('')->withFragment('');
47
48 // set the provider URLs
49 $this->authorizationURL = (string)$pds->withPath('/oauth/authorize');
50 $this->accessTokenURL = (string)$pds->withPath('/oauth/token');
51 $this->apiURL = (string)$pds->withPath('/xrpc');
52 $this->parAuthorizationURL = (string)$pds->withPath('/oauth/par');
53
54 return $this;
55 }
56}
57?>