You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "kayx23 (via GitHub)" <gi...@apache.org> on 2023/08/10 08:04:41 UTC
[GitHub] [apisix] kayx23 opened a new issue, #10002: Question: why is `_meta. error_response` not effective if configured on the auth plugin on consumer?
kayx23 opened a new issue, #10002:
URL: https://github.com/apache/apisix/issues/10002
### Description
Relevant doc: https://apisix.apache.org/docs/apisix/terminology/plugin/#custom-error-response
Testing with the `jwt-auth` plugin. `_meta. error_response` is not effective if configured on the `jwt-auth` plugin on consumer. It is effective if configured on route.
This behaviour is unintuitive and unexpected since most of the time users configure the auth plugin details on consumers.
See the following tests.
## Configure `_meta. error_response` on Consumer
Create a consumer:
```bash
curl "http://127.0.0.1:9180/apisix/admin/consumers" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"username": "tom",
"plugins": {
"jwt-auth": {
"key": "user-key",
"_meta": {
"error_response": {
"message": "TESTING FOR ERROR RESPONSE"
}
}
}
}
}'
```
Create a route:
```bash
curl "http://127.0.0.1:9180/apisix/admin/routes" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"id": "jwt-auth-route",
"uri": "/ip",
"plugins": {
"jwt-auth": {}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
}
}'
```
Sending requests without JWT token, we see that the error message is not the one we customized:
```bash
curl "http://127.0.0.1:9080/ip"
{"message":"Missing JWT token in request"}
```
```bash
curl http://127.0.0.1:9080/ip?jwt=123456
{"message":"JWT token invalid"}
```
## Configure `_meta. error_response` on Route
Create a consumer:
```bash
curl "http://127.0.0.1:9180/apisix/admin/consumers" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"username": "tom",
"plugins": {
"jwt-auth": {
"key": "user-key"
}
}
}'
```
Create a route:
```bash
curl "http://127.0.0.1:9180/apisix/admin/routes" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"id": "jwt-auth-route",
"uri": "/ip",
"plugins": {
"jwt-auth": {
"_meta": {
"error_response": {
"message": "TESTING FOR ERROR RESPONSE"
}
}
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
}
}'
```
Sending requests without JWT token, we see that the error message is not the one we customized:
```bash
curl "http://127.0.0.1:9080/ip"
{"message":"TESTING FOR ERROR RESPONSE"}
```
```bash
curl http://127.0.0.1:9080/ip?jwt=123456
{"message":"TESTING FOR ERROR RESPONSE"}
```
### Environment
- APISIX version (run `apisix version`): 3.2.0
--
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: notifications-unsubscribe@apisix.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] yuluo-yx commented on issue #10002: `_meta.error_response` not effective if configured on the auth plugin on consumer
Posted by "yuluo-yx (via GitHub)" <gi...@apache.org>.
yuluo-yx commented on issue #10002:
URL: https://github.com/apache/apisix/issues/10002#issuecomment-1674178458
I will do it in next week, please assign to me!
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] kayx23 commented on issue #10002: `_meta.error_response` not effective if configured on the auth plugin on consumer
Posted by "kayx23 (via GitHub)" <gi...@apache.org>.
kayx23 commented on issue #10002:
URL: https://github.com/apache/apisix/issues/10002#issuecomment-1674205224
Confirmed with @leslie-tsang that it was the intended behaviour.
Example scenario: return different fixed error msgs for JWT token verification failure by route, such as different IT Admin contact information for different route.
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] leslie-tsang commented on issue #10002: `_meta.error_response` not effective if configured on the auth plugin on consumer
Posted by "leslie-tsang (via GitHub)" <gi...@apache.org>.
leslie-tsang commented on issue #10002:
URL: https://github.com/apache/apisix/issues/10002#issuecomment-1674180262
> curl "http://127.0.0.1:9080/ip"
This test request does not trigger any consumer, that's why apisix echo the raw response.
Try to config the `_meta.error_reponse` in `Route` may meet your need, :)
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] kayx23 closed issue #10002: `_meta.error_response` not effective if configured on the auth plugin on consumer
Posted by "kayx23 (via GitHub)" <gi...@apache.org>.
kayx23 closed issue #10002: `_meta.error_response` not effective if configured on the auth plugin on consumer
URL: https://github.com/apache/apisix/issues/10002
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org