friendship ended with social-app. php is my new best friend
1<?php 2/** 3 * Class Google 4 * 5 * @created 09.08.2018 6 * @author smiley <smiley@chillerlan.net> 7 * @copyright 2018 smiley 8 * @license MIT 9 * 10 * @noinspection PhpUnused 11 */ 12declare(strict_types=1); 13 14namespace chillerlan\OAuth\Providers; 15 16use chillerlan\OAuth\Core\{ 17 AuthenticatedUser, CSRFToken, OAuth2Provider, PKCE, PKCETrait, TokenInvalidate, TokenInvalidateTrait, UserInfo, 18}; 19 20/** 21 * Google OAuth2 22 * 23 * @link https://developers.google.com/identity/protocols/oauth2/web-server 24 * @link https://developers.google.com/identity/protocols/oauth2/service-account 25 * @link https://developers.google.com/oauthplayground/ 26 */ 27class Google extends OAuth2Provider implements CSRFToken, PKCE, TokenInvalidate, UserInfo{ 28 use PKCETrait, TokenInvalidateTrait; 29 30 public const IDENTIFIER = 'GOOGLE'; 31 32 public const SCOPE_EMAIL = 'email'; 33 public const SCOPE_PROFILE = 'profile'; 34 public const SCOPE_USERINFO_EMAIL = 'https://www.googleapis.com/auth/userinfo.email'; 35 public const SCOPE_USERINFO_PROFILE = 'https://www.googleapis.com/auth/userinfo.profile'; 36 37 public const DEFAULT_SCOPES = [ 38 self::SCOPE_EMAIL, 39 self::SCOPE_PROFILE, 40 ]; 41 42 protected string $authorizationURL = 'https://accounts.google.com/o/oauth2/auth'; 43 protected string $accessTokenURL = 'https://oauth2.googleapis.com/token'; 44 protected string $revokeURL = 'https://oauth2.googleapis.com/revoke'; 45 protected string $apiURL = 'https://www.googleapis.com'; 46 protected string|null $userRevokeURL = 'https://myaccount.google.com/connections'; 47 protected string|null $apiDocs = 'https://developers.google.com/oauthplayground/'; 48 protected string|null $applicationURL = 'https://console.developers.google.com/apis/credentials'; 49 50 /** @codeCoverageIgnore */ 51 public function me():AuthenticatedUser{ 52 $json = $this->getMeResponseData('/userinfo/v2/me'); 53 54 $userdata = [ 55 'data' => $json, 56 'avatar' => $json['picture'], 57 'displayName' => $json['name'], 58 'email' => $json['email'], 59 'id' => $json['id'], 60 ]; 61 62 return new AuthenticatedUser($userdata); 63 } 64 65}