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

custom claim not working as expected #1388

Closed
jmdavid opened this issue Nov 14, 2017 · 6 comments
Closed

custom claim not working as expected #1388

jmdavid opened this issue Nov 14, 2017 · 6 comments

Comments

@jmdavid
Copy link

jmdavid commented Nov 14, 2017

Hello,

based on documentation, the following code is supposed to work:
$credentials = $request->only('email', 'password'); $customClaims = ['sCustomercode' => '1234', 'sActivesessionID' => 'abcd']; if (!$token = app('auth')->guard($this->guard)->attempt($credentials, $customClaims)) { return response()->json(['error' => 'invalid_credentials'], 401); }

but when token is decoded, I have no custom properties.

The only way for now is:
$token = JWTAuth::fromUser($user, $customClaims); $payload = JWTFactory::sCustomercode('1234')->sActivesessionID('1234')->sVerification('abcd')->make(); $token = JWTAuth::encode($payload)->get();
It is more intuitive to provide an array in attempt(), is it a bug or the feature changed without refreshing the documentation?

Thanks.

@ulisescarreonalvarez
Copy link

I added the claims through User model.

@axul
Copy link

axul commented Dec 15, 2017

I'm having the same issue, I need different types of tokens, with custom exp dates. Adding hte claims through User model is not a solution

@jmdavid
Copy link
Author

jmdavid commented Feb 13, 2018

@tymondesigns
Hey, any update on that?

@tymondesigns
Copy link
Owner

@jmdavid
Copy link
Author

jmdavid commented Feb 13, 2018

Still not working with LUMEN.

$token = app('auth')->attempt($credentials)
or
$token = app('auth')->guard('api')->attempt($credentials)

Always return false.

@jmdavid
Copy link
Author

jmdavid commented Feb 13, 2018

Just to clarify:

$credentials = $request->only('email', 'password');
$user = User::where('email', $request->get('email'))->first();
$valid = Hash::check($request->get('password'), $user->getAttribute('password'));

$valid is true.

$test = JWTAuth::attempt($credentials);

$test is false.

So there is something with attempt.

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

4 participants