Skip to content

[13.x] Fix middleware type error #1815

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

Merged
merged 2 commits into from
May 7, 2025

Conversation

axlon
Copy link
Contributor

@axlon axlon commented May 7, 2025

Passport's changed middleware incorrectly assumes OAuthenticatable::currentAccessToken() returns an instance of AccessToken, when it actually returns any implementation of ScopeAuthorizable (which includes TransientToken). This PR fixes the TypeError that arises when the user has a token set that is not of type AccessToken.

Note that this is a potential breaking change for anyone that is extending the middleware on 13.0.0 (which is probably not many people since its not been out for long). However, I don't see any other way to fix this TypeError and not fixing this means you'd have to use your own middleware if you wanted to use TransientToken or a custom token implementation

@axlon
Copy link
Contributor Author

axlon commented May 7, 2025

Error in question:

[2025-05-07 09:35:41] local.ERROR: Laravel\Passport\Http\Middleware\ValidateToken::validateToken(): Return value must be of type Laravel\Passport\AccessToken, Laravel\Passport\TransientToken returned {"userId":1,"exception":"[object] (TypeError(code: 0): Laravel\Passport\Http\Middleware\ValidateToken::validateToken(): Return value must be of type Laravel\Passport\AccessToken, Laravel\Passport\TransientToken returned at /Users/choraimy/Sites/project/vendor/laravel/passport/src/Http/Middleware/ValidateToken.php:63)

@taylorotwell taylorotwell merged commit d96323a into laravel:13.x May 7, 2025
8 checks passed
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