ご存知のとおり、Laravelパスポートには次のような事前定義されたルートがあります:
php artisan route:list
+--------+----------+-----------------------------------------+------+---------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------------------+------+---------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | POST | oauth/authorize | | ...\ApproveAuthorizationController@approve | web,auth |
| | GET|HEAD | oauth/authorize | | ...\AuthorizationController@authorize | web,auth |
| | DELETE | oauth/authorize | | ...\DenyAuthorizationController@deny | web,auth |
| | GET|HEAD | oauth/clients | | ...\ClientController@forUser | web,auth |
| | POST | oauth/clients | | ...\ClientController@store | web,auth |
| | PUT | oauth/clients/{client_id} | | ...\ClientController@update | web,auth |
| | DELETE | oauth/clients/{client_id} | | ...\ClientController@destroy | web,auth |
| | GET|HEAD | oauth/personal-access-tokens | | ...\PersonalAccessTokenController@forUser | web,auth |
| | POST | oauth/personal-access-tokens | | ...\PersonalAccessTokenController@store | web,auth |
| | DELETE | oauth/personal-access-tokens/{token_id} | | ...\PersonalAccessTokenController@destroy | web,auth |
| | GET|HEAD | oauth/scopes | | ...\ScopeController@all | web,auth |
| | POST | oauth/token | | ...\AccessTokenController@issueToken | throttle |
| | POST | oauth/token/refresh | | ...\TransientTokenController@refresh | web,auth |
| | GET|HEAD | oauth/tokens | | ...\AuthorizedAccessTokenController@forUser | web,auth |
| | DELETE | oauth/tokens/{token_id} | | ...\AuthorizedAccessTokenController@destroy | web,auth |
+--------+----------+-----------------------------------------+------+---------------------------------------------+--------------+
そのルートを変更することは可能ですか?例えばoauth/authorize
になるapi/v1/oauth/authorize
はいの場合、どのように?
私はかなり前から答えを探していました...
はい、そうです。 Passport::routes()
メソッドで独自のルートを宣言できます。
これを_app/Providers/AuthServiceProvider
_ファイルのboot()
メソッド内に含めます。
app/Providers/AuthServiceProvider.php
_public function boot()
{
Passport::routes(null, ['prefix' => 'api/v1/oauth']);
}
_