如何通过 Swagger 云端点传递自签名 JWT

How To Pass a Self Signed JWT through Swagger Cloud Endpoints

好的,我在这里看到了这个 QA

这并没有完全回答我的问题。目前,我有一个生成 Bearer 令牌并将其传递给客户端的节点服务。然后客户端在后续请求中传回令牌。

令牌是通过我们的身份验证令牌服务创建的。它是传递给客户端的。这行得通。但是,当令牌通过 API 网关从客户端传回后端服务时,它永远不会到达服务。

这是传入的不记名令牌的示例

eyJhbGciOiJSUzI1NR5cCI6IkpkkSXVCJ9.eyJ1c2VyX2lkIjoiWHZYSlZuZDdRZnhMMXZwZ0dTcWwiLCJyb2xlIjoidXNlciIsImlhdCI6MTU4ODczOTg3NywiZXhwIjoxNTg4NzksxjgzMDc3fQ.LJ3YQJMrVX4go-NZ_nfEdT7lrsmFD6kv9WAnDXB3w2ZXDmXn7eJJ5posUxOp5jfu32jpMCNdFywquQ 

令牌通过通过云端点创建的 API 网关(别着急,我是 Google 云端点的新手。)。那么我缺少什么以及如何传递令牌?

swagger: '2.0'
info:
  title:  API Gateway
  description: Description
  version: 1.0.0
host: {host}
schemes:
  - https
paths:
  /auth/token/decode:
    get:
      summary: Auth Endpoint - Decode Token
      operationId: auth_endpoint_decode
      x-google-backend:
        address: {backend-host}
        protocol: h2
      responses:
        200:
          description: "Token Decoded"
        400:
          description: "Page Error"
  /auth/token/create:
    post:
      summary: Auth Endpoint - Create Token
      operationId: auth_endpoint_create
      parameters:
        - description: "Message to echo"
          in: body
          name: content
          required: true
          schema:
            type: object
            properties:
              username:
                type: string
              password:
                type: string
      x-google-backend:
        address: {backend-host-2}
        protocol: h2
      responses:
       200:
         description: "Encoded Token"
       400:
         description: "Page Error"

所以我想要实现的是让客户端能够传回创建的令牌,并让该令牌进入我的节点服务以便对其进行解码。

非常感谢任何帮助..谢谢..

更新:

我发现有一个令牌被传递到我的后端服务。它与我传入的令牌不同。所以我从前端传入的令牌是:

eyJhbGciOiJSUz21Ni5sIn65cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiWHZY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rumdJ18SLnPoopHJG-GCzSJSmccSOTA

如果您想保留原始 authorization header,您必须停用端点身份验证。文档 here

在你的道路上,这样做:

paths:
  /auth/token/decode:
    get:
      summary: Auth Endpoint - Decode Token
      operationId: auth_endpoint_decode
      x-google-backend:
        address: {backend-host}
        protocol: h2
        disable_auth: true
      responses:
        200:
          description: "Token Decoded"
        400:
          description: "Page Error"