diff --git a/app/app.php b/app/app.php index c377df68a4..e373abd754 100644 --- a/app/app.php +++ b/app/app.php @@ -3,7 +3,7 @@ // Init require_once __DIR__ . '/init.php'; -global $env, $utopia, $request, $response, $register, $consoleDB, $project, $domain, $sentry, $version, $service; +global $env, $utopia, $request, $response, $register, $consoleDB, $project, $domain, $sentry, $version, $service, $providers; use Utopia\App; use Utopia\Request; @@ -23,7 +23,6 @@ use Event\Event; * Configuration files */ $roles = include __DIR__ . '/config/roles.php'; // User roles and scopes -$providers = include __DIR__ . '/config/providers.php'; // OAuth providers list $sdks = include __DIR__ . '/config/sdks.php'; // List of SDK clients $services = include __DIR__ . '/config/services.php'; // List of SDK clients diff --git a/app/config/collections.php b/app/config/collections.php index 50eb235b4d..25a8eb0fc8 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1,8 +1,10 @@ [ '$uid' => 'console', '$collection' => 'projects', @@ -51,24 +53,6 @@ return [ 'legalCity' => '', 'legalAddress' => '', 'legalTaxId' => '', - // 'usersOauthBitbucketAppid' => '', - // 'usersOauthBitbucketSecret' => '', - 'usersOauthFacebookAppid' => '', - 'usersOauthFacebookSecret' => '', - 'usersOauthGithubAppid' => '', - 'usersOauthGithubSecret' => '', - // 'usersOauthGitlabAppid' => '', - // 'usersOauthGitlabSecret' => '', - // 'usersOauthGoogleAppid' => '', - // 'usersOauthGoogleSecret' => '', - // 'usersOauthInstagramAppid' => '', - // 'usersOauthInstagramSecret' => '', - 'usersOauthLinkedinAppid' => '', - 'usersOauthLinkedinSecret' => '', - // 'usersOauthMicrosoftAppid' => '', - // 'usersOauthMicrosoftSecret' => '', - // 'usersOauthTwitterAppid' => '', - // 'usersOauthTwitterSecret' => '', ], Database::SYSTEM_COLLECTION_COLLECTIONS => [ '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, @@ -310,168 +294,6 @@ return [ 'required' => true, 'array' => false, ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Bitbucket ID', - 'key' => 'oauthBitbucket', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Bitbucket Access Token', - 'key' => 'oauthBitbucketAccessToken', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Facebook ID', - 'key' => 'oauthFacebook', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Facebook Access Token', - 'key' => 'oauthFacebookAccessToken', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth GitHub ID', - 'key' => 'oauthGithub', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth GitHub Access Token', - 'key' => 'oauthGithubAccessToken', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Gitlab ID', - 'key' => 'oauthGitlab', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Gitlab Access Token', - 'key' => 'oauthGitlabAccessToken', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Google ID', - 'key' => 'oauthGoogle', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Google Access Token', - 'key' => 'oauthGoogleAccessToken', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Instagram ID', - 'key' => 'oauthInstagram', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Instagram Access Token', - 'key' => 'oauthInstagramAccessToken', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth LinkedIn ID', - 'key' => 'oauthLinkedin', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth LinkedIn Access Token', - 'key' => 'oauthLinkedinAccessToken', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Microsoft ID', - 'key' => 'oauthMicrosoft', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Microsoft Access Token', - 'key' => 'oauthMicrosoftAccessToken', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Twitter ID', - 'key' => 'oauthTwitter', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Twitter Access Token', - 'key' => 'oauthTwitterAccessToken', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], [ '$collection' => Database::SYSTEM_COLLECTION_RULES, 'label' => 'Tokens', @@ -760,168 +582,6 @@ return [ 'default' => '', 'required' => false, ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Bitbucket AppID', - 'key' => 'usersOauthBitbucketAppid', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Bitbucket Secret', - 'key' => 'usersOauthBitbucketSecret', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Facebook AppID', - 'key' => 'usersOauthFacebookAppid', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Facebook Secret', - 'key' => 'usersOauthFacebookSecret', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth GitHub AppID', - 'key' => 'usersOauthGithubAppid', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth GitHub Secret', - 'key' => 'usersOauthGithubSecret', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Gitlab AppID', - 'key' => 'usersOauthGitlabAppid', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Gitlab Secret', - 'key' => 'usersOauthGitlabSecret', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Google AppID', - 'key' => 'usersOauthGoogleAppid', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Google Secret', - 'key' => 'usersOauthGoogleSecret', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Instagram AppID', - 'key' => 'usersOauthInstagramAppid', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Instagram Secret', - 'key' => 'usersOauthInstagramSecret', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth LinkedIn AppID', - 'key' => 'usersOauthLinkedinAppid', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth LinkedIn Secret', - 'key' => 'usersOauthLinkedinSecret', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Microsoft AppID', - 'key' => 'usersOauthMicrosoftAppid', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Microsoft Secret', - 'key' => 'usersOauthMicrosoftSecret', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Twitter AppID', - 'key' => 'usersOauthTwitterAppid', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], - [ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth Twitter Secret', - 'key' => 'usersOauthTwitterSecret', - 'type' => 'text', - 'default' => '', - 'required' => false, - 'array' => false, - ], [ '$collection' => Database::SYSTEM_COLLECTION_RULES, 'label' => 'Webhooks', @@ -1443,4 +1103,61 @@ return [ ], ], ], -]; \ No newline at end of file +]; + +/** + * Add enabled OAuth providers to default data rules + */ +$oauthProjectsRules = []; +$oauthUsersRules = []; + +foreach($providers as $key => $provider) { + if(!$provider['enabled']) { + continue; + } + + $oauthProjectsRules[] = [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'OAuth ' . ucfirst($key) . ' ID', + 'key' => 'oauth' . ucfirst($key), + 'type' => 'text', + 'default' => '', + 'required' => false, + 'array' => false, + ]; + + $oauthProjectsRules[] = [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'OAuth ' . ucfirst($key) . ' Access Token', + 'key' => 'oauth' . ucfirst($key) . 'AccessToken', + 'type' => 'text', + 'default' => '', + 'required' => false, + 'array' => false, + ]; + + $oauthUsersRules = [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'OAuth ' . ucfirst($key) . ' ID', + 'key' => 'oauth' . ucfirst($key), + 'type' => 'text', + 'default' => '', + 'required' => false, + 'array' => false, + ]; + + $oauthUsersRules = [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'OAuth ' . ucfirst($key) . ' Access Token', + 'key' => 'oauth' . ucfirst($key) . 'AccessToken', + 'type' => 'text', + 'default' => '', + 'required' => false, + 'array' => false, + ]; +} + +$collections[Database::SYSTEM_COLLECTION_USERS]['rules'] = array_merge($collections[Database::SYSTEM_COLLECTION_USERS]['rules'], $oauthUsersRules); +$collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'] = array_merge($collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'], $oauthProjectsRules); + +return $collections; \ No newline at end of file diff --git a/app/controllers/account.php b/app/controllers/account.php index 841dbe0cc9..58919732d2 100644 --- a/app/controllers/account.php +++ b/app/controllers/account.php @@ -1,6 +1,6 @@ get('/v1/account') ->label('sdk.method', 'get') ->label('sdk.description', 'Get currently logged in user data as JSON object.') ->action( - function() use ($response, &$user) + function() use ($response, &$user, $providers) { - $response->json(array_merge($user->getArrayCopy([ - '$uid', - 'email', - 'registration', - 'confirm', - 'name', - 'oauthBitbucket', - 'oauthBitBucketAccessToken', - 'oauthFacebook', - 'oauthFacebookAccessToken', - 'oauthGithub', - 'oauthGithubAccessToken', - 'oauthGitlab', - 'oauthGitlabAccessToken', - 'oauthGoogle', - 'oauthGoogleAccessToken', - 'oauthInstagram', - 'oauthInstagramAccessToken', - 'oauthLinkedin', - 'oauthLinkedinAccessToken', - 'oauthMicrosoft', - 'oauthMicrosoftAccessToken', - 'oauthTwitter', - 'oauthTwitterAccessToken', - ]), ['roles' => Authorization::getRoles()])); + $oauthKeys = []; + + foreach($providers as $key => $provider) { + if(!$provider['enabled']) { + continue; + } + + $oauthKeys[] = 'oauth' . ucfirst($key); + $oauthKeys[] = 'oauth' . ucfirst($key) . 'AccessToken'; + } + + $response->json(array_merge($user->getArrayCopy(array_merge( + [ + '$uid', + 'email', + 'registration', + 'confirm', + 'name', + ], $oauthKeys + )), ['roles' => Authorization::getRoles()])); } ); diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 0d032e2db5..36b67372ff 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -11,15 +11,6 @@ use Utopia\Validator\Host; use Utopia\Validator\URL; use Utopia\Locale\Locale; use Auth\Auth; -use Auth\OAuth\Bitbucket; -use Auth\OAuth\Facebook; -use Auth\OAuth\GitHub; -use Auth\OAuth\Gitlab; -use Auth\OAuth\Google; -use Auth\OAuth\Instagram; -use Auth\OAuth\LinkedIn; -use Auth\OAuth\Microsoft; -use Auth\OAuth\Twitter; use Auth\Validator\Password; use Database\Database; use Database\Document; @@ -623,38 +614,14 @@ $utopia->get('/v1/auth/oauth/:provider') throw new Exception('Provider is undefined, configure provider app ID and app secret key to continue', 412); } - switch($provider) { - case 'bitbucket': - $oauth = new Bitbucket($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); - break; - case 'facebook': - $oauth = new Facebook($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); - break; - case 'github': - $oauth = new GitHub($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); - break; - case 'gitlab': - $oauth = new Gitlab($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); - break; - case 'google': - $oauth = new Google($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); - break; - case 'instagram': - $oauth = new Instagram($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); - break; - case 'linkedin': - $oauth = new LinkedIn($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); - break; - case 'microsoft': - $oauth = new Microsoft($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); - break; - case 'twitter': - $oauth = new Twitter($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); - break; - default: - throw new Exception('Provider is not supported', 501); + $classname = 'Auth\\OAuth\\' . ucfirst($provider); + + if(!class_exists($classname)) { + throw new Exception('Provider is not supported', 501); } + $oauth = new $classname($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); + $response->redirect($oauth->getLoginURL()); } ); @@ -729,38 +696,15 @@ $utopia->get('/v1/auth/oauth/:provider/redirect') $appSecret = OpenSSL::decrypt($appSecret['data'], $appSecret['method'], $key,0, hex2bin($appSecret['iv']), hex2bin($appSecret['tag'])); } - switch($provider) { - case 'bitbucket': - $oauth = new Bitbucket($appId, $appSecret, $callback); - break; - case 'facebook': - $oauth = new Facebook($appId, $appSecret, $callback); - break; - case 'github': - $oauth = new GitHub($appId, $appSecret, $callback); - break; - case 'gitlab': - $oauth = new Gitlab($appId, $appSecret, $callback); - break; - case 'google': - $oauth = new Google($appId, $appSecret, $callback); - break; - case 'instagram': - $oauth = new Instagram($appId, $appSecret, $callback); - break; - case 'linkedin': - $oauth = new LinkedIn($appId, $appSecret, $callback); - break; - case 'microsoft': - $oauth = new Microsoft($appId, $appSecret, $callback); - break; - case 'twitter': - $oauth = new LinkedIn($appId, $appSecret, $callback); - break; - default: - throw new Exception('Provider is not supported', 501); + + $classname = 'Auth\\OAuth\\' . ucfirst($provider); + + if(!class_exists($classname)) { + throw new Exception('Provider is not supported', 501); } + $oauth = new $classname($appId, $appSecret, $callback); + $accessToken = $oauth->getAccessToken($code); if(empty($accessToken)) { diff --git a/app/controllers/users.php b/app/controllers/users.php index 93c71b7965..529a10fed8 100644 --- a/app/controllers/users.php +++ b/app/controllers/users.php @@ -1,6 +1,6 @@ get('/v1/users') ->param('offset', 0 , function () {return new Range(0, 2000);}, 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', function () {return new WhiteList(['ASC', 'DESC']);}, 'Order result by ASC or DESC order.', true) ->action( - function($search, $limit, $offset, $orderType) use ($response, $projectDB) + function($search, $limit, $offset, $orderType) use ($response, $projectDB, $providers) { $results = $projectDB->getCollection([ 'limit' => $limit, @@ -43,34 +42,27 @@ $utopia->get('/v1/users') ], ]); - $results = array_map(function ($value) { /* @var $value \Database\Document */ - return $value->getArrayCopy([ - '$uid', - '$permissions', - 'status', - 'email', - 'registration', - 'confirm', - 'name', - 'oauthBitbucket', - 'oauthBitBucketAccessToken', - 'oauthFacebook', - 'oauthFacebookAccessToken', - 'oauthGithub', - 'oauthGithubAccessToken', - 'oauthGitlab', - 'oauthGitlabAccessToken', - 'oauthGoogle', - 'oauthGoogleAccessToken', - 'oauthInstagram', - 'oauthInstagramAccessToken', - 'oauthLinkedin', - 'oauthLinkedinAccessToken', - 'oauthMicrosoft', - 'oauthMicrosoftAccessToken', - 'oauthTwitter', - 'oauthTwitterAccessToken', - ]); + $oauthKeys = []; + + foreach($providers as $key => $provider) { + if(!$provider['enabled']) { + continue; + } + + $oauthKeys[] = 'oauth' . ucfirst($key); + $oauthKeys[] = 'oauth' . ucfirst($key) . 'AccessToken'; + } + + $results = array_map(function ($value) use ($oauthKeys) { /* @var $value \Database\Document */ + return $value->getArrayCopy(array_merge( + [ + '$uid', + 'email', + 'registration', + 'confirm', + 'name', + ], $oauthKeys + )); }, $results); $response->json(['sum' => $projectDB->getSum(), 'users' => $results]); @@ -85,7 +77,7 @@ $utopia->get('/v1/users/:userId') ->label('sdk.description', 'Get user by its unique ID.') ->param('userId', '', function () {return new UID();}, 'User unique ID.') ->action( - function($userId) use ($response, $projectDB) + function($userId) use ($response, $projectDB, $providers) { $user = $projectDB->getDocument($userId); @@ -93,32 +85,26 @@ $utopia->get('/v1/users/:userId') throw new Exception('User not found', 404); } - $response->json(array_merge($user->getArrayCopy([ - '$uid', - 'status', - 'email', - 'registration', - 'confirm', - 'name', - 'oauthBitbucket', - 'oauthBitBucketAccessToken', - 'oauthFacebook', - 'oauthFacebookAccessToken', - 'oauthGithub', - 'oauthGithubAccessToken', - 'oauthGitlab', - 'oauthGitlabAccessToken', - 'oauthGoogle', - 'oauthGoogleAccessToken', - 'oauthInstagram', - 'oauthInstagramAccessToken', - 'oauthLinkedin', - 'oauthLinkedinAccessToken', - 'oauthMicrosoft', - 'oauthMicrosoftAccessToken', - 'oauthTwitter', - 'oauthTwitterAccessToken', - ]), ['roles' => Authorization::getRoles()])); + $oauthKeys = []; + + foreach($providers as $key => $provider) { + if(!$provider['enabled']) { + continue; + } + + $oauthKeys[] = 'oauth' . ucfirst($key); + $oauthKeys[] = 'oauth' . ucfirst($key) . 'AccessToken'; + } + + $response->json(array_merge($user->getArrayCopy(array_merge( + [ + '$uid', + 'email', + 'registration', + 'confirm', + 'name', + ], $oauthKeys + )), ['roles' => Authorization::getRoles()])); } ); @@ -289,7 +275,7 @@ $utopia->post('/v1/users') ->param('password', '', function () {return new Password();}, 'User account password.') ->param('name', '', function () {return new Text(100);}, 'User account name.', true) ->action( - function($email, $password, $name) use ($response, $register, $projectDB, $project) { + function($email, $password, $name) use ($response, $register, $projectDB, $providers) { $profile = $projectDB->getCollection([ // Get user by email address 'limit' => 1, 'first' => true, @@ -318,35 +304,28 @@ $utopia->post('/v1/users') 'reset' => false, 'name' => $name, ]); + + $oauthKeys = []; + + foreach($providers as $key => $provider) { + if(!$provider['enabled']) { + continue; + } + + $oauthKeys[] = 'oauth' . ucfirst($key); + $oauthKeys[] = 'oauth' . ucfirst($key) . 'AccessToken'; + } $response ->setStatusCode(Response::STATUS_CODE_CREATED) - ->json(array_merge($user->getArrayCopy([ + ->json(array_merge($user->getArrayCopy(array_merge([ '$uid', 'status', 'email', 'registration', 'confirm', 'name', - 'oauthBitbucket', - 'oauthBitBucketAccessToken', - 'oauthFacebook', - 'oauthFacebookAccessToken', - 'oauthGithub', - 'oauthGithubAccessToken', - 'oauthGitlab', - 'oauthGitlabAccessToken', - 'oauthGoogle', - 'oauthGoogleAccessToken', - 'oauthInstagram', - 'oauthInstagramAccessToken', - 'oauthLinkedin', - 'oauthLinkedinAccessToken', - 'oauthMicrosoft', - 'oauthMicrosoftAccessToken', - 'oauthTwitter', - 'oauthTwitterAccessToken', - ]), ['roles' => Authorization::getRoles()])); + ], $oauthKeys)), ['roles' => Authorization::getRoles()])); } ); diff --git a/app/init.php b/app/init.php index 548bb9d440..ab53340976 100644 --- a/app/init.php +++ b/app/init.php @@ -42,13 +42,15 @@ $response = new Response(); /** * ENV vars */ -$env = $request->getServer('_APP_ENV', App::ENV_TYPE_PRODUCTION); -$domain = $request->getServer('HTTP_HOST', ''); -$version = include __DIR__ . '/../app/config/version.php'; -$redisHost = $request->getServer('_APP_REDIS_HOST', ''); -$redisPort = $request->getServer('_APP_REDIS_PORT', ''); -$utopia = new App('Asia/Tel_Aviv', $env); -$port = (string)(isset($_SERVER['HTTP_HOST'])) ? parse_url($_SERVER['HTTP_HOST'], PHP_URL_PORT) : ''; +$env = $request->getServer('_APP_ENV', App::ENV_TYPE_PRODUCTION); +$domain = $request->getServer('HTTP_HOST', ''); +$version = include __DIR__ . '/../app/config/version.php'; +$providers = include __DIR__ . '/../app/config/providers.php'; // OAuth providers list +$collections = include __DIR__ . '/../app/config/collections.php'; // OAuth providers list +$redisHost = $request->getServer('_APP_REDIS_HOST', ''); +$redisPort = $request->getServer('_APP_REDIS_PORT', ''); +$utopia = new App('Asia/Tel_Aviv', $env); +$port = (string)(isset($_SERVER['HTTP_HOST'])) ? parse_url($_SERVER['HTTP_HOST'], PHP_URL_PORT) : ''; Resque::setBackend($redisHost . ':' . $redisPort); @@ -153,7 +155,7 @@ stream_context_set_default([ // Set global user agent and http settings $consoleDB = new Database(); $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $consoleDB->setNamespace('app_console'); // Should be replaced with param if we want to have parent projects -$consoleDB->setMocks(include __DIR__ . '/../app/config/collections.php'); +$consoleDB->setMocks($collections); Authorization::disable(); @@ -182,7 +184,7 @@ Auth::$secret = $session['secret']; $projectDB = new Database(); $projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $projectDB->setNamespace('app_' . $project->getUid()); -$projectDB->setMocks(include __DIR__ . '/../app/config/collections.php'); +$projectDB->setMocks($collections); $user = $projectDB->getDocument(Auth::$unique); diff --git a/src/Auth/OAuth/GitHub.php b/src/Auth/OAuth/GitHub.php index 344f06150f..37b608d172 100644 --- a/src/Auth/OAuth/GitHub.php +++ b/src/Auth/OAuth/GitHub.php @@ -4,7 +4,7 @@ namespace Auth\OAuth; use Auth\OAuth; -class GitHub extends OAuth +class Github extends OAuth { /** * @var array