Skip to content

Instantly share code, notes, and snippets.

@viralsolani
Created March 11, 2018 19:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viralsolani/f18e59046d4494a08d6947c8be6d9f77 to your computer and use it in GitHub Desktop.
Save viralsolani/f18e59046d4494a08d6947c8be6d9f77 to your computer and use it in GitHub Desktop.
How to set custom payload/Claims on Laravel JWT?
<?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(),
];
}
}
@kattykay50675
Copy link

This was helpful thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment