https://github.com/nagilum/oauth2-nodejs
A simple nodejs OAuth2 auth-code wrapper library.
https://github.com/nagilum/oauth2-nodejs
Last synced: 3 months ago
JSON representation
A simple nodejs OAuth2 auth-code wrapper library.
- Host: GitHub
- URL: https://github.com/nagilum/oauth2-nodejs
- Owner: nagilum
- License: mit
- Created: 2016-06-04T21:51:25.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-06T10:41:12.000Z (almost 9 years ago)
- Last Synced: 2025-01-16T13:47:43.185Z (4 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
A simple nodejs OAuth2 auth-code wrapper library.
## How to Create the Redirect
```js
var oauth2 = require('oauth2-nodejs'),
systemRedirectUri = oauth2.CreateRedirect(
{
clientId: 'my-client-id',
scope: 'email',
authUri: 'https://graph.facebook.com/oauth/authorize'
},
'https://awesome-domain.com/my-awesome-oauth-callback',
'en');
```This will give you a URI you can just forward the user too. They will sign in and give the app access, which will redirect back to: `https://awesome-domain.com/my-awesome-oauth-callback?code=XXX`
## How to Authenticate by Code
```js
var oauth2 = require('oauth2-nodejs');oauth2.AuthenticateByCode(
{
clientId: 'my-client-id',
clientSecret: 'my-client-secret',
scope: 'email',
accessTokenUri: 'https://graph.facebook.com/oauth/access_token'
},
'https://awesome-domain.com/my-awesome-oauth-callback',
'code-from-provider',
function (res) {
// res.accessToken
// res.expires
}
);
```The library will make a web request to the provider with the auth code given and, hopefully, return with a valid access token. You are now authorized with the given provider.