1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mckenziearts\LaravelOAuth\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
6
|
|
|
use Laravel\Socialite\Two\User; |
7
|
|
|
use Laravel\Socialite\Two\AbstractProvider; |
8
|
|
|
use Laravel\Socialite\Two\ProviderInterface; |
9
|
|
|
|
10
|
|
|
class DribbbleProvider extends AbstractProvider implements ProviderInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
protected $scopes = ['public']; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Get the authentication URL for the provider. |
19
|
|
|
* |
20
|
|
|
* @param string $state |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
protected function getAuthUrl($state) |
24
|
|
|
{ |
25
|
|
|
return $this->buildAuthUrlFromBase( |
26
|
|
|
'https://dribbble.com/oauth/authorize', $state |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get the token URL for the provider. |
32
|
|
|
* |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
protected function getTokenUrl() |
36
|
|
|
{ |
37
|
|
|
return 'https://dribbble.com/oauth/token'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the raw user for the given access token. |
42
|
|
|
* |
43
|
|
|
* @param string $token |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
protected function getUserByToken($token) |
47
|
|
|
{ |
48
|
|
|
$response = $this->getHttpClient()->get( |
49
|
|
|
'https://api.dribbble.com/v2/user?access_token='.$token |
50
|
|
|
); |
51
|
|
|
return json_decode($response->getBody()->getContents(), true); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Map the raw user array to a Socialite User instance. |
56
|
|
|
* |
57
|
|
|
* @param array $user |
58
|
|
|
* @return \Laravel\Socialite\Two\User |
59
|
|
|
*/ |
60
|
|
|
protected function mapUserToObject(array $user) |
61
|
|
|
{ |
62
|
|
|
return (new User())->setRaw($user)->map([ |
63
|
|
|
'id' => $user['id'], |
64
|
|
|
'nickname' => $user['login'], |
65
|
|
|
'name' => $user['name'], |
66
|
|
|
'email' => Arr::get($user, 'email'), |
67
|
|
|
'avatar' => $user['avatar_url'], |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|