someline / someline-starter

Someline Starter is a PHP framework for quick building Web Apps and Restful APIs, with modern PHP design pattern foundation.
https://starter.someline.com/
839 stars 170 forks source link

429 Too Many Requests #66

Open crazcdll opened 6 years ago

crazcdll commented 6 years ago

Client error: 'POST http://api.XXX.com.cn/oauth/token' resulted in a '429 Too Many Requests' response: Too Many Attempts.

Hello, when I send some requests a little fast, I would got the error above.

I have try do modify the throttle config in routes/web.php and routes/api.php, but nothing changed.

THX!

qiutuleng commented 6 years ago

Hi. @zcdll you can change the 29 line in the app/Providers/AuthServiceProvider.php file.

like this.

Passport::routes(function ($router) {
    /** @var \Laravel\Passport\RouteRegistrar $router */
    $router->forAuthorization();
    $router->forTransientTokens();
    $router->forClients();
    $router->forPersonalAccessTokens();

    // Passport Routes
    \Route::post('/token', [
        'uses' => 'AccessTokenController@issueToken',
//                'middleware' => 'throttle',
    ]);

    \Route::group(['middleware' => ['web', 'auth']], function ($router) {
        $router->get('/tokens', [
            'uses' => 'AuthorizedAccessTokenController@forUser',
        ]);

        $router->delete('/tokens/{token_id}', [
            'uses' => 'AuthorizedAccessTokenController@destroy',
        ]);
    });
});
crazcdll commented 6 years ago

Thx. @qiutuleng My app/Providers/AuthServiceProvider.php just looks like below

public function boot()
{
    $this->registerPolicies();

    Passport::routes();

    // Token Lifetimes
//        Passport::tokensExpireIn(Carbon::now()->addDays(15));

    // Refresh Token Lifetimes
//        Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));

    // Pruning Revoked Tokens
//        Passport::pruneRevokedTokens();

    // Token Scopes
//        Passport::tokensCan([
//            'place-orders' => 'Place orders',
//            'check-status' => 'Check order status',
//        ]);

}

What you mean is to overwrite the Passport::routes()

qiutuleng commented 6 years ago

@zcdll yes

qiutuleng commented 6 years ago

@zcdll You can refer to here RouteRegistrar.php It's the laravel official source code.

I just copy the forAccessTokens function code and disable throttle middleware.

example: example

before: before

after: after

crazcdll commented 6 years ago

@qiutuleng OK! Thanks a lot!

Muhammadinaam commented 3 years ago

Hi, this is a nice package but I think that the developers have stopped working on it. Maybe you can try this package: https://github.com/Muhammadinaam/speed-admin. It supports Laravel 8+.