Jwt-auth: no json output for manually generated token

Created on 3 Aug 2016  路  5Comments  路  Source: tymondesigns/jwt-auth

Hi, I've been trying to generate a token based on a given data, like the given code below

`class UserController extends Controller
{

/**
 * route: /api/users
 */
public function index()
{
    $payload = JWTFactory::sub(123)->aud('foo')->foo(['bar' => 'baz'])->make();

    $token = JWTAuth::encode($payload);

    return response()->json(compact('token'));
}`

however im getting an empty output like this:

{ "token": [] }

seems like its not allowing some characters on a json payload, any help would be apreciated thanks.

Most helpful comment

this should be specified in the wiki as well

particularly here -> Creating a Token based on anything you like

All 5 comments

compact('payload') would generate a result in the form 'payload' => $payload; there would be no key named "token". Are you sure this is the code you're running?

seems like its not allowing some characters on a json payload

Why have you come to this conclusion? Are there some characters that work and some that don't?

Thanks, yeah, sorry I mean compact ('token') , edited now, tried on var dumping the $token and im getting a random string as expected.

Got it, im plugging a Tymon\JWTAuth\Token object directly to an array value, it should be this
way:

$token = JWTAuth::encode($payload)->get();

to return a token as a string.

this should be specified in the wiki as well

particularly here -> Creating a Token based on anything you like

Yup same issue, my token was empty without get()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phamduong picture phamduong  路  3Comments

mihailo-misic picture mihailo-misic  路  3Comments

loic-lopez picture loic-lopez  路  3Comments

johncloud200 picture johncloud200  路  3Comments

hfalucas picture hfalucas  路  3Comments