From 34e286e146a43e093273996ed71e5ad918f9b2b8 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 18 Apr 2023 10:50:15 +0200 Subject: [PATCH 01/13] Fix test --- tests/LinkedInProviderTest.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/LinkedInProviderTest.php b/tests/LinkedInProviderTest.php index c67f78e8..8f92ac75 100644 --- a/tests/LinkedInProviderTest.php +++ b/tests/LinkedInProviderTest.php @@ -10,6 +10,7 @@ use Mockery as m; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; class LinkedInProviderTest extends TestCase { @@ -25,15 +26,24 @@ public function test_it_can_map_a_user_without_an_email_address() $request = m::mock(Request::class); $request->allows('input')->with('code')->andReturns('fake-code'); + $stream = m::mock(StreamInterface::class); + $stream->allows('__toString')->andReturns(json_encode(['access_token' => 'fake-token'])); + $accessTokenResponse = m::mock(ResponseInterface::class); - $accessTokenResponse->allows('getBody')->andReturns(json_encode(['access_token' => 'fake-token'])); + $accessTokenResponse->allows('getBody')->andReturns($stream); + + $basicProfileStream = m::mock(StreamInterface::class); + $basicProfileStream->allows('__toString')->andReturns(json_encode(['id' => $userId = 1])); $basicProfileResponse = m::mock(ResponseInterface::class); - $basicProfileResponse->allows('getBody')->andReturns(json_encode(['id' => $userId = 1])); + $basicProfileResponse->allows('getBody')->andReturns($basicProfileStream); + + $emailAddressStream = m::mock(StreamInterface::class); + $emailAddressStream->allows('__toString')->andReturns(json_encode(['elements' => []])); // Make sure email address response contains no values. $emailAddressResponse = m::mock(ResponseInterface::class); - $emailAddressResponse->allows('getBody')->andReturns(json_encode(['elements' => []])); + $emailAddressResponse->allows('getBody')->andReturns($emailAddressStream); $guzzle = m::mock(Client::class); $guzzle->expects('post')->andReturns($accessTokenResponse); From 8789ccb422c0aa2c9b2d36aeb0b544f5c9c59586 Mon Sep 17 00:00:00 2001 From: Alex Prokopenko Date: Mon, 29 May 2023 17:51:54 +0300 Subject: [PATCH 02/13] Fix config object override with container (#639) --- src/SocialiteManager.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SocialiteManager.php b/src/SocialiteManager.php index 6042d7f8..60384064 100644 --- a/src/SocialiteManager.php +++ b/src/SocialiteManager.php @@ -222,6 +222,7 @@ public function setContainer($container) { $this->app = $container; $this->container = $container; + $this->config = $container->make('config'); return $this; } From eb861db577ff0a6aa94345acd3cc3e6a05ee861c Mon Sep 17 00:00:00 2001 From: driesvints Date: Tue, 30 May 2023 14:51:18 +0000 Subject: [PATCH 03/13] Update CHANGELOG --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4475c32a..94166d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Release Notes -## [Unreleased](https://github.com/laravel/socialite/compare/v5.6.1...5.x) +## [Unreleased](https://github.com/laravel/socialite/compare/v5.6.2...5.x) + +## [v5.6.2](https://github.com/laravel/socialite/compare/v5.6.1...v5.6.2) - 2023-05-29 + +- Fix unable to use updated config object when using Laravel Octane by @aprokopenko in https://github.com/laravel/socialite/pull/639 ## [v5.6.1](https://github.com/laravel/socialite/compare/v5.6.0...v5.6.1) - 2023-01-20 From 27e0375343e8ab7ede8a7d346e091f2b842fb8e1 Mon Sep 17 00:00:00 2001 From: AL EMRAN Date: Tue, 6 Jun 2023 19:42:23 +0600 Subject: [PATCH 04/13] add buildProvider method on DockBlock for IDE support (#643) * add buildProvider on DockBlock for IDE support * Update Socialite.php --- src/Facades/Socialite.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Facades/Socialite.php b/src/Facades/Socialite.php index d0611459..80b4780d 100644 --- a/src/Facades/Socialite.php +++ b/src/Facades/Socialite.php @@ -7,7 +7,8 @@ /** * @method static \Laravel\Socialite\Contracts\Provider driver(string $driver = null) - * + * @method static \Laravel\Socialite\Two\AbstractProvider buildProvider($provider, $config) + * * @see \Laravel\Socialite\SocialiteManager */ class Socialite extends Facade From 00ea7f8630673ea49304fc8a9fca5a64eb838c7e Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 6 Jun 2023 13:42:43 +0000 Subject: [PATCH 05/13] Apply fixes from StyleCI --- src/Facades/Socialite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Facades/Socialite.php b/src/Facades/Socialite.php index 80b4780d..8b98118f 100644 --- a/src/Facades/Socialite.php +++ b/src/Facades/Socialite.php @@ -8,7 +8,7 @@ /** * @method static \Laravel\Socialite\Contracts\Provider driver(string $driver = null) * @method static \Laravel\Socialite\Two\AbstractProvider buildProvider($provider, $config) - * + * * @see \Laravel\Socialite\SocialiteManager */ class Socialite extends Facade From e9a18f0d477d0d25da133db819cc2738f5a06135 Mon Sep 17 00:00:00 2001 From: driesvints Date: Tue, 6 Jun 2023 14:59:43 +0000 Subject: [PATCH 06/13] Update CHANGELOG --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94166d8b..26cf1cd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Release Notes -## [Unreleased](https://github.com/laravel/socialite/compare/v5.6.2...5.x) +## [Unreleased](https://github.com/laravel/socialite/compare/v5.6.3...5.x) + +## [v5.6.3](https://github.com/laravel/socialite/compare/v5.6.2...v5.6.3) - 2023-06-06 + +- Add buildProvider method on DockBlock for IDE support by @emrancu in https://github.com/laravel/socialite/pull/643 ## [v5.6.2](https://github.com/laravel/socialite/compare/v5.6.1...v5.6.2) - 2023-05-29 From f5996f499e14db15407201a6bfbaba3ce6ce736c Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sat, 8 Jul 2023 21:51:43 +0100 Subject: [PATCH 07/13] Add support for Slack driver (#644) --- src/SocialiteManager.php | 15 ++++++++++ src/Two/SlackProvider.php | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/Two/SlackProvider.php diff --git a/src/SocialiteManager.php b/src/SocialiteManager.php index 60384064..0fd9b8e8 100644 --- a/src/SocialiteManager.php +++ b/src/SocialiteManager.php @@ -13,6 +13,7 @@ use Laravel\Socialite\Two\GitlabProvider; use Laravel\Socialite\Two\GoogleProvider; use Laravel\Socialite\Two\LinkedInProvider; +use Laravel\Socialite\Two\SlackProvider; use Laravel\Socialite\Two\TwitterProvider as TwitterOAuth2Provider; use League\OAuth1\Client\Server\Twitter as TwitterServer; @@ -154,6 +155,20 @@ protected function createTwitterOAuth2Driver() ); } + /** + * Create an instance of the specified driver. + * + * @return \Laravel\Socialite\Two\AbstractProvider + */ + protected function createSlackDriver() + { + $config = $this->config->get('services.slack'); + + return $this->buildProvider( + SlackProvider::class, $config + ); + } + /** * Build an OAuth 2 provider instance. * diff --git a/src/Two/SlackProvider.php b/src/Two/SlackProvider.php new file mode 100644 index 00000000..07825513 --- /dev/null +++ b/src/Two/SlackProvider.php @@ -0,0 +1,58 @@ +buildAuthUrlFromBase('https://slack.com/oauth/authorize', $state); + } + + /** + * {@inheritdoc} + */ + protected function getTokenUrl() + { + return 'https://slack.com/api/oauth.access'; + } + + /** + * {@inheritdoc} + */ + protected function getUserByToken($token) + { + $response = $this->getHttpClient()->get('https://slack.com/api/users.identity', [ + RequestOptions::HEADERS => ['Authorization' => 'Bearer '.$token], + ]); + + return json_decode($response->getBody(), true); + } + + /** + * {@inheritdoc} + */ + protected function mapUserToObject(array $user) + { + return (new User)->setRaw($user)->map([ + 'id' => Arr::get($user, 'user.id'), + 'name' => Arr::get($user, 'user.name'), + 'email' => Arr::get($user, 'user.email'), + 'avatar' => Arr::get($user, 'user.image_512'), + 'organization_id' => Arr::get($user, 'team.id'), + ]); + } +} From 851c8225e7c90800c0419b9c4ec660ee59fdf8ef Mon Sep 17 00:00:00 2001 From: driesvints Date: Tue, 11 Jul 2023 15:05:58 +0000 Subject: [PATCH 08/13] Update CHANGELOG --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26cf1cd9..b438462c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Release Notes -## [Unreleased](https://github.com/laravel/socialite/compare/v5.6.3...5.x) +## [Unreleased](https://github.com/laravel/socialite/compare/v5.7.0...5.x) + +## [v5.7.0](https://github.com/laravel/socialite/compare/v5.6.3...v5.7.0) - 2023-07-08 + +- Add support for Slack driver by [@jbrooksuk](https://github.com/jbrooksuk) in https://github.com/laravel/socialite/pull/644 ## [v5.6.3](https://github.com/laravel/socialite/compare/v5.6.2...v5.6.3) - 2023-06-06 From 50148edf24b6cd3e428aa9bc06a5d915b24376bb Mon Sep 17 00:00:00 2001 From: James Brooks Date: Fri, 14 Jul 2023 15:22:58 +0100 Subject: [PATCH 09/13] Update Slack provider to use v2 API and allow Bot tokens (#645) * Update Slack driver to use v2 API and allow Bot tokens * Update SlackProvider.php --------- Co-authored-by: Taylor Otwell --- src/Two/SlackProvider.php | 57 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/Two/SlackProvider.php b/src/Two/SlackProvider.php index 07825513..299f794c 100644 --- a/src/Two/SlackProvider.php +++ b/src/Two/SlackProvider.php @@ -14,12 +14,31 @@ class SlackProvider extends AbstractProvider */ protected $scopes = ['identity.basic', 'identity.email', 'identity.team', 'identity.avatar']; + /** + * The key used for scopes. + * + * @var string + */ + protected $scopeKey = 'user_scope'; + + /** + * Indicate that the requested token should be for a bot user. + * + * @return $this + */ + public function asBotUser() + { + $this->scopeKey = 'scope'; + + return $this; + } + /** * {@inheritdoc} */ public function getAuthUrl($state) { - return $this->buildAuthUrlFromBase('https://slack.com/oauth/authorize', $state); + return $this->buildAuthUrlFromBase('https://slack.com/oauth/v2/authorize', $state); } /** @@ -27,7 +46,7 @@ public function getAuthUrl($state) */ protected function getTokenUrl() { - return 'https://slack.com/api/oauth.access'; + return 'https://slack.com/api/oauth.v2.access'; } /** @@ -55,4 +74,38 @@ protected function mapUserToObject(array $user) 'organization_id' => Arr::get($user, 'team.id'), ]); } + + /** + * {@inheritdoc} + */ + protected function getCodeFields($state = null) + { + $fields = parent::getCodeFields($state); + + if ($this->scopeKey === 'user_scope') { + $fields['scope'] = ''; + $fields['user_scope'] = $this->formatScopes($this->scopes, $this->scopeSeparator); + } + + return $fields; + } + + /** + * {@inheritdoc} + */ + public function getAccessTokenResponse($code) + { + $response = $this->getHttpClient()->post($this->getTokenUrl(), [ + RequestOptions::HEADERS => $this->getTokenHeaders($code), + RequestOptions::FORM_PARAMS => $this->getTokenFields($code), + ]); + + $result = json_decode($response->getBody(), true); + + if ($this->scopeKey === 'user_scope') { + return $result['authed_user']; + } + + return $result; + } } From af4900440759c1c5f65f1b90a6b4d7d09b59adc8 Mon Sep 17 00:00:00 2001 From: driesvints Date: Fri, 14 Jul 2023 14:56:56 +0000 Subject: [PATCH 10/13] Update CHANGELOG --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b438462c..1a21151c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Release Notes -## [Unreleased](https://github.com/laravel/socialite/compare/v5.7.0...5.x) +## [Unreleased](https://github.com/laravel/socialite/compare/v5.8.0...5.x) + +## [v5.8.0](https://github.com/laravel/socialite/compare/v5.7.0...v5.8.0) - 2023-07-14 + +- Update Slack provider to use v2 API and allow Bot tokens by [@jbrooksuk](https://github.com/jbrooksuk) in https://github.com/laravel/socialite/pull/645 ## [v5.7.0](https://github.com/laravel/socialite/compare/v5.6.3...v5.7.0) - 2023-07-08 From 9989b4530331597fae811bca240bf4e8f15e804b Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 21 Aug 2023 15:06:52 +0200 Subject: [PATCH 11/13] Fix phpstan issues in Twitter and Slack drivers (#653) --- src/Two/SlackProvider.php | 2 +- src/Two/TwitterProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Two/SlackProvider.php b/src/Two/SlackProvider.php index 299f794c..225ff023 100644 --- a/src/Two/SlackProvider.php +++ b/src/Two/SlackProvider.php @@ -5,7 +5,7 @@ use GuzzleHttp\RequestOptions; use Illuminate\Support\Arr; -class SlackProvider extends AbstractProvider +class SlackProvider extends AbstractProvider implements ProviderInterface { /** * The scopes being requested. diff --git a/src/Two/TwitterProvider.php b/src/Two/TwitterProvider.php index dd1f54be..b6661f71 100644 --- a/src/Two/TwitterProvider.php +++ b/src/Two/TwitterProvider.php @@ -5,7 +5,7 @@ use GuzzleHttp\RequestOptions; use Illuminate\Support\Arr; -class TwitterProvider extends AbstractProvider +class TwitterProvider extends AbstractProvider implements ProviderInterface { /** * The scopes being requested. From 860b49af103958882de59955363544bb59621f53 Mon Sep 17 00:00:00 2001 From: driesvints Date: Tue, 22 Aug 2023 15:22:57 +0000 Subject: [PATCH 12/13] Update CHANGELOG --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a21151c..997e27fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Release Notes -## [Unreleased](https://github.com/laravel/socialite/compare/v5.8.0...5.x) +## [Unreleased](https://github.com/laravel/socialite/compare/v5.8.1...5.x) + +## [v5.8.1](https://github.com/laravel/socialite/compare/v5.8.0...v5.8.1) - 2023-08-21 + +- Fix phpstan issues in Twitter and Slack drivers by [@alecpl](https://github.com/alecpl) in https://github.com/laravel/socialite/pull/653 ## [v5.8.0](https://github.com/laravel/socialite/compare/v5.7.0...v5.8.0) - 2023-07-14 From 1e81f39ff85884df53d835af6c64b0f8aa86a0ed Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 31 Aug 2023 17:14:56 +0300 Subject: [PATCH 13/13] Include GitHub node_id field (#657) --- src/Two/GithubProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Two/GithubProvider.php b/src/Two/GithubProvider.php index 25b718c3..9488e086 100644 --- a/src/Two/GithubProvider.php +++ b/src/Two/GithubProvider.php @@ -83,6 +83,7 @@ protected function mapUserToObject(array $user) { return (new User)->setRaw($user)->map([ 'id' => $user['id'], + 'nodeId' => $user['node_id'], 'nickname' => $user['login'], 'name' => Arr::get($user, 'name'), 'email' => Arr::get($user, 'email'),