node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

oauthjs

oauthjs

oAuthjs is a simple and lightweight nodejs module to use oauth2

usage

get the authentication url

import {OAuth2, OAuth2Configuration, OAuth2GrantTypes} from 'oauthjs'
 
let clientId = 'your_clientid';
let clientSecret =  'your_clientsecret';
let baseSite = 'https://github.com/';
let authorizePath = 'login/oauth/authorize';
let accessTokenPath = 'login/oauth/token';
let config = new OAuth2Configuration(baseSite, authorizePath, accessTokenPath, clientId, clientSecret, this.getRedirectUri());
 
let oauth2 = new OAuth2();
let authUrl = oauth2.getAuthUrl(config,OAuth2GrantTypes.code);

get code from url

import {OAuth2, OAuth2Configuration, OAuth2GrantTypes} from 'oauthjs'
 
let url = 'https://localhost/your_return_path?code=12345';
let code = new oauth2().getAuthCode(url);

get authentication token

import {OAuth2, OAuth2Configuration, OAuth2GrantTypes} from 'oauthjs'
 
let clientId = 'your_clientid';
let clientSecret =  'your_clientsecret';
let baseSite = 'https://github.com/';
let authorizePath = 'login/oauth/authorize';
let accessTokenPath = 'login/oauth/token';
let config = new OAuth2Configuration(baseSite, authorizePath, accessTokenPath, clientId, clientSecret, this.getRedirectUri());
 
let oauth2 = new OAuth2();
return this.oauth2.getAuthToken(config, code);