Socket
Socket
Sign inDemoInstall

client-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

client-oauth2

Straight-forward library for executing OAuth 2.0 flows and making API requests.


Version published
Weekly downloads
23K
decreased by-80.58%
Maintainers
1
Weekly downloads
 
Created

What is client-oauth2?

The client-oauth2 npm package is a client-side library for handling OAuth2 authentication flows. It supports various OAuth2 flows including Authorization Code, Implicit, Resource Owner Password Credentials, and Client Credentials. This package is useful for applications that need to interact with OAuth2-compliant services for authentication and authorization.

What are client-oauth2's main functionalities?

Authorization Code Flow

This feature demonstrates how to use the Authorization Code Flow with GitHub as the OAuth2 provider. It includes setting up the client with necessary URIs and scopes, redirecting the user to the authorization page, and handling the callback to obtain the access token.

const ClientOAuth2 = require('client-oauth2');

const githubAuth = new ClientOAuth2({
  clientId: 'abc',
  clientSecret: '123',
  accessTokenUri: 'https://github.com/login/oauth/access_token',
  authorizationUri: 'https://github.com/login/oauth/authorize',
  redirectUri: 'http://example.com/auth/github/callback',
  scopes: ['notifications', 'gist']
});

// Redirect the user to the authorization page
const uri = githubAuth.code.getUri();

// After the user is redirected back to your callback URL
githubAuth.code.getToken(window.location.href)
  .then(function (user) {
    console.log(user);
  });

Implicit Flow

This feature demonstrates how to use the Implicit Flow with GitHub as the OAuth2 provider. It includes setting up the client with necessary URIs and scopes, redirecting the user to the authorization page, and handling the callback to obtain the access token directly from the URL.

const ClientOAuth2 = require('client-oauth2');

const githubAuth = new ClientOAuth2({
  clientId: 'abc',
  authorizationUri: 'https://github.com/login/oauth/authorize',
  redirectUri: 'http://example.com/auth/github/callback',
  scopes: ['notifications', 'gist']
});

// Redirect the user to the authorization page
const uri = githubAuth.token.getUri();

// After the user is redirected back to your callback URL
githubAuth.token.getToken(window.location.href)
  .then(function (user) {
    console.log(user);
  });

Resource Owner Password Credentials Flow

This feature demonstrates how to use the Resource Owner Password Credentials Flow with GitHub as the OAuth2 provider. It includes setting up the client with necessary URIs and scopes, and obtaining the access token using the user's username and password.

const ClientOAuth2 = require('client-oauth2');

const githubAuth = new ClientOAuth2({
  clientId: 'abc',
  clientSecret: '123',
  accessTokenUri: 'https://github.com/login/oauth/access_token',
  scopes: ['notifications', 'gist']
});

// Get the user token using username and password
githubAuth.owner.getToken('username', 'password')
  .then(function (user) {
    console.log(user);
  });

Client Credentials Flow

This feature demonstrates how to use the Client Credentials Flow with GitHub as the OAuth2 provider. It includes setting up the client with necessary URIs and scopes, and obtaining the access token using the client credentials.

const ClientOAuth2 = require('client-oauth2');

const githubAuth = new ClientOAuth2({
  clientId: 'abc',
  clientSecret: '123',
  accessTokenUri: 'https://github.com/login/oauth/access_token',
  scopes: ['notifications', 'gist']
});

// Get the client token
githubAuth.credentials.getToken()
  .then(function (user) {
    console.log(user);
  });

Other packages similar to client-oauth2

Keywords

FAQs

Package last updated on 27 Jul 2015

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc