5

I need help to figure out a issues. I am using lumen(laravel 5.1) for create web services for mobile app. I am using JWT for authentication and it returns a token.

First issue is that if i use same token from another system/device then it validated and returns requested information. I want that token should be valid only for that device/system from user get token.

Second issue is that i have added some custom claims in JWT token. I want to get custom claim value from token. I have found similar question Get custom claims from a JWT using Owin but didn't get how i use it in php.

Please help me to get solution.

Community
  • 1
  • 1
Karan
  • 2,102
  • 2
  • 22
  • 31

3 Answers3

12

I got solution. Here is solution may be help someone else

$payload = JWTAuth::parseToken()->getPayload();
// then either of
$payload->get('foo');
$payload['foo'];
Karan
  • 2,102
  • 2
  • 22
  • 31
0

I find a solution, this will help you.

 $token = JWTAuth::getToken(); 
 $payload = JWTAuth::decode($token);

 $validate = $payload->get('foo'); // return true or false

 if($validate) { 
  // some condition
 } else {
  // some condition
 }
Amit Sharma
  • 83
  • 12
0
        // SENDING:
        $user = User::first();

        $payload = [
            'foo' => 'bar'
        ];

        $guard = 'api'; // or web

        $token = auth($guard)->claims($payload)->login($user);

        // RECEIVING:
        $data = auth($guard)->payload()->get('foo');