pavlenkodev commented on issue #10518:
URL: https://github.com/apache/apisix/issues/10518#issuecomment-1829323039
> @pavlenkodev your use case is valid and the setup you described should
work. Can you share your configs?
1. This is my global serverless-pre-function for getting sub param
The `sub `variable is registered here
```
{
"key": "/apisix/global_rules/2",
"modifiedIndex": 1418,
"value": {
"create_time": 1700139583,
"plugins": {
"serverless-pre-function": {
"_meta": {
"priority": 10000
},
"phase": "rewrite",
"functions": [
"return function() local core =
require(\"apisix.core\").ctx.register_var(\"sub\",function(ctx) local core =
require(\"apisix.core\") local jwt = require(\"resty.jwt\") local sub_not_found
= \"not found\" local access_token = core.request.header(ctx,
\"Authorization\") local result_value; if not access_token then result_value =
sub_not_found return result_value end local jwt_obj =
jwt:load_jwt(access_token) result_value = tostring(jwt_obj.payload.sub) return
result_value end ) end"
]
}
},
"update_time": 1700641593,
"id": "2"
},
"createdIndex": 1075
}
```
2. This is my global proxy-rewrite plugin for header `apiKey`.
Here I pass `sub `as the value of the `apiKey ` header
```
{
"key": "/apisix/global_rules/5",
"modifiedIndex": 1417,
"value": {
"create_time": 1700230727,
"plugins": {
"proxy-rewrite": {
"_meta": {
"priority": 9999,
"disable": true
},
"use_real_request_uri_unsafe": false,
"headers": {
"add": {
"apiKey": "$sub"
}
}
}
},
"update_time": 1700641406,
"id": "5"
},
"createdIndex": 1243
}
```
4. This is my consumer config
```
curl http://127.0.0.1:9180/apisix/admin/consumers \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"username": "test",
"plugins": {
"key-auth": {
"key": "9efc0ada-b861-4b7e-ad9a-d7629feac2c4"
}
}
}'
```
5. And my route
```
curl http://127.0.0.1:9180/apisix/admin/routes/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"key-auth": {},
"consumer-restriction": {
"whitelist": [
"test"
]
}
},
"uri": "/test"
}'
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]