Add JWT refreshing
This commit is contained in:
parent
0486ddc5a1
commit
b70004ec0f
|
|
@ -267,4 +267,9 @@ class AuthController extends Controller
|
||||||
Auth::guard('api')->logout();
|
Auth::guard('api')->logout();
|
||||||
return response('', 204);
|
return response('', 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function apiRefresh()
|
||||||
|
{
|
||||||
|
return json(['token' => Auth::guard('api')->refresh()]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
Route::prefix('auth')->group(function ($route) {
|
Route::prefix('auth')->group(function ($route) {
|
||||||
$route->post('login', 'AuthController@apiLogin');
|
$route->post('login', 'AuthController@apiLogin');
|
||||||
$route->post('logout', 'AuthController@apiLogout')->middleware('auth.jwt');
|
$route->post('logout', 'AuthController@apiLogout')->middleware('auth.jwt');
|
||||||
|
$route->post('refresh', 'AuthController@apiRefresh')->middleware('auth.jwt');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('user')->middleware('auth.jwt')->group(function ($route) {
|
Route::prefix('user')->middleware('auth.jwt')->group(function ($route) {
|
||||||
|
|
|
||||||
|
|
@ -552,4 +552,19 @@ class AuthControllerTest extends TestCase
|
||||||
'Authorization' => "Bearer $token"
|
'Authorization' => "Bearer $token"
|
||||||
])->assertStatus(204);
|
])->assertStatus(204);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testApiRefresh()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$user->changePassword('12345678');
|
||||||
|
$token = $this->postJson('/api/auth/login', [
|
||||||
|
'email' => $user->email,
|
||||||
|
'password' => '12345678'
|
||||||
|
])->decodeResponseJson('token');
|
||||||
|
|
||||||
|
$token = $this->postJson('/api/auth/refresh', [], [
|
||||||
|
'Authorization' => "Bearer $token"
|
||||||
|
])->decodeResponseJson('token');
|
||||||
|
$this->assertTrue(is_string($token));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user