在PHP/Laravel中,封装Firebase/JWT令牌生成秘密base64编码的无效签名

问题描述 投票:0回答:1

我生成了一个 JWT 令牌,并使用密钥在 Jwt.io 上对其进行了测试。当我检查秘密的 Base64 编码时,令牌显示无效签名(已添加图像)

如果我没有选中秘密的base64编码,那么这是一个有效的签名,但我需要检查秘密的base64编码。

这是我的 Laravel Controller 中的代码。我正在使用 PHP 的 Firebase/JWT 包。

$payload=[
            "enable_auto_capture" => "false",
            "merchant_code" => "234dfrwer8975027a7c746ccb2eaf02bdf19a7ed",
            "merchant_reference" => "PGcfcE20pmm6RaPRBLFxO8T1xnqqE8uK",
            "payment_profile_code" => "",
            "instalment_profile_code" => "",
            "currency" => "MYR",
            "amount" => "242.50",
            "description" => "Flight Ticket KL to Sabah",
            "response_url" => "http://127.0.0.1:8000/success",
            "additional_reference" => "test",
            "customer" => [
                "customer_id" => "cust_john_5678",
                "customer_name" => "John C",
                "customer_contact_no" => "0134567890",
                "customer_email" => "[email protected]"
            ],
            "billing" => [
                "billing_address_line_1" => "C-7-7, Centum @ Oasis Corporate Park",
                "billing_address_line_2" => "Jalan PJU 1A/3",
                "billing_address_line_3" => "",
                "billing_address_city" => "Petaling Jaya",
                "billing_address_state" => "Selangor",
                "billing_address_postal_code" => "47301",
                "billing_address_country_code" => "MYS"
            ],
        ];
        $apiKey = 'my-api-key';

        // Create a JWT token
        $jwtToken = JWT::encode($payload, $apiKey, 'HS256');

我该如何解决这个问题?

php laravel jwt payment-gateway
1个回答
0
投票

当我检查秘密的 Base64 编码时,令牌显示我无效的签名(已添加图像)

jwt.io 工具会为您重新生成签名,这就是它说它有效的原因。看看

HB-ounwggLtTQbxici_CgurcrJGuCrN-lTprD6wxwV8
签名部分如何变成新的有效签名?您正在修改秘密。您可以开始在右侧部分输入任何内容,签名将替换您提供的签名。不要与正确的部分互动。

这很令人困惑。但请记住上面的签名。现在在框中输入“my-api-key”,当您输入时,您会看到签名会发生变化,当您输入最后的 y 时,您会看到它匹配并且您的签名将被验证。

jwt.io 用作调试工具,并且没有立即的 UI 来验证签名,因为当您更改输入时它会不断变化,并且一旦您开始输入,它总是会说签名有效它重新计算哈希值。再次令人困惑。

你的钥匙没问题。你的图书馆很好。另请参阅此问题https://github.com/firebase/php-jwt/issues/74

© www.soinside.com 2019 - 2024. All rights reserved.