1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mailxpert\OAuth2\Client\Provider; |
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 League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
9
|
|
|
use Mailxpert\OAuth2\Client\Exception\ResourceOwnerException; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
11
|
|
|
|
12
|
|
|
class Mailxpert extends AbstractProvider |
13
|
|
|
{ |
14
|
|
|
use BearerAuthorizationTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Get authorization url to begin OAuth 2.0 'Authorization Code' grant. |
18
|
|
|
* |
19
|
|
|
* @return string |
20
|
|
|
*/ |
21
|
4 |
|
public function getBaseAuthorizationUrl() |
22
|
|
|
{ |
23
|
4 |
|
return 'https://v5.mailxpert.ch/oauth/v2/auth'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get access token url to retrieve token. |
28
|
|
|
* |
29
|
|
|
* @param array $params |
30
|
|
|
* |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
6 |
|
public function getBaseAccessTokenUrl(array $params) |
34
|
|
|
{ |
35
|
6 |
|
return 'https://v5.mailxpert.ch/oauth/v2/token'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* We do currently not support an owner resource. |
40
|
|
|
* |
41
|
|
|
* @param AccessToken $token |
42
|
|
|
* |
43
|
|
|
* @throws ResourceOwnerException |
44
|
|
|
* |
45
|
|
|
* @return string|void |
46
|
|
|
*/ |
47
|
2 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
48
|
|
|
{ |
49
|
2 |
|
throw new ResourceOwnerException(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the default scopes uses by this provider. Currently there is no support of scopes at all thus returning an empty array. |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
4 |
|
protected function getDefaultScopes() |
58
|
|
|
{ |
59
|
4 |
|
return []; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param ResponseInterface $response |
64
|
|
|
* @param array|string $data |
65
|
|
|
* |
66
|
|
|
* @throws IdentityProviderException |
67
|
|
|
*/ |
68
|
4 |
|
protected function checkResponse(ResponseInterface $response, $data) |
69
|
|
|
{ |
70
|
4 |
|
$statusCode = $response->getStatusCode(); |
71
|
|
|
|
72
|
4 |
|
if ($statusCode >= 400) { |
73
|
2 |
|
throw new IdentityProviderException( |
74
|
2 |
|
isset($data['message']) ? $data['message'] : $response->getReasonPhrase(), |
75
|
2 |
|
$statusCode, |
76
|
1 |
|
$response |
|
|
|
|
77
|
1 |
|
); |
78
|
|
|
} |
79
|
2 |
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param array $response |
83
|
|
|
* @param AccessToken $token |
84
|
|
|
* |
85
|
|
|
* @throws ResourceOwnerException |
86
|
|
|
* |
87
|
|
|
* @return \League\OAuth2\Client\Provider\ResourceOwnerInterface|void |
88
|
|
|
*/ |
89
|
2 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
90
|
|
|
{ |
91
|
2 |
|
throw new ResourceOwnerException(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|