Skip to content

Commit 98b969e

Browse files
committedNov 14, 2020
jwt
1 parent 06373f0 commit 98b969e

File tree

17 files changed

+25860
-343
lines changed

17 files changed

+25860
-343
lines changed
 

Diff for: ‎app/Http/Controllers/Auth/LoginController.php

+16
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,20 @@ public function __construct()
3737
{
3838
$this->middleware('guest')->except('logout');
3939
}
40+
41+
/**
42+
* Get the token array structure.
43+
*
44+
* @param string $token
45+
*
46+
* @return \Illuminate\Http\JsonResponse
47+
*/
48+
protected function respondWithToken($token)
49+
{
50+
return response()->json([
51+
'access_token' => $token,
52+
'token_type' => 'bearer',
53+
'expires_in' => auth()->factory()->getTTL() * 60
54+
]);
55+
}
4056
}

Diff for: ‎app/Http/Controllers/HomeController.php

+1-16
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,7 @@
66

77
class HomeController extends Controller
88
{
9-
/**
10-
* Create a new controller instance.
11-
*
12-
* @return void
13-
*/
14-
public function __construct()
15-
{
16-
$this->middleware('auth');
17-
}
18-
19-
/**
20-
* Show the application dashboard.
21-
*
22-
* @return \Illuminate\Contracts\Support\Renderable
23-
*/
24-
public function index()
9+
public function __invoke()
2510
{
2611
return view('home');
2712
}

Diff for: ‎app/User.php renamed to ‎app/Models/User.php

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22

3-
namespace App;
3+
namespace App\Models;
44

55
use Illuminate\Contracts\Auth\MustVerifyEmail;
66
use Illuminate\Foundation\Auth\User as Authenticatable;
77
use Illuminate\Notifications\Notifiable;
8+
use Tymon\JWTAuth\Contracts\JWTSubject;
89

9-
class User extends Authenticatable
10+
class User extends Authenticatable implements JWTSubject
1011
{
1112
use Notifiable;
1213

@@ -36,4 +37,24 @@ class User extends Authenticatable
3637
protected $casts = [
3738
'email_verified_at' => 'datetime',
3839
];
40+
41+
/**
42+
* Get the identifier that will be stored in the subject claim of the JWT.
43+
*
44+
* @return mixed
45+
*/
46+
public function getJWTIdentifier()
47+
{
48+
return $this->getKey();
49+
}
50+
51+
/**
52+
* Return a key value array, containing any custom claims to be added to the JWT.
53+
*
54+
* @return array
55+
*/
56+
public function getJWTCustomClaims()
57+
{
58+
return [];
59+
}
3960
}

Diff for: ‎app/Providers/AppServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public function register()
2323
*/
2424
public function boot()
2525
{
26-
//
26+
\Illuminate\Support\Facades\Schema::defaultStringLength(191);
2727
}
2828
}

Diff for: ‎composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"guzzlehttp/guzzle": "^6.3",
1515
"laravel/framework": "^7.0",
1616
"laravel/tinker": "^2.0",
17-
"laravel/ui": "^2.0"
17+
"laravel/ui": "^2.0",
18+
"tymon/jwt-auth": "^1.0"
1819
},
1920
"require-dev": {
2021
"facade/ignition": "^2.0",

0 commit comments

Comments
 (0)
Please sign in to comment.