gpt4 book ai didi

php - 智威汤逊 401 : Unauthorized in Slim 3 framework

转载 作者:行者123 更新时间:2023-12-05 03:10:24 27 4
gpt4 key购买 nike

这是我第一个使用 slim 3 框架骨架的项目,他们说

There is also a skeleton project which will give you a quick-start for a sample application, so use that if you’d rather just have something working rather than exploring how all the moving parts work.

在现实生活中很难融入JSON Web Token Authentication Middleware

我尝试按照教程中的步骤进行操作,但仍然无法正常工作。请帮帮我?

这是我的代码

middleware.php

$app->add(new \Slim\Middleware\JwtAuthentication([
"path" => "/",
"passthrough" => "/test",
"secret" => "thisissecret"
]));

和我的/路线

routes.php

$app->get('/',App\MemberController::class);

但是结果就像下图,401: Unauthorized

enter image description here

最佳答案

您误解了参数secret。它不是 token 。它是您用来签署 token 的 key

如何生成 token 由您决定。例如有一个 online tool .您还可以使用 PHP 生成 token 。

use Firebase\JWT\JWT;

$payload = [
"sub" => "user@example.com"
];
$token = JWT::encode($payload, "thisissecret", "HS256");

在使用 JWT 之前阅读此 introduction 是个好主意.

关于php - 智威汤逊 401 : Unauthorized in Slim 3 framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40151874/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com