diff --git a/Provider.php b/Provider.php index df646fd..f154554 100644 --- a/Provider.php +++ b/Provider.php @@ -14,7 +14,11 @@ class Provider extends AbstractProvider /** * {@inheritdoc} */ - protected $scopes = ['users', 'pledges-to-me', 'my-campaign']; + protected $scopes = [ + 'campaigns', + 'identity', + 'identity[email]', + ]; /** * {@inherticdoc}. @@ -26,10 +30,7 @@ class Provider extends AbstractProvider */ protected function getAuthUrl($state) { - return $this->buildAuthUrlFromBase( - 'https://www.patreon.com/oauth2/authorize', - $state - ); + return $this->buildAuthUrlFromBase('https://www.patreon.com/oauth2/authorize', $state); } /** @@ -45,15 +46,15 @@ protected function getTokenUrl() */ protected function getUserByToken($token) { - $response = $this->getHttpClient()->get( - 'https://api.patreon.com/oauth2/api/current_user', - [ - RequestOptions::HEADERS => [ - 'Accept' => 'application/json', - 'Authorization' => 'Bearer '.$token, - ], - ] - ); + $response = $this->getHttpClient()->get('https://api.patreon.com/api/oauth2/v2/identity', [ + RequestOptions::HEADERS => [ + 'Accept' => 'application/json', + 'Authorization' => 'Bearer '.$token, + ], + RequestOptions::QUERY => [ + 'fields[user]' => 'email,full_name,image_url,vanity', + ], + ]); return json_decode((string) $response->getBody(), true); } @@ -63,21 +64,15 @@ protected function getUserByToken($token) */ protected function mapUserToObject(array $user) { - return (new User())->setRaw($user)->map([ - 'id' => $user['data']['id'], - 'nickname' => Arr::get($user['data']['attributes'], 'vanity', $user['data']['attributes']['full_name']), - 'name' => $user['data']['attributes']['full_name'], 'email' => $user['data']['attributes']['email'], - 'avatar' => $user['data']['attributes']['image_url'], - ]); - } + $userData = $user['data']; + $userAttributes = $userData['attributes']; - /** - * {@inheritdoc} - */ - protected function getTokenFields($code) - { - return array_merge(parent::getTokenFields($code), [ - 'grant_type' => 'authorization_code', + return (new User())->setRaw($user)->map([ + 'id' => $userData['id'], + 'nickname' => Arr::get($userAttributes, 'vanity', $userAttributes['full_name']), + 'name' => $userAttributes['full_name'], + 'email' => $userAttributes['email'], + 'avatar' => $userAttributes['image_url'], ]); } } diff --git a/composer.json b/composer.json index 4088001..01f9010 100644 --- a/composer.json +++ b/composer.json @@ -21,9 +21,9 @@ "docs": "https://socialiteproviders.com/patreon" }, "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "ext-json": "*", - "socialiteproviders/manager": "~4.0" + "socialiteproviders/manager": "^4.2" }, "autoload": { "psr-4": {