Skip to content

Commit ebd7bc6

Browse files
committed
Create GenerateAccessToken.php
1 parent 0d36bf7 commit ebd7bc6

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ProcessMaker\Console\Commands;
6+
7+
use Illuminate\Console\Command;
8+
use ProcessMaker\Models\User;
9+
10+
class GenerateAccessToken extends Command
11+
{
12+
protected $signature = 'processmaker:generate-access-token {username : The username of the user}';
13+
14+
protected $description = 'Generate an API access token for a user';
15+
16+
public function handle(): int
17+
{
18+
$user = User::where('username', $this->argument('username'))->first();
19+
20+
if (!$user) {
21+
return 1;
22+
}
23+
24+
$tokenResult = $user->createToken('api-user-token');
25+
$this->line($tokenResult->accessToken);
26+
27+
return 0;
28+
}
29+
}

0 commit comments

Comments
 (0)