api(remote): update sftp auth controller

This commit is contained in:
Matthew Penner 2021-07-17 17:22:47 -06:00
parent f9114e2de0
commit 790f109e66
3 changed files with 10 additions and 3 deletions

View file

@ -70,8 +70,14 @@ class SftpAuthenticationController extends Controller
['username', '=', $connection['username']], ['username', '=', $connection['username']],
]); ]);
if ($request->input('type') === 'publicKey') {
$verified = true;
} else {
$verified = password_verify($request->input('password'), $user->password);
}
$server = $this->serverRepository->getByUuid($connection['server'] ?? ''); $server = $this->serverRepository->getByUuid($connection['server'] ?? '');
if (!password_verify($request->input('password'), $user->password) || $server->node_id !== $node->id) { if (!$verified || $server->node_id !== $node->id) {
$this->incrementLoginAttempts($request); $this->incrementLoginAttempts($request);
throw new HttpForbiddenException('Authorization credentials were not correct, please try again.'); throw new HttpForbiddenException('Authorization credentials were not correct, please try again.');
@ -88,9 +94,8 @@ class SftpAuthenticationController extends Controller
$server->validateCurrentState(); $server->validateCurrentState();
return new JsonResponse([ return new JsonResponse([
'ssh_keys' => $user->sshKeys->pluck('public_key')->toArray(),
'server' => $server->uuid, 'server' => $server->uuid,
// Deprecated, but still needed at the moment for Wings.
'token' => '',
'permissions' => $permissions ?? ['*'], 'permissions' => $permissions ?? ['*'],
]); ]);
} }

View file

@ -26,6 +26,7 @@ class SftpAuthenticationFormRequest extends FormRequest
return [ return [
'username' => 'required|string', 'username' => 'required|string',
'password' => 'required|string', 'password' => 'required|string',
'type' => 'required|in:password,publicKey'
]; ];
} }

View file

@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Route;
| |
*/ */
Route::post('/sftp/auth', 'SftpAuthenticationController'); Route::post('/sftp/auth', 'SftpAuthenticationController');
Route::put('/sftp/auth', 'SftpAuthenticationController@getSSHKeys');
Route::get('/servers', 'Servers\ServerDetailsController@list'); Route::get('/servers', 'Servers\ServerDetailsController@list');
Route::post('/servers/reset', 'Servers\ServerDetailsController@resetState'); Route::post('/servers/reset', 'Servers\ServerDetailsController@resetState');