-
-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fastify-swagger: protect access of Swagger UI #465
Comments
It's not currently possible but it would be really useful, would you like to send a PR? |
The You can run this snippet to add it: const fastify = require('fastify')({ logger: true })
const docPrefix = '/docs'
fastify.register(require('fastify-basic-auth'), {
validate,
authenticate: true
}).after(() => {
fastify.addHook('onRoute', function hook (routeOptions) {
if (routeOptions.url.startsWith(docPrefix)) {
routeOptions.onRequest = fastify.basicAuth
}
})
})
function validate (username, password, req, reply, done) {
if (username === 'admin' && password === 'admin') {
done()
} else {
done(new Error('Winter is coming'))
}
}
fastify.register(require('fastify-swagger'), {
routePrefix: docPrefix,
.... And it works @simon-tannai Would you like to integrate it in our plugin out of the box? |
I'm +1 on hooks addition to the |
but this will lead that this check runs on every request made to the server..no? |
yes, that is basic authentication. Generally basic auth is saved in the browser for additional requests so it is transparent to user. |
Hello !
I'm using fastify-swagger to generate API documentation.
It's working fine but I would like to protect the access to Swagger UI with a simple username / password.
Is it possible do to it with fastify-swagger ?
The text was updated successfully, but these errors were encountered: