Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| Bitbucket | |
100.00% |
15 / 15 |
|
100.00% |
6 / 6 |
7 | |
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 | |||
| 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 Bitbucket extends AbstractOAuth2Provider |
| 8 | { |
| 9 | /** |
| 10 | * Returns the Authorize URL |
| 11 | * |
| 12 | * @return string |
| 13 | */ |
| 14 | protected function getAuthorizeUrl(): string |
| 15 | { |
| 16 | return 'https://bitbucket.org/site/oauth2/authorize'; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Returns the Access Token URL |
| 21 | * |
| 22 | * @return string |
| 23 | */ |
| 24 | protected function getAccessTokenUrl(): string |
| 25 | { |
| 26 | return 'https://bitbucket.org/site/oauth2/access_token'; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Returns the requested scope |
| 31 | * |
| 32 | * @return string|null |
| 33 | */ |
| 34 | protected function getScope(): ?string |
| 35 | { |
| 36 | return 'account'; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns the user profile |
| 41 | * |
| 42 | * @param array $accessToken The access token. |
| 43 | * |
| 44 | * @return User |
| 45 | */ |
| 46 | protected function getUserProfile(array $accessToken): User |
| 47 | { |
| 48 | $data = $this->curlRequest('https://api.bitbucket.org/2.0/user', 'GET', null, [ |
| 49 | 'Authorization: Bearer ' . $accessToken['access_token'], |
| 50 | ]); |
| 51 | if ($data['account_status'] !== 'active') { |
| 52 | throw new \RuntimeException('User is inactive'); |
| 53 | } |
| 54 | |
| 55 | return new User( |
| 56 | $data['uuid'], |
| 57 | $data['username'], |
| 58 | $data['display_name'], |
| 59 | $data['links']['avatar']['href'], |
| 60 | static::class, |
| 61 | ['accessToken' => $accessToken, 'userData' => $data] |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns the image source for the logo of this provider. |
| 67 | * |
| 68 | * @return string |
| 69 | */ |
| 70 | public static function getLogoSource(): string |
| 71 | { |
| 72 | return 'data:image/svg+xml;base64,' |
| 73 | . base64_encode(file_get_contents(__DIR__ . '/../../templates/logos/Bitbucket.svg')); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the theme color for this provider. |
| 78 | * |
| 79 | * @return string |
| 80 | */ |
| 81 | public static function getThemeColor(): string |
| 82 | { |
| 83 | return 'rgb(8,76,164)'; |
| 84 | } |
| 85 | } |