mirror of
https://gitlab.linphone.org/BC/public/flexisip-account-manager.git
synced 2026-01-17 01:58:07 +00:00
Fix FLEXIAPI-264 Add -k|api_key_ip parameter to accounts:create-admin-account...
This commit is contained in:
parent
1b1df7eef8
commit
1ba3834f40
7 changed files with 13 additions and 12 deletions
|
|
@ -15,6 +15,7 @@ v1.7
|
|||
- Fix FLEXIAPI-257 Return a more coherent message when search API endpoints returns a 404
|
||||
- Fix FLEXIAPI-260 Return 404 and not 403 if the contact is already in the list or missing when removing it
|
||||
- Fix FLEXIAPI-262 Bypass the JWT auth if we have an API Key
|
||||
- Fix FLEXIAPI-264 Add -k|api_key_ip parameter to accounts:create-admin-account to set/clear the related API Key restriction
|
||||
|
||||
v1.6
|
||||
----
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ Create or update a Space, required to then create accounts afterward. The `super
|
|||
|
||||
### Create an admin account
|
||||
|
||||
Create an admin account, an API Key will also be generated along the way, it might expire after a while.
|
||||
Create an admin account, an API Key will also be generated along the way, it might expire after a while (regarding the API Key expiration policy). An empty `api_key_ip` will remove the IP restriction on the key.
|
||||
|
||||
If no parameters are put, a default admin account will be created.
|
||||
|
||||
php artisan accounts:create-admin-account {-u|username=} {-p|password=} {-d|domain=}
|
||||
php artisan accounts:create-admin-account {-u|username=} {-p|password=} {-d|domain=} {-k|api_key_ip=}
|
||||
|
||||
### Clear the expired API Keys
|
||||
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ class Account extends Authenticatable
|
|||
return ($this->activationExpiration && $this->activationExpiration->isExpired());
|
||||
}
|
||||
|
||||
public function generateApiKey(?Request $request = null): ApiKey
|
||||
public function generateApiKey(?string $ip = null): ApiKey
|
||||
{
|
||||
$this->apiKey()->delete();
|
||||
|
||||
|
|
@ -360,7 +360,7 @@ class Account extends Authenticatable
|
|||
$apiKey->account_id = $this->id;
|
||||
$apiKey->last_used_at = Carbon::now();
|
||||
$apiKey->key = Str::random(40);
|
||||
$apiKey->ip = $request ? $request->ip() : '127.0.0.1';
|
||||
$apiKey->ip = $ip;
|
||||
$apiKey->save();
|
||||
|
||||
return $apiKey;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ use App\Space;
|
|||
|
||||
class CreateAdminAccount extends Command
|
||||
{
|
||||
protected $signature = 'accounts:create-admin-account {--u|username=} {--p|password=} {--d|domain=}';
|
||||
protected $description = 'Create an admin account';
|
||||
protected $signature = 'accounts:create-admin-account {--u|username=} {--p|password=} {--d|domain=} {--k|api_key_ip=}';
|
||||
protected $description = 'Create an admin account and generate an API Key';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
|
@ -90,10 +90,10 @@ class CreateAdminAccount extends Command
|
|||
$account->created_at = Carbon::now()->subYears(3);
|
||||
$account->save();
|
||||
|
||||
$account->generateApiKey();
|
||||
$account->generateApiKey(ip: $this->option('api_key_ip') ?? null);
|
||||
$account->updatePassword($password);
|
||||
|
||||
$this->info('Admin test account created: "' . $username . '@' . $domain . '" | Password: "' . $password . '" | API Key: "' . $account->apiKey->key . '"');
|
||||
$this->info('Admin test account created: "' . $username . '@' . $domain . '" | Password: "' . $password . '" | API Key: "' . $account->apiKey->key . '" (valid on ' . ($account->apiKey->ip ?? 'any') . ' ip)');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class ApiKeyController extends Controller
|
|||
public function update(Request $request)
|
||||
{
|
||||
$account = $request->user();
|
||||
$account->generateApiKey($request);
|
||||
$account->generateApiKey($request->ip());
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class ApiKeyController extends Controller
|
|||
public function generate(Request $request)
|
||||
{
|
||||
$account = $request->user();
|
||||
$account->generateApiKey($request);
|
||||
$account->generateApiKey($request->ip());
|
||||
|
||||
$account->refresh();
|
||||
Cookie::queue('x-api-key', $account->apiKey->key, config('app.api_key_expiration_minutes'));
|
||||
|
|
@ -42,7 +42,7 @@ class ApiKeyController extends Controller
|
|||
$authToken = AuthToken::where('token', $token)->valid()->firstOrFail();
|
||||
|
||||
if ($authToken->account) {
|
||||
$authToken->account->generateApiKey($request);
|
||||
$authToken->account->generateApiKey($request->ip());
|
||||
|
||||
$authToken->account->refresh();
|
||||
Cookie::queue('x-api-key', $authToken->account->apiKey->key, config('app.api_key_expiration_minutes'));
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
{{ $account->apiKey->last_used_at }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $account->apiKey->ip ?? '-' }}
|
||||
{{ $account->apiKey->ip ?? '*' }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $account->apiKey->requests }}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue