-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
13,159 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
dist | ||
node_modules | ||
coverage | ||
build | ||
build | ||
.travis | ||
.nyc_output | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
.DS_store | ||
dist | ||
dist | ||
.nyc_output | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ | |
*.html | ||
/coverage | ||
*.md | ||
build | ||
build | ||
.nyc_output | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- 12 | ||
install: | ||
- npm ci | ||
|
||
script: | ||
- npm run lint | ||
- npm run test:coverage | ||
|
||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
[](https://opensource.org/licenses/ISC) | ||
[](//npmjs.com/package/react-js-css-loaders) | ||
|
||
# survey monkey oauth # | ||
Oauth2 authentication tools for SurveyMonkey | ||
## Quick overview ## | ||
### Step 1: Configuration setup ### | ||
``` | ||
const lib = require('survey-monkey-oauth')({ | ||
clientId: process.env.clientId, | ||
clientSecret: process.env.clientSecret, | ||
baseURL: 'http://localhost:3000/', /* optional, default baseURL is http://localhost:3000/ */ | ||
redirectPath: '/callback/', /* optional, default redirectPath is /callback/ */ | ||
scope: 'scopes', | ||
}) | ||
``` | ||
### Step 2: Routes configuration ### | ||
``` | ||
if (req.url.match(/login/)) return lib.authorize(req, res) | ||
if (req.url.match(/callback/)) return lib.generateToken(req, res) | ||
``` | ||
|
||
### Step 3: Listening for response ### | ||
``` | ||
// on success | ||
lib.on('success', (tokenRes, res) => { | ||
console.log('success !!!', tokenRes.data) | ||
res.end('token successfully generated') | ||
}) | ||
// on failure | ||
lib.on('error', (errorRes, res) => { | ||
console.log('error', errorRes) | ||
}) | ||
``` | ||
### Usage ### | ||
#### [Using native-addons](https://github.com/amareshsm/survey-monkey-oauth/tree/master/demo/native-api) #### | ||
``` | ||
const http = require('http') | ||
const port = 3000 | ||
const hostname = '127.0.0.1' | ||
const lib = require('survey-monkey-oauth')({ | ||
clientId: process.env.clientId, | ||
clientSecret: process.env.clientSecret, | ||
baseURL: 'http://localhost:3000/', /* redirect url base */ | ||
redirectPath: '/callback/', /* redirect url pathname */ | ||
scope: '', /* scopes to request permissions from app users during OAuth */ | ||
}) | ||
/* on success */ | ||
lib.on('success', (tokenRes, res) => { | ||
console.log('success !!!', tokenRes.data) | ||
res.end('token successfully generated') | ||
}) | ||
/* on failure */ | ||
lib.on('error', (errorRes, res) => { | ||
console.log('error', errorRes) | ||
}) | ||
const server = http.createServer((req, res) => { | ||
res.statusCode = 200 | ||
res.setHeader('Content-Type', 'text/plain') | ||
if (req.url.match(/login/)) return lib.authorize(req, res) /* /login - initiates oauth authentication */ | ||
if (req.url.match(/callback/)) return lib.generateToken(req, res) /* /callback - initiates authorization process */ | ||
}) | ||
server.listen(port, hostname, () => { | ||
console.log(`Server running at http://${hostname}:${port}/`) | ||
}) | ||
``` | ||
##### ***Note: redirectPath and callback route which initiates authorization process must be the same** ##### | ||
#### [Using express](https://github.com/amareshsm/survey-monkey-oauth/tree/master/demo/express-framework) #### | ||
``` | ||
const express = require('express') | ||
const app = express() | ||
const port = 3000 | ||
const lib = require('survey-monkey-oauth')({ | ||
clientId: process.env.clientId, | ||
clientSecret: process.env.clientSecret, | ||
baseURL: 'http://localhost:3000/', /* redirect url base */ | ||
redirectPath: '/callback/', /* redirect url pathname */ | ||
scope: '', /* scopes to request permissions from app users during OAuth */ | ||
}) | ||
// on success | ||
lib.on('success', (tokenRes, res) => { | ||
console.log('success', tokenRes.data) | ||
res.end('token successfully generated') | ||
}) | ||
// on failure | ||
lib.on('error', (errorRes, res) => { | ||
console.log('error', errorRes) | ||
}) | ||
app.get('/', (req, res) => { | ||
res.send('Hello World!') | ||
}) | ||
app.get('/login/', (req, res) => { | ||
lib.authorize(req, res) /* /login - initiates oauth authentication */ | ||
}) | ||
app.get('/callback/', (req, res) => { | ||
lib.generateToken(req, res) /* /callback - initiates authorization process */ | ||
}) | ||
app.listen(port, () => { | ||
console.log(`Example app listening at http://localhost:${port}`) | ||
}) | ||
``` | ||
### samples available under `/demo` : ### | ||
|
||
* [using-node-native-addons](https://github.com/amareshsm/survey-monkey-oauth/tree/master/demo/native-api) | ||
* [using-express-framework](https://github.com/amareshsm/survey-monkey-oauth/tree/master/demo/express-framework) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const express = require('express') | ||
const app = express() | ||
const port = 3000 | ||
const lib = require('survey-monkey-oauth')({ | ||
clientId: 'your client id', | ||
clientSecret: 'your client secret', | ||
baseURL: 'http://localhost:3000/', | ||
redirectPath: '/callback/', | ||
scope: '', | ||
}) | ||
|
||
// on success | ||
lib.on('success', (tokenRes, res) => { | ||
console.log('success', tokenRes.data) | ||
res.end('token successfully generated') | ||
}) | ||
|
||
// on failure | ||
lib.on('error', (errorRes, res) => { | ||
console.log('error', errorRes) | ||
}) | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Hello World!') | ||
}) | ||
app.get('/login/', (req, res) => { | ||
lib.authorize(req, res) | ||
}) | ||
app.get('/callback/', (req, res) => { | ||
lib.generateToken(req, res) | ||
}) | ||
app.listen(port, () => { | ||
console.log(`Example app listening at http://localhost:${port}`) | ||
}) |
Oops, something went wrong.