hapi-swagger / hapi-swagger

A Swagger interface for hapi
https://hapi.dev/
MIT License
913 stars 420 forks source link

File Upload causes Auth validation function to not be called. #192

Closed shanemcnamara11 closed 8 years ago

shanemcnamara11 commented 8 years ago

I have added file uploading in the same way as the example code

method: 'POST',
    path: '/store/file/',
    config: {
        handler: handlers.storeAddFile,
        plugins: {
            'hapi-swagger': {
                payloadType: 'form'
            }
        },
        tags: ['api'],
        validate: {
            payload: {
                file: Joi.any()
                    .meta({ swaggerType: 'file' })
                    .description('json file')
            }
        },
        payload: {
            maxBytes: 1048576,
            parse: true,
            output: 'stream'
        },
        response: {schema : sumModel}

I am also using hapi-auth-jwt as my default auth strategy. My JWT auth strategy calls a validation function to determine if the given JWT is valid. For all my APIs this validation function is called, except the route for file uploading (i.e. the one above). The above route gives me a 401 error, but does not call the validation function.

I can set auth to false, but I don't want anyone to be able to upload files to my database. I'm not sure if this is an issue with hapi-swagger or hapi-auth-jwt, but I can only repeat the error with the above code so I posted it here.

shanemcnamara11 commented 8 years ago

Nevermind. I had written my own stuff to allow the user to add a JWT in the Swagger UI, but I had not hooked correctly into the file upload part of swagger-ui.js