3.0.0 • Published 5 years ago

oauth20 v3.0.0

Weekly downloads
87
License
-
Repository
github
Last release
5 years ago

OAuth 2.0

Build Status Coverage Status

This module is a implementation of OAuth 2.0 standard protocol for authorization - https://oauth.net/2/

You need nodejs version > 6x because this module was made with ES6.

node --version

Installation:

Add the latest version of oauth20 to your package.json:

npm install oauth20 --save

Usage:

let OAuth2 = require('oauth20');

Give the credentials of the OAuth to the constructor

ParamsDescriptionOptional
ClientIdThe Client Idfalse
ClientSecretThe Client Secretfalse
RedirectUrlThe RedirectUrl with format 'http://yourdomain/youraction'false
ScopesThe scopesfalse
AccessTokenThe access token if you have onefalse
UrlBaseThe url base of Authenticationfalse
UrlAuthorizateThe path of url Authorization. Default is authorizetrue
UrlTokenThe path of url Token. Default is tokentrue
let oauth2 = new OAuth2('clientId', 'clientSecret', 'http://yourdomain/youraction', 'scopes', 'accessToken', 'https://domain/oauth/', 'auth', 'token');

Authorization

To authenticate with OAuth you will call authorizationUrl and will return an URL, you will make a request with a browser and authorizate in OAuth. After that you will be redirect to RedirectUrl and you will get a code on QueryString ?code='hjqweassxzass'

let urlAuthorization = oauth2.authorizationUrl();

Get Access Token

For generate an access token and refresh token you have to call connect with the code you got on QueryString

ParamsDescriptionOptional
CodeThe code you got in the querystringfalse
oauth.connect(code);

Refresh Access Token

If you need refresh the access token, you have to call reconnect and send the refreshToken

ParamsDescriptionOptional
RefreshTokenThe refresh token you got in credentialsfalse
oauth.reconnect(refreshToken);

Get Credentials

If you need the credentials, you have to call getCredentials and you will get an object with:

{
  accessToken,
  refreshToken,
  expiresIn
}

Promises

If you add then to call you will take the success of response and if you add catch you will take the error of response.

oauth.connect(code)
	.then((res) => console.log(res)))
	.catch((err) => console.log(err)))
3.0.0

5 years ago

2.0.2

7 years ago

1.0.8

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago