friendship ended with social-app. php is my new best friend
1<?php 2/** 3 * Class Foursquare 4 * 5 * @created 10.08.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, OAuth2Provider, UserInfo}; 15use Psr\Http\Message\{ResponseInterface, StreamInterface}; 16use function array_merge, sprintf; 17 18/** 19 * Foursquare OAuth2 20 * 21 * @link https://location.foursquare.com/developer/reference/personalization-apis-authentication 22 */ 23class Foursquare extends OAuth2Provider implements UserInfo{ 24 25 public const IDENTIFIER = 'FOURSQUARE'; 26 27 public const AUTH_METHOD = self::AUTH_METHOD_QUERY; 28 public const AUTH_PREFIX_QUERY = 'oauth_token'; 29 30 protected const API_VERSIONDATE = '20190225'; 31 protected const QUERY_PARAMS = ['m' => 'foursquare', 'v' => self::API_VERSIONDATE]; 32 33 protected string $authorizationURL = 'https://foursquare.com/oauth2/authenticate'; 34 protected string $accessTokenURL = 'https://foursquare.com/oauth2/access_token'; 35 protected string $apiURL = 'https://api.foursquare.com'; 36 protected string|null $userRevokeURL = 'https://foursquare.com/settings/connections'; 37 protected string|null $apiDocs = 'https://location.foursquare.com/developer/reference/foursquare-apis-overview'; 38 protected string|null $applicationURL = 'https://foursquare.com/developers/apps'; 39 40 /** @codeCoverageIgnore */ 41 public function request( 42 string $path, 43 array|null $params = null, 44 string|null $method = null, 45 StreamInterface|array|string|null $body = null, 46 array|null $headers = null, 47 string|null $protocolVersion = null, 48 ):ResponseInterface{ 49 $params = array_merge(($params ?? []), $this::QUERY_PARAMS); 50 51 return parent::request($path, $params, $method, $body, $headers, $protocolVersion); 52 } 53 54 /** @codeCoverageIgnore */ 55 public function me():AuthenticatedUser{ 56 $json = $this->getMeResponseData('/v2/users/self', $this::QUERY_PARAMS); 57 $user = $json['response']['user']; 58 59 $userdata = [ 60 'data' => $json, 61 'avatar' => sprintf('%s%s%s', $user['photo']['prefix'], $user['id'], $user['photo']['suffix']), 62 'displayName' => $user['firstName'], 63 'email' => $user['contact']['email'], 64 'id' => $user['id'], 65 'handle' => $user['handle'], 66 'url' => $user['canonicalUrl'], 67 ]; 68 69 return new AuthenticatedUser($userdata); 70 } 71 72}