Skip to content

mohamednehad450/fastify-oauth2-server

Repository files navigation

fastify-oauth2-server

js-standard-style

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published