Skip to content

Commit 92b8497

Browse files
committed
Instalar y configurar php-open-source-saver/jwt-auth
1 parent e7f60a1 commit 92b8497

File tree

5 files changed

+654
-3
lines changed

5 files changed

+654
-3
lines changed

app/Models/User.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
77
use Illuminate\Foundation\Auth\User as Authenticatable;
88
use Illuminate\Notifications\Notifiable;
9+
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
910

10-
class User extends Authenticatable
11+
class User extends Authenticatable implements JWTSubject
1112
{
1213
/** @use HasFactory<\Database\Factories\UserFactory> */
1314
use HasFactory, Notifiable;
@@ -45,4 +46,24 @@ protected function casts(): array
4546
'password' => 'hashed',
4647
];
4748
}
49+
50+
/**
51+
* Get the identifier that will be stored in the subject claim of the JWT.
52+
*
53+
* @return mixed
54+
*/
55+
public function getJWTIdentifier()
56+
{
57+
return $this->getKey();
58+
}
59+
60+
/**
61+
* Return a key value array, containing any custom claims to be added to the JWT.
62+
*
63+
* @return array
64+
*/
65+
public function getJWTCustomClaims()
66+
{
67+
return [];
68+
}
4869
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"php": "^8.2",
1313
"dedoc/scramble": "^0.13.10",
1414
"laravel/framework": "^12.0",
15-
"laravel/tinker": "^2.10.1"
15+
"laravel/tinker": "^2.10.1",
16+
"php-open-source-saver/jwt-auth": "^2.8"
1617
},
1718
"require-dev": {
1819
"fakerphp/faker": "^1.23",

composer.lock

Lines changed: 305 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/auth.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
*/
3737

3838
'guards' => [
39+
'api' => [
40+
'driver' => 'jwt',
41+
'provider' => 'users',
42+
],
3943
'web' => [
4044
'driver' => 'session',
4145
'provider' => 'users',

0 commit comments

Comments
 (0)