Hello folks,
I trying to set authentication via JWT using Policy but im getting this error:
time="Feb 25 12:22:43" level=warning msg="Key not found in storage engine" err="key not found" inbound-key="****3f0f" prefix=auth-mgr
time="Feb 25 12:22:43" level=warning msg="Key not found in storage engine" err="key not found" inbound-key="****3f0f" prefix=auth-mgr
but if i’m using policies i dont need to set a key, right?
On configuration file its like this:
"policies": {
"policy_source": "file",
"policy_record_name": "/opt/tyk-gateway/policies/policies.json"
},
and the file its in right folder.
root@43ea6dc3048c:/opt/tyk-gateway# ls policies/
policies.json
api file:
{
"enable_context_vars": true,
"name": "Simula Rota JWT",
"api_id": "40",
"org_id": "",
"use_basic_auth": false,
"use_keyless": false,
"use_oauth2": false,
"enable_jwt": true,
"jwt_signing_method":"hmac",
"jwt_source":"dHlrMTIz",
"jwt_identity_base_field":"clientid",
"jwt_policy_field_name": 123456789,
"auth": {
"auth_header_name": "Authorization"
},
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default",
"expires": "3000-01-02 15:04",
"use_extended_paths": true,
"extended_paths": {
"ignored": [],
"white_list": [],
"black_list": [],
"cache": [
"get"
],
"transform": []
}
}
}
},
"proxy": {
"listen_path": "/jwt/",
"target_url": "http://httpbin.org",
"strip_listen_path": true,
"preserve_host_header": true
},
"custom_middleware": {
"pre": [
{
"name": "bearerAuthMiddleware",
"path": "middleware/bearerAuthMiddleware.js",
"require_session": false
}
]
},
"enable_batch_request_support": true
}
policy file
{
"123456789": {
"id":123456789,
"access_rights": {
"40": {
"api_id": "40",
"api_name": "Simula Rota JWT",
"versions": [
"Default"
]
}
},
"active": true,
"name": "Main Policy",
"allowance":100,
"rate": 100,
"per": 1,
"expires":-1,
"org_id": ""
}
}
curl Comando from Postman:
curl --location --request GET 'http://localhost:8080/jwt/get' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiTWFyY29zIE9sZWlybyIsImNsaWVudGlkIjoiMWEyYTNhNGE1YTZhN2E4YTlhMGEiLCJpYXQiOjE1MTYyMzkwMjIsInBvbCI6MTIzNDU2Nzg5fQ.JJktBquE5yn84og7Bl5-Om3R25m32P5i2roitJBiH-w' \
--header 'Content-Type: application/json' \
--header 'x-application-id: user1'
How i created token (the secret is tyk123)
This is the request received on middleware:
{“AddParams”:{},“Body”:“”,“DeleteHeaders”:[],“DeleteParams”:[],“ExtendedParams”:{},“Headers”:{“Accept”:[“/”],“Accept-Encoding”:[“gzip, deflate, br”],“Authorization”:[“Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiTWFyY29zIE9sZWlybyIsImNsaWVudGlkIjoiMWEyYTNhNGE1YTZhN2E4YTlhMGEiLCJpYXQiOjE1MTYyMzkwMjIsInBvbCI6MTIzNDU2Nzg5fQ.JJktBquE5yn84og7Bl5-Om3R25m32P5i2roitJBiH-w”],“Connection”:[“keep-alive”],“Content-Type”:[“application/json”],“Host”:[“localhost:8080”],“Postman-Token”:[“38db5a89-c42b-40dc-810e-4024cbbbda17”],“User-Agent”:[“PostmanRuntime/7.26.10”],“X-Application-Id”:[“user1”]},“IgnoreBody”:false,“Method”:“GET”,“Params”:{},“RequestURI”:“/jwt/get”,“ReturnOverrides”:{“OverrideError”:false,“ResponseBody”:“”,“ResponseCode”:0,“ResponseError”:“”,“ResponseHeaders”:null},“Scheme”:“http”,“SetHeaders”:{},“URL”:“/jwt/get”}" prefix=jsvm type=log-msg
Thanks in advance