首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >go-swagger不调用我的标题检查

go-swagger不调用我的标题检查
EN

Stack Overflow用户
提问于 2018-08-28 07:45:31
回答 1查看 462关注 0票数 0

我有一个通过go-swagger生成的api。我正在尝试进行会话检查,它没有像我预期的那样触发。我使用了我在github中找到的一个example,但似乎对我不起作用。

我的代码:

代码语言:javascript
复制
// Applies when the "X-Session-Key" header is set
    api.SessionKeyHeaderAuth = func(token string) (interface{}, error) {
    // test the token
    success := routeHandler.HandleSessionHeaderKey(token)
    if success{
        return nil, nil
    }
    //We are pessimistic, if they aren't successful then we return a 401
    api.Logger("Access attempt with incorrect api key auth: %s", token)
    return nil, errors.New(401, "incorrect api key auth")
    }

我的Yaml (对于我正在冰壶的端点):

代码语言:javascript
复制
/auth/logout:
  post:
    summary: Logs in the user
    consumes:
      - application/x-www-form-urlencoded
    operationId: authLogoutUser
    tags:
      - auth
    description:
      Allow users to log out and their session will be terminated
    produces:
      - application/json
    parameters:
      - in: header
        name: X-Session-Key
        type: string
        required: true
      - in: header
        name: X-Profile-Key
        type: string
        required: true
    responses:
      200:
       description: Login Success
       headers:
        ProfileKeyHeader:
          type: string
          description: The key for the profile data
        SessionKeyHeader:
          type: string
          description: The key for the session data
      400:
       description: Whether the user is not found or error while login, decided on a generic login failure error
       schema:
        $ref: 'definitions.yaml#/definitions/Error'
      429:
       description: Too many requests and being throttled
       schema:
        $ref: 'definitions.yaml#/definitions/Error'
      500:
        description: Too many requests and being throttled
        schema:
          $ref: 'definitions.yaml#/definitions/Error'

如果你能帮助我发现我做错了什么,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2018-08-28 22:27:52

所以,我就像个笨蛋...

问题是我忘了在我的swagger中添加Security。一旦我这样做了,我的函数就会被调用。

代码语言:javascript
复制
operationId: authLogoutUser
        tags:
          - auth
        description:
          Allow users to log out and their session will be terminated
        produces:
          - application/json
        security:
          - SessionKeyHeader: []
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52048275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档