-
Notifications
You must be signed in to change notification settings - Fork 0
/
Provvider.php
82 lines (72 loc) · 1.95 KB
/
Provvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Erre2Web\Esl;
use Illuminate\Support\Arr;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
use SocialiteProviders\Manager\OAuth2\User;
class Provider extends AbstractProvider
{
/**
* Unique Provider Identifier.
*/
const IDENTIFIER = 'ESL';
/**
* {@inheritdoc}
*/
protected $scopes = ['basicprofile.read fullprofile.read gameaccounts.read openid'];
/**
* {@inherticdoc}.
*/
protected $scopeSeparator = ' ';
/**
* {@inheritdoc}
*/
protected function getAuthUrl($state)
{
return $this->buildAuthUrlFromBase(
'https://account.eslgaming.com/oauth2/v1/auth', $state
);
}
/**
* {@inheritdoc}
*/
protected function getTokenUrl()
{
return 'https://account.eslgaming.com/oauth2/v1/token';
}
/**
* {@inheritdoc}
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->get(
'https://account.eslgaming.com/oauth2/v1/userinfo', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
],
]);
return json_decode($response->getBody()->getContents(), true);
}
/**
* {@inheritdoc}
*/
protected function mapUserToObject(array $user)
{
return (new User())->setRaw($user)->map([
'id' => $user['sub'],
'nickname' => $user['nickname'],
'name' => $user['nickname'],
'email' => $user['email'],
'avatar' => $user['picture'],
]);
}
/**
* {@inheritdoc}
*/
protected function getTokenFields($code)
{
return array_merge(parent::getTokenFields($code), [
'grant_type' => 'authorization_code',
]);
}
}