LoginSignup
0
0

More than 1 year has passed since last update.

Laravel Passportのoauth系ルーティングはどこで定義されているのか

Last updated at Posted at 2022-04-14

概要

  • Laravel Passportのoauth系のルーティングはどこで定義されているのか追ってみた。

結果

  • vendor/laravel/passport/src/Passport.phpにルーティングに関する記載があった。

    vendor/laravel/passport/src/Passport.php
    /**
     * Binds the Passport routes into the controller.
     *
     * @param  callable|null  $callback
     * @param  array  $options
     * @return void
     */
    public static function routes($callback = null, array $options = [])
    {
        $callback = $callback ?: function ($router) {
            $router->all();
        };
    
        $defaultOptions = [
            'prefix' => 'oauth',
            'namespace' => '\Laravel\Passport\Http\Controllers',
        ];
    
        $options = array_merge($defaultOptions, $options);
    
        Route::group($options, function ($router) use ($callback) {
            $callback(new RouteRegistrar($router));
        });
    }
    
  • どうやらRouteRegistrarクラスをインスタンス化してルーティングを定義しているっぽい。当該のクラスを見てみる。

  • vendor/laravel/passport/src/RouteRegistrar.phpにて当該のクラスが定義されていて、ルーティング情報が記載されていた。(一部抜粋して下記に記載する。)

    vendor/laravel/passport/src/RouteRegistrar.php
    /**
     * Register the routes needed for managing clients.
     *
     * @return void
     */
    public function forClients()
    {
        $this->router->group(['middleware' => ['web', 'auth']], function ($router) {
            $router->get('/clients', [
                'uses' => 'ClientController@forUser',
                'as' => 'passport.clients.index',
            ]);
    
            $router->post('/clients', [
                'uses' => 'ClientController@store',
                'as' => 'passport.clients.store',
            ]);
    
            $router->put('/clients/{client_id}', [
                'uses' => 'ClientController@update',
                'as' => 'passport.clients.update',
            ]);
    
            $router->delete('/clients/{client_id}', [
                'uses' => 'ClientController@destroy',
                'as' => 'passport.clients.destroy',
            ]);
        });
    }
    

ご注意

  • Passportのライブラリを入れると勝手に定義してくれるけどAuthServiceProviderクラスのboot()関数にPassport::route();を追記して登録してあげないと当該のルートは使用できないのでご注意を
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0