Skip to content

Instantly share code, notes, and snippets.

@anabellaspinelli
Last active September 24, 2018 12:12
Show Gist options
  • Save anabellaspinelli/c91cd18b38cc381bd72b1c4c20665781 to your computer and use it in GitHub Desktop.
Save anabellaspinelli/c91cd18b38cc381bd72b1c4c20665781 to your computer and use it in GitHub Desktop.
Typeform OAuth Tutorial - Passport setup complete
const express = require('express')
const path = require('path')
const passport = require('passport')
const TypeformStrategy = require('passport-typeform')
const app = express()
app.set('view engine', 'ejs')
app.set('views', path.join(__dirname, '/views'))
app.use(passport.initialize())
app.use(passport.session())
passport.serializeUser((user, done) => done(null, user))
passport.deserializeUser((user, done) => done(null, user))
passport.use(
new TypeformStrategy(
{
// options for the typeform strategy
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: process.env.REDIRECT_URI,
scope: ['accounts:read', 'forms:write']
},
(accessToken, refreshToken, profile, cb) => {
// this is passport's verify callback
// it runs after exchanging the code for profile info
const { email, alias } = profile
cb(null, { access_token: accessToken, profile })
}
)
)
/* Routes */
app.get('/', (req, res) => res.render('home'))
app.listen(9010, () => {
console.log('app and running at http://localhost:9010')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment