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/oauth2/authorize';
26 protected string $accessTokenURL = 'https://bsky.app/oauth2/token';
27 protected string $apiURL = 'https://bsky.app/api';
28
29 public const DEFAULT_SCOPES = [
30 self::SCOPE_ATPROTO,
31 self::SCOPE_TRANSITION_GENERIC,
32 ];
33
34 public function setPds(UriInterface|string $pds):static{
35 if(!$pds instanceof UriInterface){
36 $pds = $this->uriFactory->createUri($pds);
37 }
38
39 // throw if the host is empty
40 if($pds->getHost() === ''){
41 throw new OAuthException('invalid PDS URL');
42 }
43
44 // enforce https and remove unnecessary parts
45 $pds = $pds->withScheme('https')->withQuery('')->withFragment('');
46
47 // set the provider URLs
48 $this->authorizationURL = (string)$pds->withPath('/oauth/authorize');
49 $this->accessTokenURL = (string)$pds->withPath('/oauth/token');
50 $this->apiURL = (string)$pds->withPath('/api');
51
52 return $this;
53 }
54}
55?>