|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sludio\HelperBundle\Oauth\Client\Provider\Draugiem; |
|
4
|
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
|
6
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
|
7
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
9
|
|
|
|
|
10
|
|
|
class Draugiem extends AbstractProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Draugiem.lv API URL |
|
14
|
|
|
*/ |
|
15
|
|
|
const API_URL = 'http://api.draugiem.lv/json/'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Draugiem.lv passport login URL |
|
19
|
|
|
*/ |
|
20
|
|
|
const LOGIN_URL = 'https://api.draugiem.lv/authorize/'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Timeout in seconds for session_check requests |
|
24
|
|
|
*/ |
|
25
|
|
|
const SESSION_CHECK_TIMEOUT = 180; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param array $options |
|
29
|
|
|
* @param array $collaborators |
|
30
|
|
|
* |
|
31
|
|
|
* @throws \InvalidArgumentException |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($options = [], array $collaborators = []) |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct($options, $collaborators); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getBaseAuthorizationUrl() |
|
39
|
|
|
{ |
|
40
|
|
|
return static::LOGIN_URL; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getBaseAccessTokenUrl(array $params = []) |
|
44
|
|
|
{ |
|
45
|
|
|
return static::API_URL; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getDefaultScopes() |
|
49
|
|
|
{ |
|
50
|
|
|
return []; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function createResourceOwner(array $response, AccessToken $token = null) |
|
54
|
|
|
{ |
|
55
|
|
|
return new DraugiemUser($response); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function checkResponse(ResponseInterface $response, $data) |
|
59
|
|
|
{ |
|
60
|
|
View Code Duplication |
if (!empty($data['error'])) { |
|
|
|
|
|
|
61
|
|
|
$message = $data['error']['description']; |
|
|
|
|
|
|
62
|
|
|
throw new IdentityProviderException('error_draugiem_bad_response', $data['error']['code'], $response); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getClientSecret() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->clientSecret; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getClientId() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->clientId; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getRedirectUri() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->redirectUri; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
82
|
|
|
{ |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.