Answer the question
In order to leave comments, you need to log in
How to reset the token when the user logs out?
Hello! I'm trying to implement authorization for an API using JWT ( JWT library ).
The following logic comes out:
The user enters a login and password on the client side (android application).
They arrive at the server and if the login and password match, this code is executed:
$token = (new Lcobucci\JWT\Builder())
->setExpiration(time() + 3600000) // Время жизни токена
->set('user_id', 1453535345) // в токене храним ID юзера
->sign($signer, 'testing') // ключ подписи
->getToken();
echo (string) $token; // отправляем токен пользователю
$token = (new Lcobucci\JWT\Parser())->parse((string) $_GET['token']); // парсим полученый токен
$data = new Lcobucci\JWT\ValidationData();
if($token->validate($data) && $token->verify($signer, 'testing')){
$_SESSION['user_id'] = $token->getClaim('user_id');
}
$_SESSION['user_id']
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question