Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc的sw中的自定义headers没有效果 #104

Closed
careyyoung opened this issue May 10, 2022 · 2 comments
Closed

grpc的sw中的自定义headers没有效果 #104

careyyoung opened this issue May 10, 2022 · 2 comments

Comments

@careyyoung
Copy link

hello,
Describe the bug

  1. 在boot.yaml 中启用 grpc,
  2. middleware中启用auth、apiKey,为token-1,
  3. 开启 sw,配置headers: [ "X-API-Key:token-1" ],想要得到每次在swagger web 上发请求时,能带上头部X-API-Key:token-1
  4. 但是现在,在 sw 上 发请求 ,得到的都是 401 ,未认证。
  5. 如:
curl -X 'GET' \
  'https://localhost:8082/api/v1/greeter?name=1' \
  -H 'accept: application/json'

{
  "error": {
    "code": 401,
    "status": "Unauthorized",
    "message": "missing authorization, provide one of bellow auth header:[X-API-Key]",
    "details": [
      {
        "code": 16,
        "status": "Unauthenticated",
        "message": "[from-grpc] missing authorization, provide one of bellow auth header:[X-API-Key]"
      }
    ]
  }
}

rk-boot/v2 v2.1.2
rk-grpc/v2 v2.0.2
rk-entry/v2 v2.1.7

谢谢。

@dongxuny
Copy link
Contributor

@careyyoung Hi
grpc.sw.header 这个选项是当 Swagger UI 界面返回时,带的 Header,并不是用来在发送请求时自带的 Header。如果想要在 Swagger UI 界面上开启 X-API-Key, Basic Auth,JWT 的验证

请参考例子:https://github.com/rookie-ninja/rk-demo/tree/master/grpc/v2/swagger-auth

@careyyoung
Copy link
Author

感谢回复和例子,辛苦了。
之前看的文档 https://docs.rkdev.info/cn/docs/rk-boot/user-guide/grpc/basic/swagger-ui/ ,提到的:

grpc.sw.headers 每次 Swagger 界面请求,都会带着这些头部。格式: [key:value] []string []
所以可能 误解 了。不好意思。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants