Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/oauth2-server

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/oauth2-server

TypeScript definitions for Node OAuth2 Server

  • 3.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
369K
increased by9.4%
Maintainers
1
Weekly downloads
 
Created

What is @types/oauth2-server?

@types/oauth2-server provides TypeScript type definitions for the oauth2-server package, which is a complete, compliant, and well-tested module for implementing an OAuth2 server in Node.js.

What are @types/oauth2-server's main functionalities?

Authorization Code Grant

This code demonstrates how to set up an authorization endpoint using the Authorization Code Grant type. The endpoint will handle authorization requests and return an authorization code.

const OAuth2Server = require('oauth2-server');
const Request = OAuth2Server.Request;
const Response = OAuth2Server.Response;

const oauth = new OAuth2Server({
  model: require('./model')
});

app.post('/authorize', (req, res) => {
  const request = new Request(req);
  const response = new Response(res);

  oauth.authorize(request, response)
    .then((code) => {
      res.json(code);
    }).catch((err) => {
      res.status(err.code || 500).json(err);
    });
});

Token Grant

This code demonstrates how to set up a token endpoint. The endpoint will handle token requests and return an access token.

app.post('/token', (req, res) => {
  const request = new Request(req);
  const response = new Response(res);

  oauth.token(request, response)
    .then((token) => {
      res.json(token);
    }).catch((err) => {
      res.status(err.code || 500).json(err);
    });
});

Token Authentication

This code demonstrates how to set up a secure endpoint that requires token authentication. The endpoint will return secure data if the token is valid.

app.get('/secure', (req, res) => {
  const request = new Request(req);
  const response = new Response(res);

  oauth.authenticate(request, response)
    .then((token) => {
      res.json({ message: 'Secure data' });
    }).catch((err) => {
      res.status(err.code || 500).json(err);
    });
});

Other packages similar to @types/oauth2-server

FAQs

Package last updated on 01 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc