friendship ended with social-app. php is my new best friend
1<?php 2/** 3 * Class WordPress 4 * 5 * @created 26.10.2017 6 * @author Smiley <smiley@chillerlan.net> 7 * @copyright 2017 Smiley 8 * @license MIT 9 * 10 * @noinspection PhpUnused 11 */ 12declare(strict_types=1); 13 14namespace chillerlan\OAuth\Providers; 15 16use chillerlan\OAuth\Core\{AuthenticatedUser, CSRFToken, OAuth2Provider, UserInfo}; 17 18/** 19 * WordPress OAuth2 20 * 21 * @link https://developer.wordpress.com/docs/oauth2/ 22 */ 23class WordPress extends OAuth2Provider implements CSRFToken, UserInfo{ 24 25 public const IDENTIFIER = 'WORDPRESS'; 26 27 public const SCOPE_AUTH = 'auth'; 28 public const SCOPE_GLOBAL = 'global'; 29 30 public const DEFAULT_SCOPES = [ 31 self::SCOPE_GLOBAL, 32 ]; 33 34 protected string $authorizationURL = 'https://public-api.wordpress.com/oauth2/authorize'; 35 protected string $accessTokenURL = 'https://public-api.wordpress.com/oauth2/token'; 36 protected string $apiURL = 'https://public-api.wordpress.com/rest'; 37 protected string|null $userRevokeURL = 'https://wordpress.com/me/security/connected-applications'; 38 protected string|null $apiDocs = 'https://developer.wordpress.com/docs/api/'; 39 protected string|null $applicationURL = 'https://developer.wordpress.com/apps/'; 40 41 /** @codeCoverageIgnore */ 42 public function me():AuthenticatedUser{ 43 $json = $this->getMeResponseData('/v1/me'); 44 45 $userdata = [ 46 'data' => $json, 47 'avatar' => $json['avatar_URL'], 48 'handle' => $json['username'], 49 'displayName' => $json['display_name'], 50 'email' => $json['email'], 51 'id' => $json['ID'], 52 'url' => $json['profile_URL'], 53 ]; 54 55 return new AuthenticatedUser($userdata); 56 } 57 58}