Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

survey-monkey-oauth

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

survey-monkey-oauth

survey monkey oauth authencation.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

License: ISC 1.0

SurveyMonkey 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
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
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 :

Keywords

FAQs

Package last updated on 25 Jan 2021

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc