friendship ended with social-app. php is my new best friend
1<?php 2/** 3 * Class Twitter 4 * 5 * @created 08.04.2018 6 * @author Smiley <smiley@chillerlan.net> 7 * @copyright 2018 Smiley 8 * @license MIT 9 */ 10declare(strict_types=1); 11 12namespace chillerlan\OAuth\Providers; 13 14use chillerlan\OAuth\Core\{AuthenticatedUser, OAuth1Provider, UserInfo}; 15use function sprintf, str_replace; 16 17/** 18 * Twitter OAuth1 19 * 20 * @todo: twitter is dead. fuck elon musk. 21 * 22 * @link https://developer.twitter.com/en/docs/basics/authentication/overview/oauth 23 */ 24class Twitter extends OAuth1Provider implements UserInfo{ 25 26 public const IDENTIFIER = 'TWITTER'; 27 28 // choose your fighter 29 /** @link https://developer.twitter.com/en/docs/basics/authentication/api-reference/authorize */ 30 protected string $authorizationURL = 'https://api.twitter.com/oauth/authorize'; 31 /** @link https://developer.twitter.com/en/docs/basics/authentication/api-reference/authenticate */ 32# protected string $authorizationURL = 'https://api.twitter.com/oauth/authenticate'; 33 34 protected string $requestTokenURL = 'https://api.twitter.com/oauth/request_token'; 35 protected string $accessTokenURL = 'https://api.twitter.com/oauth/access_token'; 36 protected string $apiURL = 'https://api.twitter.com'; 37 protected string|null $userRevokeURL = 'https://twitter.com/settings/applications'; 38 protected string|null $apiDocs = 'https://developer.twitter.com/docs'; 39 protected string|null $applicationURL = 'https://developer.twitter.com/apps'; 40 41 /** @codeCoverageIgnore */ 42 public function me():AuthenticatedUser{ 43 $json = $this->getMeResponseData('/1.1/account/verify_credentials.json'); 44 45 $userdata = [ 46 'data' => $json, 47 'avatar' => str_replace('_normal', '_400x400', $json['profile_image_url_https']), 48 'handle' => $json['screen_name'], 49 'displayName' => $json['name'], 50 'id' => $json['id'], 51 'url' => sprintf('https://twitter.com/%s', $json['screen_name']), 52 ]; 53 54 return new AuthenticatedUser($userdata); 55 } 56 57}