Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| Atlassian | |
100.00% |
18 / 18 |
|
100.00% |
7 / 7 |
8 | |
100.00% |
1 / 1 |
| getAuthorizeUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAccessTokenUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getScope | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFullAuthorizeUrl | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getUserProfile | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
| getLogoSource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getThemeColor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Miniframe\SocialLogin\Provider; |
| 4 | |
| 5 | use Miniframe\SocialLogin\Model\User; |
| 6 | |
| 7 | class Atlassian extends AbstractOAuth2Provider |
| 8 | { |
| 9 | /** |
| 10 | * Returns the Authorize URL |
| 11 | * |
| 12 | * @return string |
| 13 | */ |
| 14 | protected function getAuthorizeUrl(): string |
| 15 | { |
| 16 | return 'https://auth.atlassian.com/authorize'; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Returns the Access Token URL |
| 21 | * |
| 22 | * @return string |
| 23 | */ |
| 24 | protected function getAccessTokenUrl(): string |
| 25 | { |
| 26 | return 'https://auth.atlassian.com/oauth/token'; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Returns the requested scope |
| 31 | * |
| 32 | * @return string|null |
| 33 | */ |
| 34 | protected function getScope(): ?string |
| 35 | { |
| 36 | return 'read:me'; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Gets a full authorize URL, including the client ID and all other required parameters. |
| 41 | * |
| 42 | * @param array $data Optionally extra fields to append to the authorize URL. |
| 43 | * |
| 44 | * @return string |
| 45 | */ |
| 46 | protected function getFullAuthorizeUrl(array $data = array()): string |
| 47 | { |
| 48 | // Atlassian requires these fields also to be defined |
| 49 | $data['audience'] = 'api.atlassian.com'; |
| 50 | $data['prompt'] = 'consent'; |
| 51 | return parent::getFullAuthorizeUrl($data); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Returns the user profile |
| 56 | * |
| 57 | * @param array $accessToken The access token. |
| 58 | * |
| 59 | * @return User |
| 60 | */ |
| 61 | protected function getUserProfile(array $accessToken): User |
| 62 | { |
| 63 | $data = $this->curlRequest('https://api.atlassian.com/me', 'GET', null, [ |
| 64 | 'Authorization: Bearer ' . $accessToken['access_token'], |
| 65 | 'Accept: application/json', |
| 66 | ]); |
| 67 | if (!$data['email_verified']) { |
| 68 | throw new \RuntimeException('The email address for this Atlassian account is not yet verified'); |
| 69 | } |
| 70 | |
| 71 | return new User( |
| 72 | $data['account_id'], |
| 73 | $data['email'], |
| 74 | $data['name'], |
| 75 | $data['picture'], |
| 76 | static::class, |
| 77 | ['accessToken' => $accessToken, 'userData' => $data] |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the image source for the logo of this provider. |
| 83 | * |
| 84 | * @return string |
| 85 | */ |
| 86 | public static function getLogoSource(): string |
| 87 | { |
| 88 | return 'data:image/svg+xml;base64,' |
| 89 | . base64_encode(file_get_contents(__DIR__ . '/../../templates/logos/Atlassian.svg')); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns the theme color for this provider. |
| 94 | * |
| 95 | * @return string |
| 96 | */ |
| 97 | public static function getThemeColor(): string |
| 98 | { |
| 99 | return 'rgba(16,76,180,255)'; |
| 100 | } |
| 101 | } |