1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mrjoops\OAuth2\Client\Provider; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
6
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
7
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
8
|
|
|
use Mrjoops\OAuth2\Client\Provider\Exception\JiraIdentityProviderException; |
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
10
|
|
|
|
11
|
|
|
class Jira extends AbstractProvider |
12
|
|
|
{ |
13
|
|
|
use BearerAuthorizationTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Check a provider response for errors. |
17
|
|
|
* |
18
|
|
|
* @throws IdentityProviderException |
19
|
|
|
* @param ResponseInterface $response |
20
|
|
|
* @param array $data Parsed response data |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
protected function checkResponse(ResponseInterface $response, $data) |
25
|
|
|
{ |
26
|
|
|
if ($response->getStatusCode() >= 400) { |
27
|
|
|
throw JiraIdentityProviderException::clientException($response, $data); |
28
|
|
|
} elseif (isset($data['error'])) { |
29
|
|
|
throw JiraIdentityProviderException::oauthException($response, $data); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Generate a user object from a successful user details request. |
35
|
|
|
* |
36
|
|
|
* @param array $response |
37
|
|
|
* @param AccessToken $token |
38
|
|
|
* |
39
|
|
|
* @return \League\OAuth2\Client\Provider\ResourceOwnerInterface |
40
|
|
|
*/ |
41
|
|
|
protected function createResourceOwner(array $response, AccessToken $token) |
42
|
|
|
{ |
43
|
|
|
return new JiraResourceOwner($response); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get access token url to retrieve token |
48
|
|
|
* |
49
|
|
|
* @param array $params |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getBaseAccessTokenUrl(array $params) |
54
|
|
|
{ |
55
|
|
|
return 'https://accounts.atlassian.com/oauth/token'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get authorization url to begin OAuth flow |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getBaseAuthorizationUrl() |
64
|
|
|
{ |
65
|
|
|
return 'https://accounts.atlassian.com/authorize?audience=api.atlassian.com&prompt=consent'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the default scopes used by this provider. |
70
|
|
|
* |
71
|
|
|
* This should not be a complete list of all scopes, but the minimum |
72
|
|
|
* required for the provider user interface! |
73
|
|
|
* |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
protected function getDefaultScopes() |
77
|
|
|
{ |
78
|
|
|
return []; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get provider url to fetch user details |
83
|
|
|
* |
84
|
|
|
* @param AccessToken $token |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
89
|
|
|
{ |
90
|
|
|
return 'https://api.atlassian.com/oauth/token/accessible-resources'; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|