1 year ago

Testing Passport logout -- is it possible?

Posted 1 year ago by jediping

I'm trying to figure out how to test my Passport-driven logout function, which looks like this:

public function logout() {
        $accessToken = auth()->user()->token();

        $refreshToken = DB::table('oauth_refresh_tokens')
            ->where('access_token_id', $accessToken->id)
                'revoked' => true


        return response()->json(['status' => 200]);

I am using the Passport actingAs helper in setting up the response.

            ['read write']
$response = $this->post('/logout')

The test fails, as the code gives a 500 error, as auth()->user()->token() is ... empty-ish? $accessToken->id is 0, for example, which it shouldn't be, which means the code fails.

What I'm not sure about is if this is expected behavior because of how Passport's actingAs helper works and I can't actually test the logout function, or if there's something wrong with my logout function. Halp!

ETA: My login function, if it's helpful:

public function login(Request $request, Client $client){

        if ($this->hasTooManyLoginAttempts($request)) {

            return $this->sendLockoutResponse($request);

        $response = $client->post(config('app.url') . '/oauth/token', [
            'form_params' => [
                'client_id' => config('auth.proxy.client_id'),
                'client_secret' => config('auth.proxy.client_secret'),
                'grant_type' => config('auth.proxy.grant_type'),
                'username' => $request->email,
                'password' => $request->password,
                'scopes' => '[read write]'

        if ($response->getStatusCode() === 200) {

           return response($response->getBody()->getContents(), $response->getStatusCode());


        return response($response->getBody()->getContents(), $response->getStatusCode());

Please sign in or create an account to participate in this conversation.