0

I have an api generated through go-swagger. I am trying to put in a session check it is not firing as I expected. I followed an example that I found in github but didn't seem to work for me.

My code:

// 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")
    }

My Yaml (for the endpoint that I am curling):

/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'

Any help to see what I did incorrectly would be appreciated.

mornindew
  • 1,993
  • 6
  • 32
  • 54

1 Answers1

0

So, I was being an idiot...

The issue was that I forgot to add Security to my swagger yaml. Once I did that then my function was getting called.

operationId: authLogoutUser
        tags:
          - auth
        description:
          Allow users to log out and their session will be terminated
        produces:
          - application/json
        security:
          - SessionKeyHeader: []
mornindew
  • 1,993
  • 6
  • 32
  • 54