swooletw / laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
MIT License
4.04k stars 390 forks source link

Laravel sanctum not work when I use incorrect bearer token #492

Closed alphasnow closed 3 years ago

alphasnow commented 3 years ago

Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks! (Any non-English issues will be closed immediately.)

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole) php: 7.4.19 swoole: 4.6.7
    
    $ php -v
    PHP 7.4.19 (cli) (built: May 25 2021 15:53:39) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Yasd v0.3.8, Our Copyright, by codinghuang

$ php --ri swoole swoole

Swoole => enabled Author => Swoole Team team@swoole.com Version => 4.6.7 Built => May 25 2021 15:56:22 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 1.0.2u 20 Dec 2019 pcre => enabled zlib => 1.2.11 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled

Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608



2. Please provide your Laravel/Lumen version.
Laravel Framework 8.44.0

3. Which release version of this package are you using?
swooletw/laravel-swoole^2.8

4. What did you do? If possible, provide a recipe for reproducing the error.
when i use the sanctum provide bearer token to get user information, only when the token is run for the first time, user information can be obtained normally, but when I want to obtain new user information for the second time by another bearer token, the old information is returned. If I send the wrong bearer token, it still responds to my number one. User data sent this time, I guess swoole only executes Auth::resolve() once. How can i solve it?

5. What did you expect to see?
I expect that when I use bearer tokens of different users, I can get different user information instead of sending back to me the old ones all the time. Even if it’s a wrong bearer token, it won’t report an error.

6. What did you see instead?
I see it is swoole's problem, but i can't solve it.
alphasnow commented 3 years ago

I found a solution by modifying the configuration file.

config/swoole_http.php

    'providers' => [
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Auth\AuthServiceProvider::class,
    ],
  1. when Illuminate\Auth\RequestGuard was first initialized, a blank request was obtained
  2. when the first time auth is used, Illuminate\Auth\RequestGuard will be saved in the Illuminate\Auth\AuthManager
  3. so we need to reset $customCreators inside Illuminate\Auth\AuthManager
Arkanius commented 3 years ago

Thanks @alphasnow ! Good job