Lumen

Lumen Passport Logout

If you are using LumenPassport (that is based on Laravel Passport) for user authentication, you must know that Laravel Passport/Lumen Passport support’s both single and multiple token(s).

It doesn’t come with logout route as you can see routes list from LaravelPassport.

Solution:
Create /api/auth/logout route, since Lumen is session less you need to pass Authentication headers by providing Bearer access token.

Through that access token, we will parse token to get token Id in order to revoke it in oauth_access_tokens table.

    public function logout(Request $request) {
        $token = $request->bearerToken();
        if ($token) {
            $id = (new Parser())->parse($token)->getHeader('jti');
            DB::table('oauth_access_tokens')->where('id', '=', $id)->update(['revoked' => 1]);
        }

        return [
            'status' => 'success',
            'message' => 'Logout successfully.'
        ];
    }

That’s it, this will do the magic…

Author: Danyal
I'm skilled programmer with expertise in Vue.js/Nux.js for front-end development and PHP Laravel for back-end development. I excel in building APIs and services, and also have experience in web server setup & maintenance. My versatile skill set allows you to develop and maintain web applications effectively, from the user interface to the server-side functionality. I love coding with never ending learning attitude, thanks for visiting danya.dk