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 ...@@ -31,48 +31,6 @@ class AuthController extends APIController
return $this->throwValidation($validation->messages()->first()); 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']); $credentials = $request->only(['email', 'password']);
try { try {
...@@ -87,7 +45,7 @@ class AuthController extends APIController ...@@ -87,7 +45,7 @@ class AuthController extends APIController
'message' => trans('api.messages.login.success'), 'message' => trans('api.messages.login.success'),
'token' => $token, 'token' => $token,
]); ]);
}*/ }
/** /**
* Log the user out (Invalidate the token). * Log the user out (Invalidate the token).
......
...@@ -86,6 +86,14 @@ class User extends Authenticatable implements JWTSubject ...@@ -86,6 +86,14 @@ class User extends Authenticatable implements JWTSubject
*/ */
public function getJWTCustomClaims() 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 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "10c3915573d2705afb9d125425e23680", "content-hash": "bc9d94beb0a4b88c5eaee8a9a2238bea",
"packages": [ "packages": [
{ {
"name": "arcanedev/log-viewer", "name": "arcanedev/log-viewer",
...@@ -3605,16 +3605,16 @@ ...@@ -3605,16 +3605,16 @@
}, },
{ {
"name": "tymon/jwt-auth", "name": "tymon/jwt-auth",
"version": "1.0.0-rc.2", "version": "dev-develop",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/tymondesigns/jwt-auth.git", "url": "https://github.com/tymondesigns/jwt-auth.git",
"reference": "d5220f6a84cbb8300f6f2f0f20aa908d072b4e4b" "reference": "2b79229235d83523a05069ccb9c97cd5ec0b8123"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/tymondesigns/jwt-auth/zipball/d5220f6a84cbb8300f6f2f0f20aa908d072b4e4b", "url": "https://api.github.com/repos/tymondesigns/jwt-auth/zipball/2b79229235d83523a05069ccb9c97cd5ec0b8123",
"reference": "d5220f6a84cbb8300f6f2f0f20aa908d072b4e4b", "reference": "2b79229235d83523a05069ccb9c97cd5ec0b8123",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -3676,7 +3676,7 @@ ...@@ -3676,7 +3676,7 @@
"jwt", "jwt",
"laravel" "laravel"
], ],
"time": "2018-02-07T20:55:14+00:00" "time": "2018-03-10T22:14:03+00:00"
}, },
{ {
"name": "unisharp/laravel-filemanager", "name": "unisharp/laravel-filemanager",
...@@ -6089,7 +6089,7 @@ ...@@ -6089,7 +6089,7 @@
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": { "stability-flags": {
"tymon/jwt-auth": 5 "tymon/jwt-auth": 20
}, },
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": 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