diff --git a/.gitignore b/.gitignore index 187e79cd..9729c46b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.lock build coverage.xml .phpunit.result.cache +.idea diff --git a/config/config.php b/config/config.php index f83234d1..2f25c059 100644 --- a/config/config.php +++ b/config/config.php @@ -11,6 +11,17 @@ return [ + /* + |-------------------------------------------------------------------------- + | JWT Authentication Key + |-------------------------------------------------------------------------- + | + | You can define a specific key to return user data from the JWT + | + */ + + 'identifier' => env('JWT_IDENTIFIER', 'sub'), + /* |-------------------------------------------------------------------------- | JWT Authentication Secret diff --git a/src/JWT.php b/src/JWT.php index a958071c..a7074db6 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -250,7 +250,7 @@ protected function getClaimsArray(JWTSubject $subject) protected function getClaimsForSubject(JWTSubject $subject) { return array_merge([ - 'sub' => $subject->getJWTIdentifier(), + config('jwt.identifier') => $subject->getJWTIdentifier(), ], $this->lockSubject ? ['prv' => $this->hashSubjectModel($subject)] : []); } diff --git a/src/JWTAuth.php b/src/JWTAuth.php index e8ab7272..bc65b3b5 100644 --- a/src/JWTAuth.php +++ b/src/JWTAuth.php @@ -60,7 +60,7 @@ public function attempt(array $credentials) */ public function authenticate() { - $id = $this->getPayload()->get('sub'); + $id = $this->getPayload()->get(config('jwt.identifier')); if (! $this->auth->byId($id)) { return false; diff --git a/src/JWTGuard.php b/src/JWTGuard.php index 31957072..94ac8cdc 100644 --- a/src/JWTGuard.php +++ b/src/JWTGuard.php @@ -78,7 +78,7 @@ public function user() ($payload = $this->jwt->check(true)) && $this->validateSubject() ) { - return $this->user = $this->provider->retrieveById($payload['sub']); + return $this->user = $this->provider->retrieveById($payload[config('jwt.identifier')]); } }