fastify-oauth2-server
v1.0.1
Published
a @node-oauth/oauth2-server wrapper for fastify
Downloads
162
Maintainers
Readme
fastify-oauth2-server
Supports Fastify versions 4.x
Install
npm i fastify-oauth2-server
Usage
Require fastify-oauth2-server
and register.
const fastify = require("fastify")();
fastify.register(require("fastify-oauth2-server"), {
model: {}, // See https://github.com/node-oauth/node-oauth2-server for specification,
// ...oauth2-server options
});
// Token route
fastify.post("/", fastify.oauthServer.token());
// Authorize route
fastify.post(
"/",
fastify.oauthServer.authorize({
authenticateHandler: {
handle: async (request) => {
// authorization logic here
return user;
},
},
})
);
// Protected route
fastify.get(
"/",
{ preValidation: fastify.oauthServer.authenticate() },
(request, reply) => reply.send("Protected route")
);
fastify.listen({ port: 3000 });
TODOS
1.Add tests
Acknowledgements
License
Licensed under MIT.