为什么我的 laravel 护照在从内置服务器迁移到 vagrant 时停止工作?
Why my laravel passport stopped working when migrated to vagrant from build-in server?
所以我不得不实现 facebook 登录,这需要 https 连接,在我使用 php artisan serve 之前,但它只允许 http,现在我决定将整个项目迁移到 vagrant。一切正常,但护照。
我检查了一下,发现这两行导致了内部错误 500
auth()->attempt($loginData, true);
auth()->user()->createToken('authToken')->accessToken;
删除后,我没有收到任何错误。我的整个登录功能如下所示:
public function login(Request $request)
{
$loginData = $request->validate([
'name' => 'required',
'password' => 'required'
]);
$a = auth()->attempt($loginData, true);
if(!$a) {
return response(['message'=>'Invalid credentials', 'auth' => false]);
}
$accessToken = auth()->user()->createToken('authToken')->accessToken;
return response(['user' => auth()->user(), 'access_token' => $accessToken, 'auth' => true, "attempt" => $a, "auth()" => auth()]);
}
此外,我通过 tinker 创建了用户,存储了令牌和用户。
这是我的数据库数据
mysql> select * from users;
+----+-------+--------------------------------------------------------------+----------------+---------------------+---------------------+
| id | name | password | remember_token | created_at | updated_at |
+----+-------+--------------------------------------------------------------+----------------+---------------------+---------------------+
| 1 | admin | y$V8fM6Vvc7xOJxN/LPyImUeQNzG9/k3tSsaF8qf1NsxrzK9B3VPmsa | NULL | 2019-08-26 15:22:02 | 2019-08-26 15:22:02 |
| 2 | demis | y$oRvcL0ZC2NQuGXE446GhfO1KBcAw3h8d/TGQmODL/AFHnat1I.Yvq | NULL | 2019-08-26 15:45:27 | 2019-08-26 15:45:27 |
+----+-------+--------------------------------------------------------------+----------------+---------------------+---------------------+
2 rows in set (0.00 sec)
mysql> select * from oauth_access_tokens;
+----------------------------------------------------------------------------------+---------+-----------+-----------+--------+---------+---------------------+---------------------+---------------------+
| id | user_id | client_id | name | scopes | revoked | created_at | updated_at | expires_at |
+----------------------------------------------------------------------------------+---------+-----------+-----------+--------+---------+---------------------+---------------------+---------------------+
| 2e82923d6fdc1cc98580b683952b7b96d555e67d6b7e06b8080f8a55227b6c1d7a755fc21b570941 | NULL | 1 | authToken | [] | 0 | 2019-08-26 15:21:52 | 2019-08-26 15:21:52 | 2020-08-26 15:21:52 |
| 610f8fd1f2212ab257810de88605bff4e419f26477bcf63f8dfe20018d9bcf74797bb9c817d6450a | NULL | 1 | authToken | [] | 0 | 2019-08-26 15:45:19 | 2019-08-26 15:45:19 | 2020-08-26 15:45:19 |
+----------------------------------------------------------------------------------+---------+-----------+-----------+--------+---------+---------------------+---------------------+---------------------+
怎么了,为什么我无法登录,可能是配置有问题?
运行 php artisan passport:install
在新服务器上。
所以我不得不实现 facebook 登录,这需要 https 连接,在我使用 php artisan serve 之前,但它只允许 http,现在我决定将整个项目迁移到 vagrant。一切正常,但护照。
我检查了一下,发现这两行导致了内部错误 500
auth()->attempt($loginData, true);
auth()->user()->createToken('authToken')->accessToken;
删除后,我没有收到任何错误。我的整个登录功能如下所示:
public function login(Request $request)
{
$loginData = $request->validate([
'name' => 'required',
'password' => 'required'
]);
$a = auth()->attempt($loginData, true);
if(!$a) {
return response(['message'=>'Invalid credentials', 'auth' => false]);
}
$accessToken = auth()->user()->createToken('authToken')->accessToken;
return response(['user' => auth()->user(), 'access_token' => $accessToken, 'auth' => true, "attempt" => $a, "auth()" => auth()]);
}
此外,我通过 tinker 创建了用户,存储了令牌和用户。
这是我的数据库数据
mysql> select * from users;
+----+-------+--------------------------------------------------------------+----------------+---------------------+---------------------+
| id | name | password | remember_token | created_at | updated_at |
+----+-------+--------------------------------------------------------------+----------------+---------------------+---------------------+
| 1 | admin | y$V8fM6Vvc7xOJxN/LPyImUeQNzG9/k3tSsaF8qf1NsxrzK9B3VPmsa | NULL | 2019-08-26 15:22:02 | 2019-08-26 15:22:02 |
| 2 | demis | y$oRvcL0ZC2NQuGXE446GhfO1KBcAw3h8d/TGQmODL/AFHnat1I.Yvq | NULL | 2019-08-26 15:45:27 | 2019-08-26 15:45:27 |
+----+-------+--------------------------------------------------------------+----------------+---------------------+---------------------+
2 rows in set (0.00 sec)
mysql> select * from oauth_access_tokens;
+----------------------------------------------------------------------------------+---------+-----------+-----------+--------+---------+---------------------+---------------------+---------------------+
| id | user_id | client_id | name | scopes | revoked | created_at | updated_at | expires_at |
+----------------------------------------------------------------------------------+---------+-----------+-----------+--------+---------+---------------------+---------------------+---------------------+
| 2e82923d6fdc1cc98580b683952b7b96d555e67d6b7e06b8080f8a55227b6c1d7a755fc21b570941 | NULL | 1 | authToken | [] | 0 | 2019-08-26 15:21:52 | 2019-08-26 15:21:52 | 2020-08-26 15:21:52 |
| 610f8fd1f2212ab257810de88605bff4e419f26477bcf63f8dfe20018d9bcf74797bb9c817d6450a | NULL | 1 | authToken | [] | 0 | 2019-08-26 15:45:19 | 2019-08-26 15:45:19 | 2020-08-26 15:45:19 |
+----------------------------------------------------------------------------------+---------+-----------+-----------+--------+---------+---------------------+---------------------+---------------------+
怎么了,为什么我无法登录,可能是配置有问题?
运行 php artisan passport:install
在新服务器上。