Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How add custom Claims? #44

Closed
angelmartz opened this issue Feb 17, 2015 · 4 comments
Closed

How add custom Claims? #44

angelmartz opened this issue Feb 17, 2015 · 4 comments

Comments

@angelmartz
Copy link

I am trying with JWTAuth::encode();

Argument 1 passed to Tymon\JWTAuth\JWTManager::encode() must be an instance of Tymon\JWTAuth\Payload, array given

@tymondesigns
Copy link
Owner

which version are you using?

@tymondesigns
Copy link
Owner

It looks like you're probably using dev-laravel-5 ? If so..

You can pass an array of custom claims via the second parameter on the attempt() method, and also fromUser() as seen here. e.g.

$customClaims = ['foo' => 'bar', 'baz' => 'bob'];

$token = JWTAuth::fromUser(User::first(), $customClaims);

Alternatively if you are manually creating the token via the encode() method, then you will need to create a Payload instance as follows:

$customClaims = ['foo' => 'bar', 'baz' => 'bob'];

$payload = app('tymon.jwt.payload.factory')->make($customClaims);

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

@angelmartz
Copy link
Author

Yes I'm using dev-laravel-5

Thank you

@jgardezi
Copy link

jgardezi commented Jun 21, 2016

Can someone please have a look at this issue #771 its kind of similar.

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

The above gave you a private token string how do I get a public one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants