|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Laravel\Socialite\Two; |
| 4 | + |
| 5 | +use GuzzleHttp\RequestOptions; |
| 6 | +use Illuminate\Support\Arr; |
| 7 | + |
| 8 | +class SlackProvider extends AbstractProvider |
| 9 | +{ |
| 10 | + /** |
| 11 | + * The scopes being requested. |
| 12 | + * |
| 13 | + * @var array |
| 14 | + */ |
| 15 | + protected $scopes = ['identity.basic', 'identity.email', 'identity.team', 'identity.avatar']; |
| 16 | + |
| 17 | + /** |
| 18 | + * {@inheritdoc} |
| 19 | + */ |
| 20 | + public function getAuthUrl($state) |
| 21 | + { |
| 22 | + return $this->buildAuthUrlFromBase('https://slack.com/oauth/authorize', $state); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * {@inheritdoc} |
| 27 | + */ |
| 28 | + protected function getTokenUrl() |
| 29 | + { |
| 30 | + return 'https://slack.com/api/oauth.access'; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * {@inheritdoc} |
| 35 | + */ |
| 36 | + protected function getUserByToken($token) |
| 37 | + { |
| 38 | + $response = $this->getHttpClient()->get('https://slack.com/api/users.identity', [ |
| 39 | + RequestOptions::HEADERS => ['Authorization' => 'Bearer '.$token], |
| 40 | + ]); |
| 41 | + |
| 42 | + return json_decode($response->getBody(), true); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * {@inheritdoc} |
| 47 | + */ |
| 48 | + protected function mapUserToObject(array $user) |
| 49 | + { |
| 50 | + return (new User)->setRaw($user)->map([ |
| 51 | + 'id' => Arr::get($user, 'user.id'), |
| 52 | + 'name' => Arr::get($user, 'user.name'), |
| 53 | + 'email' => Arr::get($user, 'user.email'), |
| 54 | + 'avatar' => Arr::get($user, 'user.image_512'), |
| 55 | + 'organization_id' => Arr::get($user, 'team.id'), |
| 56 | + ]); |
| 57 | + } |
| 58 | +} |
0 commit comments