1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00

group auth methods

This commit is contained in:
Damodar Lohani 2021-08-06 13:27:31 +05:45
parent 2459844e97
commit 851a00e438
4 changed files with 36 additions and 26 deletions

View file

@ -166,6 +166,17 @@ $collections = [
'array' => false,
'filters' => ['json'],
],
[
'$id' => 'auths',
'type' => Database::VAR_STRING,
'format' => '',
'size' => 16384,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => ['json'],
],
[
'$id' => 'platforms',
'type' => Database::VAR_STRING,
@ -1427,18 +1438,4 @@ foreach ($providers as $index => $provider) {
];
}
foreach ($auth as $index => $method) {
$collections['projects']['attributes'][] = [
'$id' => $method['key'] ?? '',
'type' => Database::VAR_BOOLEAN,
'format' => '',
'size' => 0,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
];
}
return $collections;

View file

@ -69,6 +69,12 @@ App::post('/v1/projects')
if ($team->isEmpty()) {
throw new Exception('Team not found', 404);
}
$auth = Config::getParam('auth', []);
$auths = [];
foreach ($auth as $index => $method) {
$auths[$method['key'] ?? ''] = true;
}
$project = $dbForConsole->createDocument('projects', new Document([
'$read' => ['team:' . $teamId],
@ -90,11 +96,7 @@ App::post('/v1/projects')
'webhooks' => [],
'keys' => [],
'domains' => [],
'usersAuthEmailPassword' => true,
'usersAuthAnonymous' => true,
'usersAuthInvites' => true,
'usersAuthJWT' => true,
'usersAuthPhone' => true,
'auths' => $auths,
]));
$collections = Config::getParam('collections2', []); /** @var array $collections */
@ -570,9 +572,10 @@ App::patch('/v1/projects/:projectId/auth/:method')
throw new Exception('Project not found', 404);
}
$dbForConsole->updateDocument('projects', $project->getId(), $project
->setAttribute($authKey, $status)
);
$auths = $project->getAttribute('auths', []);
$auths[$authKey] = $status;
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project->setAttribute('auths', $auths));
$response->dynamic($project, Response::MODEL_PROJECT);
});

View file

@ -137,27 +137,28 @@ App::init(function ($utopia, $request, $response, $project, $user) {
return;
}
$auths = $project->getAttribute('auths', []);
switch ($route->getLabel('auth.type', '')) {
case 'emailPassword':
if($project->getAttribute('usersAuthEmailPassword', true) === false) {
if(($auths['usersAuthEmailPassword'] ?? true) === false) {
throw new Exception('Email / Password authentication is disabled for this project', 501);
}
break;
case 'anonymous':
if($project->getAttribute('usersAuthAnonymous', true) === false) {
if(($auths['usersAuthAnonymous'] ?? true) === false) {
throw new Exception('Anonymous authentication is disabled for this project', 501);
}
break;
case 'invites':
if($project->getAttribute('usersAuthInvites', true) === false) {
if(($auths['usersAuthInvites'] ?? true) === false) {
throw new Exception('Invites authentication is disabled for this project', 501);
}
break;
case 'jwt':
if($project->getAttribute('usersAuthJWT', true) === false) {
if(($auths['usersAuthJWT'] ?? true) === false) {
throw new Exception('JWT authentication is disabled for this project', 501);
}
break;

View file

@ -225,6 +225,15 @@ class Project extends Model
$document->setAttribute('serviceStatusFor'.ucfirst($key), $value);
}
$authValues = $document->getAttribute('auths',[]);
$auth = Config::getParam('auth', []);
foreach ($auth as $index => $method) {
$key = $method['key'] ?? '';
$value = $authValues[$key] ?? true;
$document->setAttribute($key, $value);
}
return $document;
}
}