krakenjs / generator-swaggerize

Yeoman generator for design-driven apis with swagger 2.0 and krakenjs/swaggerize tools.
Other
70 stars 34 forks source link

configuring security for type basic #101

Closed arozwalak closed 7 years ago

arozwalak commented 7 years ago

on my swagger file I'm using securityDefinitions and security in paths using type basic. I'm not quite sure how to configure security js files to be able to communicate with requests which are looking this security

ie. in my swagger file

securityDefinitions:
  test:
    type: basic

[...]

paths: 
   /ping:
      get:
        x-method-name: ping
        description:
          Return an OK status if it is available.t
        security:
          - test: []
        produces:
          - application/json
        responses:
          '200':
            description:
              The response was succesfully processed
          '401':
            description: The user is not authorized to make this request
          '500':
            description: An internal error has occurred

how should security/test.js file looks like

module.exports = function authorize(req, res, next) {
    //The context('this') for authorize will be bound to the 'securityDefinition'

    //Perform auth here

    next();
};

when I'm hitting /sample-path which has security 'basic' on get I'm receiving unauthorize. How I should configure authorize function in security js file to be able to retrieve correct response. Thanks for help

arozwalak commented 7 years ago

I found out that I need to add security property in Swaggerize options. Works fine now