Merge branch 'master' of github.com:appwrite/appwrite into restify
This commit is contained in:
commit
73e1062884
4
.env
Normal file
4
.env
Normal file
|
@ -0,0 +1,4 @@
|
|||
TESTS_FACEBOOK_APP_ID=dbase
|
||||
TESTS_FACEBOOK_APP_KEY=SDASDHAJSHDAJSHDJHSD
|
||||
DB_PW=dbpassword
|
||||
DB_ROOT_PW=dbrootpw
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
/.vscode/
|
||||
/vendor/
|
||||
/node_modules/
|
||||
/storage/uploads/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- '7.3'
|
||||
- '7.4'
|
||||
|
||||
addons:
|
||||
hosts:
|
||||
|
|
|
@ -5,70 +5,92 @@ return [
|
|||
'developers' => 'https://developer.atlassian.com/bitbucket',
|
||||
'icon' => 'icon-bitbucket',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
'facebook' => [
|
||||
'developers' => 'https://developers.facebook.com/',
|
||||
'icon' => 'icon-facebook',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
'github' => [
|
||||
'developers' => 'https://developer.github.com/',
|
||||
'icon' => 'icon-github-circled',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
'gitlab' => [
|
||||
'developers' => 'https://docs.gitlab.com/ee/api/',
|
||||
'icon' => 'icon-gitlab',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
'google' => [
|
||||
'developers' => 'https://developers.google.com/',
|
||||
'icon' => 'icon-google',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
// 'instagram' => [
|
||||
// 'developers' => 'https://www.instagram.com/developer/',
|
||||
// 'icon' => 'icon-instagram',
|
||||
// 'enabled' => false,
|
||||
// 'mock' => false,
|
||||
// ],
|
||||
'microsoft' => [
|
||||
'developers' => 'https://developer.microsoft.com/en-us/',
|
||||
'icon' => 'icon-windows',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
// 'twitter' => [
|
||||
// 'developers' => 'https://developer.twitter.com/',
|
||||
// 'icon' => 'icon-twitter',
|
||||
// 'enabled' => false,
|
||||
// 'mock' => false,
|
||||
// ],
|
||||
'linkedin' => [
|
||||
'developers' => 'https://developer.linkedin.com/',
|
||||
'icon' => 'icon-linkedin',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
'slack' => [
|
||||
'developers' => 'https://api.slack.com/',
|
||||
'icon' => 'icon-slack',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
'dropbox' => [
|
||||
'developers' => 'https://www.dropbox.com/developers/documentation',
|
||||
'icon' => 'icon-dropbox',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
// 'apple' => [
|
||||
// 'developers' => 'https://developer.apple.com/',
|
||||
// 'icon' => 'icon-apple',
|
||||
// 'enabled' => false,
|
||||
// 'mock' => false,
|
||||
// ],
|
||||
'amazon' => [
|
||||
'developers' => 'https://developer.amazon.com/apps-and-games/services-and-apis',
|
||||
'icon' => 'icon-amazon',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
'vk' => [
|
||||
'developers' => 'https://vk.com/dev',
|
||||
'icon' => 'icon-vk',
|
||||
'enabled' => true,
|
||||
'mock' => false,
|
||||
],
|
||||
|
||||
// Keep Last
|
||||
'mock' => [
|
||||
'developers' => 'https://appwrite.io',
|
||||
'icon' => 'icon-appwrite',
|
||||
'enabled' => true,
|
||||
'mock' => true,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -433,8 +433,6 @@ $utopia->get('/v1/auth/login/oauth/callback/:provider/:projectId')
|
|||
->desc('OAuth Callback')
|
||||
->label('error', __DIR__.'/../../views/general/error.phtml')
|
||||
->label('scope', 'auth')
|
||||
->label('abuse-limit', 50)
|
||||
->label('abuse-key', 'ip:{ip}')
|
||||
->label('docs', false)
|
||||
->param('projectId', '', function () { return new Text(1024); }, 'Project unique ID')
|
||||
->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider')
|
||||
|
|
|
@ -6,6 +6,7 @@ use Utopia\Validator\Numeric;
|
|||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\ArrayList;
|
||||
use Storage\Validators\File;
|
||||
use Utopia\Validator\Host;
|
||||
|
||||
$result = [];
|
||||
|
||||
|
@ -218,6 +219,65 @@ $utopia->get('/v1/mock/tests/general/empty')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/oauth/login')
|
||||
->desc('Mock an OAuth login route')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
->param('client_id', '', function () { return new Text(100); }, 'OAuth Client ID.')
|
||||
->param('redirect_uri', '', function () { return new Host(['http://localhost']); }, 'OAuth Redirect URI.') // Important to deny an open redirect attack
|
||||
->param('scope', '', function () { return new Text(100); }, 'OAuth scope list.')
|
||||
->param('state', '', function () { return new Text(100); }, 'OAuth state.')
|
||||
->action(
|
||||
function ($clientId, $redirectURI, $scope, $state) use ($response) {
|
||||
$response->redirect($redirectURI);
|
||||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/oauth/token')
|
||||
->desc('Mock an OAuth login route')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
->param('client_id', '', function () { return new Text(100); }, 'OAuth Client ID.')
|
||||
->param('redirect_uri', '', function () { return new Host(['http://localhost']); }, 'OAuth Redirect URI.')
|
||||
->param('client_secret', '', function () { return new Text(100); }, 'OAuth scope list.')
|
||||
->param('code', '', function () { return new Text(100); }, 'OAuth state.')
|
||||
->action(
|
||||
function ($clientId, $redirectURI, $clientSecret, $code) use ($response) {
|
||||
if($clientId != '1') {
|
||||
throw new Exception('Invalid client ID');
|
||||
}
|
||||
|
||||
if($clientSecret != 'secret') {
|
||||
throw new Exception('Invalid client secret');
|
||||
}
|
||||
|
||||
if($code != 'abcdef') {
|
||||
throw new Exception('Invalid token');
|
||||
}
|
||||
|
||||
$response->json(['access_token' => '123456']);
|
||||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/oauth/user')
|
||||
->desc('Mock an OAuth user route')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
->param('token', '', function () { return new Text(100); }, 'OAuth Access Token.')
|
||||
->action(
|
||||
function ($token) use ($response) {
|
||||
if($token != '123456') {
|
||||
throw new Exception('Invalid token');
|
||||
}
|
||||
|
||||
$response->json([
|
||||
'id' => 1,
|
||||
'name' => 'User Name',
|
||||
'email' => 'user@localhost',
|
||||
]);
|
||||
}
|
||||
);
|
||||
|
||||
$utopia->shutdown(function() use ($response, $request, &$result, $utopia) {
|
||||
|
||||
$route = $utopia->match($request);
|
||||
|
|
|
@ -7,6 +7,7 @@ use Utopia\Abuse\Adapters\TimeLimit;
|
|||
global $utopia, $request, $response, $register, $user, $project;
|
||||
|
||||
$utopia->init(function () use ($utopia, $request, $response, $register, $user, $project) {
|
||||
|
||||
$route = $utopia->match($request);
|
||||
|
||||
/*
|
||||
|
|
|
@ -318,7 +318,10 @@ $providers = $this->getParam('providers', []);
|
|||
data-param-project-id="{{router.params.project}}"
|
||||
data-scope="console">
|
||||
<ul class="list">
|
||||
<?php foreach ($providers as $provider => $data): if (isset($data['enabled']) && !$data['enabled']) { continue; } ?>
|
||||
<?php foreach ($providers as $provider => $data):
|
||||
if (isset($data['enabled']) && !$data['enabled']) { continue; }
|
||||
if (isset($data['mock']) && $data['mock']) { continue; }
|
||||
?>
|
||||
<li class="clear <?php echo (isset($data['enabled']) && !$data['enabled']) ? 'dev-feature' : ''; ?>">
|
||||
<div data-ui-modal class="modal close" data-button-text="Settings" data-button-class="pull-end">
|
||||
<button type="button" class="close pull-end" data-ui-modal-close=""><i class="icon-cancel"></i></button>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
The Teams service allows you to group users of your project and to enable them to share read and write access to your project resources, such as database documents or storage files.
|
||||
|
||||
The teams' service allows you to group users of your project and to enable them to share [read and write](/docs/permissions) access to your project resources, such as database documents or storage files.
|
||||
|
||||
Each user who creates a team becomes the team owner and can delegate the ownership role by inviting a new team member. Only team owners can invite new users to their team.
|
123
src/Auth/OAuth/Mock.php
Normal file
123
src/Auth/OAuth/Mock.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
namespace Auth\OAuth;
|
||||
|
||||
use Auth\OAuth;
|
||||
|
||||
class Mock extends OAuth
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $version = 'v1';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $user = [];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'mock';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLoginURL():string
|
||||
{
|
||||
return 'http://localhost/'.$this->version.'/oauth?client_id='.urlencode($this->appID).'&redirect_uri='.urlencode($this->callback).'&scope=email&state='.urlencode(json_encode($this->state));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessToken(string $code):string
|
||||
{
|
||||
$accessToken = $this->request(
|
||||
'GET',
|
||||
'http://localhost/'.$this->version.'/oauth/token?'.
|
||||
'client_id='.urlencode($this->appID).
|
||||
'&redirect_uri='.urlencode($this->callback).
|
||||
'&client_secret='.urlencode($this->appSecret).
|
||||
'&code='.urlencode($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['id'])) {
|
||||
return $user['id'];
|
||||
}
|
||||
|
||||
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['name'])) {
|
||||
return $user['name'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getUser(string $accessToken):array
|
||||
{
|
||||
if (empty($this->user)) {
|
||||
$user = $this->request('GET', 'http://localhost/'.$this->version.'/oauth/user?token='.urlencode($accessToken));
|
||||
|
||||
$this->user = json_decode($user, true);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue