Merge pull request #63 from christyjacob4/master
Added Support for BitBucket OAuth
This commit is contained in:
commit
4c5e3947b0
17 changed files with 573 additions and 441 deletions
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* List Of World Currencies.
|
||||
|
|
|
@ -1,198 +1,198 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'AF' => 'Afganistan',
|
||||
'AO' => 'Angola',
|
||||
'AL' => 'Arnavutluk',
|
||||
'AD' => 'Andorra',
|
||||
'AE' => 'Birleşik Arap Emirlikleri',
|
||||
'AR' => 'Arjantin',
|
||||
'AM' => 'Ermenistan',
|
||||
'AG' => 'Antigua ve Barbuda',
|
||||
'AU' => 'Avustralya',
|
||||
'AT' => 'Avusturya',
|
||||
'AZ' => 'Azerbaycan',
|
||||
'BI' => 'Burundi',
|
||||
'BE' => 'Belçika',
|
||||
'BJ' => 'Benin',
|
||||
'BF' => 'Burkina Faso',
|
||||
'BD' => 'Bangladeş',
|
||||
'BG' => 'Bulgaristan',
|
||||
'BH' => 'Bahreyn',
|
||||
'BS' => 'Bahamalar',
|
||||
'BA' => 'Bosna Hersek',
|
||||
'BY' => 'Beyaz Rusya',
|
||||
'BZ' => 'Belize',
|
||||
'BO' => 'Bolivya',
|
||||
'BR' => 'Brezilya',
|
||||
'BB' => 'Barbados',
|
||||
'BN' => 'Brunei',
|
||||
'BT' => 'Butan',
|
||||
'BW' => 'Botsvana',
|
||||
'CF' => 'Orta Afrika Cumhuriyeti',
|
||||
'CA' => 'Kanada',
|
||||
'CH' => 'İsviçre',
|
||||
'CL' => 'Şili',
|
||||
'CN' => 'Çin',
|
||||
'CI' => 'Fildişi Sahili',
|
||||
'CM' => 'Kamerun',
|
||||
'CD' => 'Kongo - Kinşasa',
|
||||
'CG' => 'Kongo - Brazavil',
|
||||
'CO' => 'Kolombiya',
|
||||
'KM' => 'Komorlar',
|
||||
'CV' => 'Cape Verde',
|
||||
'CR' => 'Kosta Rika',
|
||||
'CU' => 'Küba',
|
||||
'CY' => 'Güney Kıbrıs Rum Kesimi',
|
||||
'CZ' => 'Çek Cumhuriyeti',
|
||||
'DE' => 'Almanya',
|
||||
'DJ' => 'Cibuti',
|
||||
'DM' => 'Dominika',
|
||||
'DK' => 'Danimarka',
|
||||
'DO' => 'Dominik Cumhuriyeti',
|
||||
'DZ' => 'Cezayir',
|
||||
'EC' => 'Ekvador',
|
||||
'EG' => 'Mısır',
|
||||
'ER' => 'Eritre',
|
||||
'ES' => 'İspanya',
|
||||
'EE' => 'Estonya',
|
||||
'ET' => 'Etiyopya',
|
||||
'FI' => 'Finlandiya',
|
||||
'FJ' => 'Fiji',
|
||||
'FR' => 'Fransa',
|
||||
'FM' => 'Mikronezya',
|
||||
'GA' => 'Gabon',
|
||||
'GB' => 'Birleşik Krallık',
|
||||
'GE' => 'Gürcistan',
|
||||
'GH' => 'Gana',
|
||||
'GN' => 'Gine',
|
||||
'GM' => 'Gambiya',
|
||||
'GW' => 'Gine-Bissau',
|
||||
'GQ' => 'Ekvator Ginesi',
|
||||
'GR' => 'Yunanistan',
|
||||
'GD' => 'Grenada',
|
||||
'GT' => 'Guatemala',
|
||||
'GY' => 'Guyana',
|
||||
'HN' => 'Honduras',
|
||||
'HR' => 'Hırvatistan',
|
||||
'HT' => 'Haiti',
|
||||
'HU' => 'Macaristan',
|
||||
'ID' => 'Endonezya',
|
||||
'IN' => 'Hindistan',
|
||||
'IE' => 'İrlanda',
|
||||
'IR' => 'İran',
|
||||
'IQ' => 'Irak',
|
||||
'IS' => 'İzlanda',
|
||||
'IL' => 'İsrail',
|
||||
'IT' => 'İtalya',
|
||||
'JM' => 'Jamaika',
|
||||
'JO' => 'Ürdün',
|
||||
'JP' => 'Japonya',
|
||||
'KZ' => 'Kazakistan',
|
||||
'KE' => 'Kenya',
|
||||
'KG' => 'Kırgızistan',
|
||||
'KH' => 'Kamboçya',
|
||||
'KI' => 'Kiribati',
|
||||
'KN' => 'Saint Kitts ve Nevis',
|
||||
'KR' => 'Güney Kore',
|
||||
'KW' => 'Kuveyt',
|
||||
'LA' => 'Laos',
|
||||
'LB' => 'Lübnan',
|
||||
'LR' => 'Liberya',
|
||||
'LY' => 'Libya',
|
||||
'LC' => 'Saint Lucia',
|
||||
'LI' => 'Liechtenstein',
|
||||
'LK' => 'Sri Lanka',
|
||||
'LS' => 'Lesoto',
|
||||
'LT' => 'Litvanya',
|
||||
'LU' => 'Lüksemburg',
|
||||
'LV' => 'Letonya',
|
||||
'MA' => 'Fas',
|
||||
'MC' => 'Monako',
|
||||
'MD' => 'Moldova',
|
||||
'MG' => 'Madagaskar',
|
||||
'MV' => 'Maldivler',
|
||||
'MX' => 'Meksika',
|
||||
'MH' => 'Marshall Adaları',
|
||||
'MK' => 'Makedonya',
|
||||
'ML' => 'Mali',
|
||||
'MT' => 'Malta',
|
||||
'MM' => 'Myanmar (Burma)',
|
||||
'ME' => 'Karadağ',
|
||||
'MN' => 'Moğolistan',
|
||||
'MZ' => 'Mozambik',
|
||||
'MR' => 'Moritanya',
|
||||
'MU' => 'Mauritius',
|
||||
'MW' => 'Malavi',
|
||||
'MY' => 'Malezya',
|
||||
'NA' => 'Namibya',
|
||||
'NE' => 'Nijer',
|
||||
'NG' => 'Nijerya',
|
||||
'NI' => 'Nikaragua',
|
||||
'NL' => 'Hollanda',
|
||||
'NO' => 'Norveç',
|
||||
'NP' => 'Nepal',
|
||||
'NR' => 'Nauru',
|
||||
'NZ' => 'Yeni Zelanda',
|
||||
'OM' => 'Umman',
|
||||
'PK' => 'Pakistan',
|
||||
'PA' => 'Panama',
|
||||
'PE' => 'Peru',
|
||||
'PH' => 'Filipinler',
|
||||
'PW' => 'Palau',
|
||||
'PG' => 'Papua Yeni Gine',
|
||||
'PL' => 'Polonya',
|
||||
'KP' => 'Kuzey Kore',
|
||||
'PT' => 'Portekiz',
|
||||
'PY' => 'Paraguay',
|
||||
'QA' => 'Katar',
|
||||
'RO' => 'Romanya',
|
||||
'RU' => 'Rusya',
|
||||
'RW' => 'Ruanda',
|
||||
'SA' => 'Suudi Arabistan',
|
||||
'SD' => 'Sudan',
|
||||
'SN' => 'Senegal',
|
||||
'SG' => 'Singapur',
|
||||
'SB' => 'Solomon Adaları',
|
||||
'SL' => 'Sierra Leone',
|
||||
'SV' => 'El Salvador',
|
||||
'SM' => 'San Marino',
|
||||
'SO' => 'Somali',
|
||||
'RS' => 'Sırbistan',
|
||||
'SS' => 'Güney Sudan',
|
||||
'ST' => 'São Tomé ve Príncipe',
|
||||
'SR' => 'Surinam',
|
||||
'SK' => 'Slovakya',
|
||||
'SI' => 'Slovenya',
|
||||
'SE' => 'İsveç',
|
||||
'SZ' => 'Svaziland',
|
||||
'SC' => 'Seyşeller',
|
||||
'SY' => 'Suriye',
|
||||
'TD' => 'Çad',
|
||||
'TG' => 'Togo',
|
||||
'TH' => 'Tayland',
|
||||
'TJ' => 'Tacikistan',
|
||||
'TM' => 'Türkmenistan',
|
||||
'TL' => 'Timor-Leste',
|
||||
'TO' => 'Tonga',
|
||||
'TT' => 'Trinidad ve Tobago',
|
||||
'TN' => 'Tunus',
|
||||
'TR' => 'Türkiye',
|
||||
'TV' => 'Tuvalu',
|
||||
'TZ' => 'Tanzanya',
|
||||
'UG' => 'Uganda',
|
||||
'UA' => 'Ukrayna',
|
||||
'UY' => 'Uruguay',
|
||||
'US' => 'ABD',
|
||||
'UZ' => 'Özbekistan',
|
||||
'VA' => 'Vatikan',
|
||||
'VC' => 'Saint Vincent ve Grenadinler',
|
||||
'VE' => 'Venezuela',
|
||||
'VN' => 'Vietnam',
|
||||
'VU' => 'Vanuatu',
|
||||
'WS' => 'Samoa',
|
||||
'YE' => 'Yemen',
|
||||
'ZA' => 'Güney Afrika',
|
||||
'ZM' => 'Zambiya',
|
||||
'ZW' => 'Zimbabve',
|
||||
'AF' => 'Afganistan',
|
||||
'AO' => 'Angola',
|
||||
'AL' => 'Arnavutluk',
|
||||
'AD' => 'Andorra',
|
||||
'AE' => 'Birleşik Arap Emirlikleri',
|
||||
'AR' => 'Arjantin',
|
||||
'AM' => 'Ermenistan',
|
||||
'AG' => 'Antigua ve Barbuda',
|
||||
'AU' => 'Avustralya',
|
||||
'AT' => 'Avusturya',
|
||||
'AZ' => 'Azerbaycan',
|
||||
'BI' => 'Burundi',
|
||||
'BE' => 'Belçika',
|
||||
'BJ' => 'Benin',
|
||||
'BF' => 'Burkina Faso',
|
||||
'BD' => 'Bangladeş',
|
||||
'BG' => 'Bulgaristan',
|
||||
'BH' => 'Bahreyn',
|
||||
'BS' => 'Bahamalar',
|
||||
'BA' => 'Bosna Hersek',
|
||||
'BY' => 'Beyaz Rusya',
|
||||
'BZ' => 'Belize',
|
||||
'BO' => 'Bolivya',
|
||||
'BR' => 'Brezilya',
|
||||
'BB' => 'Barbados',
|
||||
'BN' => 'Brunei',
|
||||
'BT' => 'Butan',
|
||||
'BW' => 'Botsvana',
|
||||
'CF' => 'Orta Afrika Cumhuriyeti',
|
||||
'CA' => 'Kanada',
|
||||
'CH' => 'İsviçre',
|
||||
'CL' => 'Şili',
|
||||
'CN' => 'Çin',
|
||||
'CI' => 'Fildişi Sahili',
|
||||
'CM' => 'Kamerun',
|
||||
'CD' => 'Kongo - Kinşasa',
|
||||
'CG' => 'Kongo - Brazavil',
|
||||
'CO' => 'Kolombiya',
|
||||
'KM' => 'Komorlar',
|
||||
'CV' => 'Cape Verde',
|
||||
'CR' => 'Kosta Rika',
|
||||
'CU' => 'Küba',
|
||||
'CY' => 'Güney Kıbrıs Rum Kesimi',
|
||||
'CZ' => 'Çek Cumhuriyeti',
|
||||
'DE' => 'Almanya',
|
||||
'DJ' => 'Cibuti',
|
||||
'DM' => 'Dominika',
|
||||
'DK' => 'Danimarka',
|
||||
'DO' => 'Dominik Cumhuriyeti',
|
||||
'DZ' => 'Cezayir',
|
||||
'EC' => 'Ekvador',
|
||||
'EG' => 'Mısır',
|
||||
'ER' => 'Eritre',
|
||||
'ES' => 'İspanya',
|
||||
'EE' => 'Estonya',
|
||||
'ET' => 'Etiyopya',
|
||||
'FI' => 'Finlandiya',
|
||||
'FJ' => 'Fiji',
|
||||
'FR' => 'Fransa',
|
||||
'FM' => 'Mikronezya',
|
||||
'GA' => 'Gabon',
|
||||
'GB' => 'Birleşik Krallık',
|
||||
'GE' => 'Gürcistan',
|
||||
'GH' => 'Gana',
|
||||
'GN' => 'Gine',
|
||||
'GM' => 'Gambiya',
|
||||
'GW' => 'Gine-Bissau',
|
||||
'GQ' => 'Ekvator Ginesi',
|
||||
'GR' => 'Yunanistan',
|
||||
'GD' => 'Grenada',
|
||||
'GT' => 'Guatemala',
|
||||
'GY' => 'Guyana',
|
||||
'HN' => 'Honduras',
|
||||
'HR' => 'Hırvatistan',
|
||||
'HT' => 'Haiti',
|
||||
'HU' => 'Macaristan',
|
||||
'ID' => 'Endonezya',
|
||||
'IN' => 'Hindistan',
|
||||
'IE' => 'İrlanda',
|
||||
'IR' => 'İran',
|
||||
'IQ' => 'Irak',
|
||||
'IS' => 'İzlanda',
|
||||
'IL' => 'İsrail',
|
||||
'IT' => 'İtalya',
|
||||
'JM' => 'Jamaika',
|
||||
'JO' => 'Ürdün',
|
||||
'JP' => 'Japonya',
|
||||
'KZ' => 'Kazakistan',
|
||||
'KE' => 'Kenya',
|
||||
'KG' => 'Kırgızistan',
|
||||
'KH' => 'Kamboçya',
|
||||
'KI' => 'Kiribati',
|
||||
'KN' => 'Saint Kitts ve Nevis',
|
||||
'KR' => 'Güney Kore',
|
||||
'KW' => 'Kuveyt',
|
||||
'LA' => 'Laos',
|
||||
'LB' => 'Lübnan',
|
||||
'LR' => 'Liberya',
|
||||
'LY' => 'Libya',
|
||||
'LC' => 'Saint Lucia',
|
||||
'LI' => 'Liechtenstein',
|
||||
'LK' => 'Sri Lanka',
|
||||
'LS' => 'Lesoto',
|
||||
'LT' => 'Litvanya',
|
||||
'LU' => 'Lüksemburg',
|
||||
'LV' => 'Letonya',
|
||||
'MA' => 'Fas',
|
||||
'MC' => 'Monako',
|
||||
'MD' => 'Moldova',
|
||||
'MG' => 'Madagaskar',
|
||||
'MV' => 'Maldivler',
|
||||
'MX' => 'Meksika',
|
||||
'MH' => 'Marshall Adaları',
|
||||
'MK' => 'Makedonya',
|
||||
'ML' => 'Mali',
|
||||
'MT' => 'Malta',
|
||||
'MM' => 'Myanmar (Burma)',
|
||||
'ME' => 'Karadağ',
|
||||
'MN' => 'Moğolistan',
|
||||
'MZ' => 'Mozambik',
|
||||
'MR' => 'Moritanya',
|
||||
'MU' => 'Mauritius',
|
||||
'MW' => 'Malavi',
|
||||
'MY' => 'Malezya',
|
||||
'NA' => 'Namibya',
|
||||
'NE' => 'Nijer',
|
||||
'NG' => 'Nijerya',
|
||||
'NI' => 'Nikaragua',
|
||||
'NL' => 'Hollanda',
|
||||
'NO' => 'Norveç',
|
||||
'NP' => 'Nepal',
|
||||
'NR' => 'Nauru',
|
||||
'NZ' => 'Yeni Zelanda',
|
||||
'OM' => 'Umman',
|
||||
'PK' => 'Pakistan',
|
||||
'PA' => 'Panama',
|
||||
'PE' => 'Peru',
|
||||
'PH' => 'Filipinler',
|
||||
'PW' => 'Palau',
|
||||
'PG' => 'Papua Yeni Gine',
|
||||
'PL' => 'Polonya',
|
||||
'KP' => 'Kuzey Kore',
|
||||
'PT' => 'Portekiz',
|
||||
'PY' => 'Paraguay',
|
||||
'QA' => 'Katar',
|
||||
'RO' => 'Romanya',
|
||||
'RU' => 'Rusya',
|
||||
'RW' => 'Ruanda',
|
||||
'SA' => 'Suudi Arabistan',
|
||||
'SD' => 'Sudan',
|
||||
'SN' => 'Senegal',
|
||||
'SG' => 'Singapur',
|
||||
'SB' => 'Solomon Adaları',
|
||||
'SL' => 'Sierra Leone',
|
||||
'SV' => 'El Salvador',
|
||||
'SM' => 'San Marino',
|
||||
'SO' => 'Somali',
|
||||
'RS' => 'Sırbistan',
|
||||
'SS' => 'Güney Sudan',
|
||||
'ST' => 'São Tomé ve Príncipe',
|
||||
'SR' => 'Surinam',
|
||||
'SK' => 'Slovakya',
|
||||
'SI' => 'Slovenya',
|
||||
'SE' => 'İsveç',
|
||||
'SZ' => 'Svaziland',
|
||||
'SC' => 'Seyşeller',
|
||||
'SY' => 'Suriye',
|
||||
'TD' => 'Çad',
|
||||
'TG' => 'Togo',
|
||||
'TH' => 'Tayland',
|
||||
'TJ' => 'Tacikistan',
|
||||
'TM' => 'Türkmenistan',
|
||||
'TL' => 'Timor-Leste',
|
||||
'TO' => 'Tonga',
|
||||
'TT' => 'Trinidad ve Tobago',
|
||||
'TN' => 'Tunus',
|
||||
'TR' => 'Türkiye',
|
||||
'TV' => 'Tuvalu',
|
||||
'TZ' => 'Tanzanya',
|
||||
'UG' => 'Uganda',
|
||||
'UA' => 'Ukrayna',
|
||||
'UY' => 'Uruguay',
|
||||
'US' => 'ABD',
|
||||
'UZ' => 'Özbekistan',
|
||||
'VA' => 'Vatikan',
|
||||
'VC' => 'Saint Vincent ve Grenadinler',
|
||||
'VE' => 'Venezuela',
|
||||
'VN' => 'Vietnam',
|
||||
'VU' => 'Vanuatu',
|
||||
'WS' => 'Samoa',
|
||||
'YE' => 'Yemen',
|
||||
'ZA' => 'Güney Afrika',
|
||||
'ZM' => 'Zambiya',
|
||||
'ZW' => 'Zimbabve',
|
||||
];
|
||||
|
|
|
@ -4,7 +4,7 @@ return [
|
|||
'bitbucket' => [
|
||||
'developers' => 'https://developer.atlassian.com/bitbucket',
|
||||
'icon' => 'icon-bitbucket',
|
||||
'enabled' => false,
|
||||
'enabled' => true,
|
||||
],
|
||||
'facebook' => [
|
||||
'developers' => 'https://developers.facebook.com/',
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
<?php
|
||||
|
||||
global $utopia, $register, $request, $response, $user, $audit, $webhook, $project, $domain, $projectDB, $providers, $clients;
|
||||
|
@ -49,9 +48,9 @@ $utopia->post('/v1/auth/register')
|
|||
->action(
|
||||
function ($email, $password, $confirm, $success, $failure, $name) use ($request, $response, $register, $audit, $projectDB, $project, $webhook) {
|
||||
if ('console' === $project->getUid()) {
|
||||
$whitlistEmails = $project->getAttribute('authWhitelistEmails');
|
||||
$whitlistIPs = $project->getAttribute('authWhitelistIPs');
|
||||
$whitlistDomains = $project->getAttribute('authWhitelistDomains');
|
||||
$whitlistEmails = $project->getAttribute('authWhitelistEmails');
|
||||
$whitlistIPs = $project->getAttribute('authWhitelistIPs');
|
||||
$whitlistDomains = $project->getAttribute('authWhitelistDomains');
|
||||
|
||||
if (!empty($whitlistEmails) && !in_array($email, $whitlistEmails)) {
|
||||
throw new Exception('Console registration is restricted to specific emails. Contact your administrator for more information.', 401);
|
||||
|
@ -61,7 +60,7 @@ $utopia->post('/v1/auth/register')
|
|||
throw new Exception('Console registration is restricted to specific IPs. Contact your administrator for more information.', 401);
|
||||
}
|
||||
|
||||
if (!empty($whitlistDomains) && !in_array(substr(strrchr($email, '@'), 1), $whitlistDomains)) {
|
||||
if (!empty($whitlistDomains) && !in_array(substr(strrchr($email, "@"), 1), $whitlistDomains)) {
|
||||
throw new Exception('Console registration is restricted to specific domains. Contact your administrator for more information.', 401);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +76,7 @@ $utopia->post('/v1/auth/register')
|
|||
|
||||
if (!empty($profile)) {
|
||||
if ($failure) {
|
||||
$response->redirect($failure.'?message=User already registered');
|
||||
$response->redirect($failure . '?message=User already registered');
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -802,6 +801,7 @@ $utopia->get('/v1/auth/oauth/:provider/redirect')
|
|||
],
|
||||
]) : $user;
|
||||
|
||||
|
||||
if (empty($user)) { // No user logged in or with oauth provider ID, create new one or connect with account with same email
|
||||
$name = $oauth->getUserName($accessToken);
|
||||
$email = $oauth->getUserEmail($accessToken);
|
||||
|
|
|
@ -31,7 +31,7 @@ Once you have finished setting up all the metadata for the new provider, you nee
|
|||
Create a new class that extends the basic OAuth provider abstract class in this location:
|
||||
|
||||
```bash
|
||||
src/Auth/OAuth/ProviderName
|
||||
./src/Auth/OAuth/ProviderName
|
||||
```
|
||||
|
||||
Note that the class name should start with a capital letter as PHP FIG standards suggest.
|
||||
|
|
BIN
public/images/oauth/bitbucket.png
Normal file
BIN
public/images/oauth/bitbucket.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 716 KiB After Width: | Height: | Size: 6.7 KiB |
132
src/Auth/OAuth/Bitbucket.php
Normal file
132
src/Auth/OAuth/Bitbucket.php
Normal file
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
namespace Auth\OAuth;
|
||||
|
||||
use Auth\OAuth;
|
||||
|
||||
// Reference Material
|
||||
// https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html#OAuthonBitbucketCloud-Createaconsumer
|
||||
|
||||
class Bitbucket extends OAuth
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $user = [];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'bitbucket';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLoginURL(): string
|
||||
{
|
||||
return 'https://bitbucket.org/site/oauth2/authorize?' .
|
||||
'client_id=' . urlencode($this->appID).
|
||||
'&state=' . urlencode(json_encode($this->state)).
|
||||
'&response_type=code';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessToken(string $code): string
|
||||
{
|
||||
// Required as per Bitbucket Spec.
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
||||
|
||||
$accessToken = $this->request(
|
||||
'POST',
|
||||
'https://bitbucket.org/site/oauth2/access_token',
|
||||
$headers,
|
||||
'code=' . urlencode($code) .
|
||||
'&client_id=' . urlencode($this->appID) .
|
||||
'&client_secret=' . urlencode($this->appSecret).
|
||||
'&grant_type=authorization_code'
|
||||
);
|
||||
|
||||
$accessToken = json_decode($accessToken, true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
return $accessToken['access_token'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUserID(string $accessToken): string
|
||||
{
|
||||
$user = $this->getUser($accessToken);
|
||||
|
||||
if (isset($user['uuid'])) {
|
||||
return $user['uuid'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUserEmail(string $accessToken): string
|
||||
{
|
||||
$user = $this->getUser($accessToken);
|
||||
|
||||
if (isset($user['email'])) {
|
||||
return $user['email'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUserName(string $accessToken): string
|
||||
{
|
||||
$user = $this->getUser($accessToken);
|
||||
|
||||
if (isset($user['display_name'])) {
|
||||
return $user['display_name'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getUser(string $accessToken): array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'https://api.bitbucket.org/2.0/user?access_token='.urlencode($accessToken));
|
||||
$this->user = json_decode($user, true);
|
||||
|
||||
$email = $this->request('GET', 'https://api.bitbucket.org/2.0/user/emails?access_token='.urlencode($accessToken));
|
||||
$this->user['email'] = json_decode($email, true)['values'][0]['email'];
|
||||
|
||||
// var_dump($user);
|
||||
// exit();
|
||||
}
|
||||
return $this->user;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue