11.3. 使用 Passport 认证
使用 Passport 认证
这一节我们将现有的接口实现,由之前 JWT 授权方式, 更替为 Passport 的 Oauth2 授权。
登录接口
调整接口
Passport 提供的默认路由为 larabbs.test/oauth/token ,而我们的现在接口统一都有 /api
的前缀,所以我们不使用 Passport 默认的路由,依然使用 /api/authorizations
。先来修改登录接口:
app/Http/Controllers/Api/AuthorizationsController.php
.
.
.
use Zend\Diactoros\Response as Psr7Response;
use Psr\Http\Message\ServerRequestInterface;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\AuthorizationServer;
.
.
.
public function store(AuthorizationRequest $originRequest, AuthorizationServer $server, ServerRequestInterface $serverRequest)
{
try {
return $server->respondToAccessTokenRequest($serverRequest, new Psr7Response)->wi...