Created
March 11, 2018 19:13
-
-
Save viralsolani/f18e59046d4494a08d6947c8be6d9f77 to your computer and use it in GitHub Desktop.
How to set custom payload/Claims on Laravel JWT?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models\Access\User; | |
use Illuminate\Foundation\Auth\User as Authenticatable; | |
use Tymon\JWTAuth\Contracts\JWTSubject; | |
/** | |
* Class User. | |
*/ | |
class User extends Authenticatable implements JWTSubject | |
{ | |
/** | |
* Get the identifier that will be stored in the subject claim of the JWT. | |
* | |
* @return mixed | |
*/ | |
public function getJWTIdentifier() | |
{ | |
return $this->getKey(); | |
} | |
/** | |
* Return a key value array, containing any custom claims to be added to the JWT. | |
* | |
* @return array | |
*/ | |
public function getJWTCustomClaims() | |
{ | |
return [ | |
'id' => $this->id, | |
'first_name' => $this->first_name, | |
'last_name' => $this->last_name, | |
'email' => $this->email, | |
'picture' => $this->getPicture(), | |
'confirmed' => $this->confirmed, | |
'registered_at' => $this->created_at->toIso8601String(), | |
'last_updated_at' => $this->updated_at->toIso8601String(), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was helpful thank you