我正在按照API Authentication (Passport) - Laravel上的说明进行操作,但这只是为我提供了网络路由(如果您查看下面的“中间件”列下方)。
当前,尚无针对Web界面(即HTML)的规范,但有一些提示,因此,我想保留Web开放的可能性,但目前仅使用API路由。整个API接口应仅使用JSON,而不使用HTML。
我正在尝试使用api/*
和/或api
中间件在auth:api
下设置路由。应该有注册(不认证),登录(不认证),检索用户详细信息(认证),更新(认证)和删除(认证)的途径。
我确实以某种方式获得了一条api/user
路由,但是没有身份验证就无法使用它,因为没有注册/创建用户的方式,所以我没有身份验证。所有网络路由都可以按您期望的方式工作,除非它们在我需要之前不存在。
为什么我按照API的说明获取网络路由而不是API路由?
+--------+----------+-----------------------------------------+------------------+---------------------------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------------------+------------------+---------------------------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController@index | web,auth |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web |
| | POST | oauth/authorize | | Laravel\Passport\Http\Controllers\ApproveAuthorizationController@approve | web,auth |
| | GET|HEAD | oauth/authorize | | Laravel\Passport\Http\Controllers\AuthorizationController@authorize | web,auth |
| | DELETE | oauth/authorize | | Laravel\Passport\Http\Controllers\DenyAuthorizationController@deny | web,auth |
| | POST | oauth/clients | | Laravel\Passport\Http\Controllers\ClientController@store | web,auth |
| | GET|HEAD | oauth/clients | | Laravel\Passport\Http\Controllers\ClientController@forUser | web,auth |
| | DELETE | oauth/clients/{client_id} | | Laravel\Passport\Http\Controllers\ClientController@destroy | web,auth |
| | PUT | oauth/clients/{client_id} | | Laravel\Passport\Http\Controllers\ClientController@update | web,auth |
| | POST | oauth/personal-access-tokens | | Laravel\Passport\Http\Controllers\PersonalAccessTokenController@store | web,auth |
| | GET|HEAD | oauth/personal-access-tokens | | Laravel\Passport\Http\Controllers\PersonalAccessTokenController@forUser | web,auth |
| | DELETE | oauth/personal-access-tokens/{token_id} | | Laravel\Passport\Http\Controllers\PersonalAccessTokenController@destroy | web,auth |
| | GET|HEAD | oauth/scopes | | Laravel\Passport\Http\Controllers\ScopeController@all | web,auth |
| | POST | oauth/token | | Laravel\Passport\Http\Controllers\AccessTokenController@issueToken | throttle |
| | POST | oauth/token/refresh | | Laravel\Passport\Http\Controllers\TransientTokenController@refresh | web,auth |
| | GET|HEAD | oauth/tokens | | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@forUser | web,auth |
| | DELETE | oauth/tokens/{token_id} | | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@destroy | web,auth |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest |
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest |
+--------+----------+-----------------------------------------+------------------+---------------------------------------------------------------------------+--------------+