Commit 0c5b963f authored by Viral Solani's avatar Viral Solani

- Get custom claims with latest jwt version (require composer update)

parent 341ff697
......@@ -31,48 +31,6 @@ class AuthController extends APIController
return $this->throwValidation($validation->messages()->first());
}
$credentials = $request->only('email', 'password');
$user = User::where('email', $credentials['email'])->firstOrFail();
if (!Hash::check($credentials['password'], $user->password)) {
return $this->throwValidation('invalid_credentials');
}
try {
$customClaims = [
'id' => $user->id,
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'email' => $user->email,
'confirmed' => $user->confirmed,
'registered_at' => $user->created_at->toIso8601String(),
'last_updated_at' => $user->updated_at->toIso8601String(),
];
$token = JWTAuth::fromUser($user, $customClaims);
} catch (JWTException $e) {
return $this->respondInternalError($e->getMessage());
}
return $this->respond([
'message' => trans('api.messages.login.success'),
'token' => $token,
]);
}
/*public function login(Request $request)
{
$validation = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required|min:4',
]);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
$credentials = $request->only(['email', 'password']);
try {
......@@ -87,7 +45,7 @@ class AuthController extends APIController
'message' => trans('api.messages.login.success'),
'token' => $token,
]);
}*/
}
/**
* Log the user out (Invalidate the token).
......
......@@ -86,6 +86,14 @@ class User extends Authenticatable implements JWTSubject
*/
public function getJWTCustomClaims()
{
return [];
return [
'id' => $this->id,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'email' => $this->email,
'confirmed' => $this->confirmed,
'registered_at' => $this->created_at->toIso8601String(),
'last_updated_at' => $this->updated_at->toIso8601String(),
];
}
}
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "10c3915573d2705afb9d125425e23680",
"content-hash": "bc9d94beb0a4b88c5eaee8a9a2238bea",
"packages": [
{
"name": "arcanedev/log-viewer",
......@@ -3605,16 +3605,16 @@
},
{
"name": "tymon/jwt-auth",
"version": "1.0.0-rc.2",
"version": "dev-develop",
"source": {
"type": "git",
"url": "https://github.com/tymondesigns/jwt-auth.git",
"reference": "d5220f6a84cbb8300f6f2f0f20aa908d072b4e4b"
"reference": "2b79229235d83523a05069ccb9c97cd5ec0b8123"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tymondesigns/jwt-auth/zipball/d5220f6a84cbb8300f6f2f0f20aa908d072b4e4b",
"reference": "d5220f6a84cbb8300f6f2f0f20aa908d072b4e4b",
"url": "https://api.github.com/repos/tymondesigns/jwt-auth/zipball/2b79229235d83523a05069ccb9c97cd5ec0b8123",
"reference": "2b79229235d83523a05069ccb9c97cd5ec0b8123",
"shasum": ""
},
"require": {
......@@ -3676,7 +3676,7 @@
"jwt",
"laravel"
],
"time": "2018-02-07T20:55:14+00:00"
"time": "2018-03-10T22:14:03+00:00"
},
{
"name": "unisharp/laravel-filemanager",
......@@ -6089,7 +6089,7 @@
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"tymon/jwt-auth": 5
"tymon/jwt-auth": 20
},
"prefer-stable": false,
"prefer-lowest": false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment