Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.x] Create access and refresh token in Passport::actingAs() #1740

Closed
wants to merge 1 commit into from

Conversation

gdebrauwer
Copy link
Contributor

@gdebrauwer gdebrauwer commented Apr 17, 2024

If you use Passport::actingAs() in a test while in the tested API route needs to revoke the authenticated user's current access token, then that causes an error in the test. That is because Eloquent can not revoke a token that does not exist in database.

Passport::actingAs($user);

auth()->user()->token()->revoke(); // This currently causes an error

This PR fixes that by creating and saving an access and refresh token in the database.

I also create a refresh token because of #1739 so the following works as well:

Passport::actingAs($user);

auth()->user()->token()->refreshToken->revoke();

@taylorotwell
Copy link
Member

This might be a breaking change to existing applications. I would recommend maybe creating the tokens yourself in the few tests that need to actually revoke. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants