Skip to content

Commit 95bc7b4

Browse files
committed
feat: configure passport to use UUIDs
1 parent ea236b6 commit 95bc7b4

8 files changed

+200
-2
lines changed

app/Domain/Users/Models/User.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Illuminate\Database\Eloquent\Factories\HasFactory;
1010
use Illuminate\Foundation\Auth\User as Authenticatable;
1111
use Illuminate\Notifications\Notifiable;
12-
use Laravel\Sanctum\HasApiTokens;
12+
use Laravel\Passport\HasApiTokens;
1313

1414
class User extends Authenticatable
1515
{

config/passport.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Passport Guard
8+
|--------------------------------------------------------------------------
9+
|
10+
| Here you may specify which authentication guard Passport will use when
11+
| authenticating users. This value should correspond with one of your
12+
| guards that is already present in your "auth" configuration file.
13+
|
14+
*/
15+
16+
'guard' => 'web',
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Encryption Keys
21+
|--------------------------------------------------------------------------
22+
|
23+
| Passport uses encryption keys while generating secure access tokens for
24+
| your application. By default, the keys are stored as local files but
25+
| can be set via environment variables when that is more convenient.
26+
|
27+
*/
28+
29+
'private_key' => env('PASSPORT_PRIVATE_KEY'),
30+
31+
'public_key' => env('PASSPORT_PUBLIC_KEY'),
32+
33+
/*
34+
|--------------------------------------------------------------------------
35+
| Client UUIDs
36+
|--------------------------------------------------------------------------
37+
|
38+
| By default, Passport uses auto-incrementing primary keys when assigning
39+
| IDs to clients. However, if Passport is installed using the provided
40+
| --uuids switch, this will be set to "true" and UUIDs will be used.
41+
|
42+
*/
43+
44+
'client_uuids' => true,
45+
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Personal Access Client
49+
|--------------------------------------------------------------------------
50+
|
51+
| If you enable client hashing, you should set the personal access client
52+
| ID and unhashed secret within your environment file. The values will
53+
| get used while issuing fresh personal access tokens to your users.
54+
|
55+
*/
56+
57+
'personal_access_client' => [
58+
'id' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_ID'),
59+
'secret' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET'),
60+
],
61+
62+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::create('oauth_auth_codes', function (Blueprint $table) {
14+
$table->string('id', 100)->primary();
15+
$table->unsignedBigInteger('user_id')->index();
16+
$table->uuid('client_id');
17+
$table->text('scopes')->nullable();
18+
$table->boolean('revoked');
19+
$table->dateTime('expires_at')->nullable();
20+
});
21+
}
22+
23+
public function down(): void
24+
{
25+
Schema::dropIfExists('oauth_auth_codes');
26+
}
27+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::create('oauth_access_tokens', function (Blueprint $table) {
14+
$table->string('id', 100)->primary();
15+
$table->unsignedBigInteger('user_id')->nullable()->index();
16+
$table->uuid('client_id');
17+
$table->string('name')->nullable();
18+
$table->text('scopes')->nullable();
19+
$table->boolean('revoked');
20+
$table->timestamps();
21+
$table->dateTime('expires_at')->nullable();
22+
});
23+
}
24+
25+
public function down(): void
26+
{
27+
Schema::dropIfExists('oauth_access_tokens');
28+
}
29+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::create('oauth_refresh_tokens', function (Blueprint $table) {
14+
$table->string('id', 100)->primary();
15+
$table->string('access_token_id', 100)->index();
16+
$table->boolean('revoked');
17+
$table->dateTime('expires_at')->nullable();
18+
});
19+
}
20+
21+
public function down(): void
22+
{
23+
Schema::dropIfExists('oauth_refresh_tokens');
24+
}
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::create('oauth_clients', function (Blueprint $table) {
14+
$table->uuid('id')->primary();
15+
$table->unsignedBigInteger('user_id')->nullable()->index();
16+
$table->string('name');
17+
$table->string('secret', 100)->nullable();
18+
$table->string('provider')->nullable();
19+
$table->text('redirect');
20+
$table->boolean('personal_access_client');
21+
$table->boolean('password_client');
22+
$table->boolean('revoked');
23+
$table->timestamps();
24+
});
25+
}
26+
27+
public function down(): void
28+
{
29+
Schema::dropIfExists('oauth_clients');
30+
}
31+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::create('oauth_personal_access_clients', function (Blueprint $table) {
14+
$table->bigIncrements('id');
15+
$table->uuid('client_id');
16+
$table->timestamps();
17+
});
18+
}
19+
20+
public function down(): void
21+
{
22+
Schema::dropIfExists('oauth_personal_access_clients');
23+
}
24+
};

setup-dev.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if [ "$isFirstInstallation" = true ]; then
3030
runScript php artisan storage:link
3131

3232
echo "==[ Installing Laravel Passport"
33-
runScript php artisan passport:install
33+
runScript php artisan passport:install --uuids
3434
fi
3535

3636
echo "==[ Opening shell in PHP service"

0 commit comments

Comments
 (0)