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

oauth

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oauth

Library for interacting with OAuth 1.0, 1.0A, 2 and Echo. Provides simplified client access and allows for construction of more complex apis and OAuth providers.

  • 0.10.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8M
decreased by-10.79%
Maintainers
1
Weekly downloads
 
Created

What is oauth?

The 'oauth' npm package is a library that allows developers to implement OAuth authentication in their Node.js applications. OAuth is an open standard for access delegation, commonly used to grant websites or applications access to user information on other websites without giving them the passwords. This package supports both OAuth 1.0A and OAuth 2.0 protocols.

What are oauth's main functionalities?

Creating an OAuth 1.0A client

This code sample demonstrates how to create an OAuth 1.0A client for interacting with a service like Twitter. It initializes the OAuth client with the necessary endpoints and credentials.

const OAuth = require('oauth').OAuth;
let oauth = new OAuth(
  'https://api.twitter.com/oauth/request_token',
  'https://api.twitter.com/oauth/access_token',
  'your_consumer_key',
  'your_consumer_secret',
  '1.0A',
  null,
  'HMAC-SHA1'
);

Signing OAuth 1.0A requests

This code sample shows how to sign OAuth 1.0A requests to access protected resources, such as a user's account information on Twitter. It uses the 'get' method of the OAuth client.

oauth.get(
  'https://api.twitter.com/1.1/account/verify_credentials.json',
  'your_access_token', // user token
  'your_token_secret', // user secret
  function (e, data, res) {
    if (e) console.error(e);
    console.log(require('util').inspect(data));
  }
);

Creating an OAuth 2.0 client

This code sample demonstrates how to create an OAuth 2.0 client for interacting with a service like Google. It initializes the OAuth2 client with the necessary endpoints and credentials.

const OAuth2 = require('oauth').OAuth2;
let oauth2 = new OAuth2(
  'your_client_id',
  'your_client_secret',
  '',
  'https://accounts.google.com/o/oauth2/auth',
  'https://accounts.google.com/o/oauth2/token',
  null
);

Getting OAuth 2.0 access token

This code sample shows how to get an OAuth 2.0 access token using the client credentials grant type. The access token can then be used to authenticate API requests.

oauth2.getOAuthAccessToken(
  '',
  {'grant_type':'client_credentials'},
  function (e, access_token, refresh_token, results){
    console.log('bearer: ',access_token);
  }
);

Other packages similar to oauth

FAQs

Package last updated on 22 Jul 2022

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