1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth\OAuth2\Service; |
4
|
|
|
|
5
|
|
|
use OAuth\OAuth2\Token\StdOAuth2Token; |
6
|
|
|
use OAuth\Common\Http\Exception\TokenResponseException; |
7
|
|
|
use OAuth\Common\Http\Uri\Uri; |
8
|
|
|
|
9
|
|
|
class Mondo extends AbstractService |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* {@inheritdoc} |
13
|
|
|
*/ |
14
|
|
|
protected function init() |
15
|
|
|
{ |
16
|
|
|
$this->stateParameterInAuthUrl = true; |
17
|
|
|
|
18
|
|
|
if( $this->baseApiUri === null ) { |
|
|
|
|
19
|
|
|
$this->baseApiUri = new Uri('https://api.getmondo.co.uk'); |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function getAuthorizationEndpoint() |
27
|
|
|
{ |
28
|
|
|
return new Uri('https://auth.getmondo.co.uk'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function getAccessTokenEndpoint() |
35
|
|
|
{ |
36
|
|
|
return new Uri('https://api.getmondo.co.uk/oauth2/token'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
protected function getAuthorizationMethod() |
43
|
|
|
{ |
44
|
|
|
return static::AUTHORIZATION_METHOD_HEADER_BEARER; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
protected function parseAccessTokenResponse($responseBody) |
51
|
|
|
{ |
52
|
|
|
$data = json_decode($responseBody, true); |
53
|
|
|
|
54
|
|
|
if (null === $data || !is_array($data)) { |
55
|
|
|
throw new TokenResponseException('Unable to parse response.'); |
56
|
|
|
} elseif (isset($data['error'])) { |
57
|
|
|
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
$token = new StdOAuth2Token(); |
62
|
|
|
$token->setAccessToken($data['access_token']); |
63
|
|
|
|
64
|
|
|
if (isset($data['expires_in'])) { |
65
|
|
|
$token->setLifetime($data['expires_in']); |
66
|
|
|
unset($data['expires_in']); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (isset($data['refresh_token'])) { |
70
|
|
|
$token->setRefreshToken($data['refresh_token']); |
71
|
|
|
unset($data['refresh_token']); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
unset($data['access_token']); |
75
|
|
|
|
76
|
|
|
$token->setExtraParams($data); |
77
|
|
|
|
78
|
|
|
return $token; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|