我试图通过使用这个模块在nginx级别验证jwt令牌。https://github.com/TeslaGov/ngx-http-auth-jwt-module我在nginx日志中得到此错误。当我使用我的自定义密钥和令牌时会引发错误,当我使用源代码中的密钥和令牌时它会起作用。
- CustomKey+CustomToken =不起作用
- ProvidedKey+ProvidedToken =有效
- ProvidedKey+CustomToken =不起作用
[error] 23#23: *3 failed to parse JWT, error code 22, client: 172.30.0.1, server: mylocaldev.com, request: "GET /hsa HTTP/1.1"
我试过HS256和RSA256键,都给予同样的错误.
我的nginx配置
server {
listen 443 ssl;
server_name auth.mylocaldev.com.com www.auth.mylocaldev.com.com;
ssl_certificate /etc/nginx/ssl/mylocaldev.crt;
ssl_certificate_key /etc/nginx/ssl/mylocaldev.key;
location /hsa {
proxy_pass https://mybackend.dev/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
auth_jwt_enabled on;
auth_jwt_key "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF";
auth_jwt_algorithm HS256;
}
}
我的令牌,不能用。
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxMjM0NSwiZm9vIjoiYmFyIn0.hSVab6LHsl2K-G1SRHRZshgE_Pf8JBohnkWQws_zJNE
有效的代币。
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzb21lLWxvbmctdXVpZCIsImZpcnN0TmFtZSI6ImhlbGxvIiwibGFzdE5hbWUiOiJ3b3JsZCIsImVtYWlsQWRkcmVzcyI6ImhlbGxvd29ybGRAZXhhbXBsZS5jb20iLCJyb2xlcyI6WyJ0aGlzIiwidGhhdCIsInRoZW90aGVyIl0sImlzcyI6Imlzc3VlciIsInBlcnNvbklkIjoiNzViYjNjYzctYjkzMy00NGYwLTkzYzYtMTQ3YjA4MmZhZGI1IiwiZXhwIjoxOTA4ODM1MjAwLCJpYXQiOjE0ODg4MTk2MDAsInVzZXJuYW1lIjoiaGVsbG8ud29ybGQifQ.r8tG8IZheiQ-i6HqUYyJj9V6dipgcQ4ZIdxau6QCZDo
1条答案
按热度按时间huwehgph1#
1.你必须将base64转换为HEX(https://base64.guru/converter/decode/hex),并在Nginx中配置auth_jwt_key“HEX”;
1.并将base64转换为HS 256 https://jwt.io/(粘贴“secret base64 encoded”)