在服务器访问令牌问题中使用Passport Oauth2

时间:2018-02-17 06:03:33

标签: laravel oauth-2.0 laravel-passport

大家好我在laravel 5.4中遇到使用护照Oauth2身份验证的问题,我正在研究我定义两条路线的项目 1.对于通过API http://localhost:8000/api/login登录,我得到了一个响应作为访问令牌。 2.另一个获取用户详细信息http://localhost/api/user,我将收到用户详细信息。

但是当我将我的应用程序部署到服务器并尝试在Postman中点击上面的两个URL时,我获得了访问令牌,但是尝试使用生成的访问令牌访问用户。它发送给我错误的Unauthenticated。

我是否需要使用php artisan passport:keys

在服务器中生成护照密钥

1 个答案:

答案 0 :(得分:0)

是的,您还需要服务器上的加密密钥:

php artisan passport:keys

// or with new installations
php artisan passport:install

在访问用户时,还要确保使用正确的身份验证,auth:api

// middleware
Route::group(['middleware' => ['auth:api'])->(...)

// and with the user helper
auth('api')->user()
相关问题