Skip to content

Commit 229fbfe

Browse files
update jwt lib
1 parent 4c309ff commit 229fbfe

File tree

9 files changed

+395
-377
lines changed

9 files changed

+395
-377
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Make sure you have installed **Node** and [**Yarn**](https://yarnpkg.com/) (late
4444
* `touch database/database.sqlite` to create an empty database file
4545
* `cp .env.example .env` to configure installation
4646
* `php artisan key:generate` to generate unique key for the project
47+
* `php artisan jwt:secret` to generate unique key for the project
4748
* `php artisan migrate` to create all the tables
4849
* `php artisan db:seed` to fill the tables with fake data
4950
* `php artisan serve` to serve application on localhost:8000

webservice/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ MAIL_ENCRYPTION=null
3333
PUSHER_APP_ID=
3434
PUSHER_KEY=
3535
PUSHER_SECRET=
36+
37+
JWT_SECRET=

webservice/app/Http/Controllers/LoginController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Http\Request;
66
use Auth;
7-
use JWTAuth;
87
use JWTException;
98

109
class LoginController extends Controller
@@ -16,15 +15,15 @@ public function login(Request $request)
1615

1716
try {
1817
// attempt to verify the credentials and create a token for the user
19-
if (! $token = JWTAuth::attempt($credentials)) {
18+
if (!$token = Auth::guard('api')->attempt($credentials)) {
2019
return response()->json(['messages' => ['E-mail ou senha não conferem']], 401);
2120
}
2221
} catch (JWTException $e) {
2322
// something went wrong whilst attempting to encode the token
2423
return response()->json(['messages' => ['Não foi possível gerar o token']], 500);
2524
}
2625

27-
$user = Auth::user();
26+
$user = Auth::guard('api')->user();
2827

2928
// all good so return the token
3029
return response()->json(compact('token', 'user'));

webservice/app/User.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use Illuminate\Notifications\Notifiable;
66
use Illuminate\Foundation\Auth\User as Authenticatable;
7+
use Tymon\JWTAuth\Contracts\JWTSubject;
78

8-
class User extends Authenticatable
9+
class User extends Authenticatable implements JWTSubject
910
{
1011
use Notifiable;
1112

@@ -26,4 +27,14 @@ class User extends Authenticatable
2627
protected $hidden = [
2728
'password', 'remember_token',
2829
];
30+
31+
public function getJWTIdentifier()
32+
{
33+
return $this->id;
34+
}
35+
36+
public function getJWTCustomClaims()
37+
{
38+
return [];
39+
}
2940
}

webservice/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
"keywords": ["framework", "laravel"],
55
"license": "MIT",
66
"type": "project",
7+
"minimum-stability": "dev",
8+
"prefer-stable": true,
79
"require": {
810
"php": ">=5.6.4",
911
"laravel/framework": "5.3.*",
1012
"barryvdh/laravel-cors": "^0.8.2",
11-
"tymon/jwt-auth": "0.5.*",
13+
"tymon/jwt-auth": "~1.0",
1214
"predis/predis": "^1.1"
1315
},
1416
"require-dev": {

0 commit comments

Comments
 (0)