Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// define libraries you would need
var oauth = require('oauth')
var AWS = require('aws-sdk')
var cuid = require('cuid')
// define your OAuth-application credentials
var twitterConsumerKey = 'xxxxxxxxxxxxxxxxxxxx'
var twitterConsumerSecret = 'xxxxxxxxxxxxxxxxxxxx'
// ensure AWS is requesting the nearest region
region: 'eu-west-1'
// the function that will be executed by Lambda
exports.handler = function (event, context) {
// define unique token to identify callback data for which user it is ment
var idToken = cuid()
// define OAuth signature
var api = new oauth.OAuth(
'' + idToken,
// get request token and redirect users to that URL
api.getOAuthRequestToken(function (error, oauthToken, oauthTokenSecret, result) {
if (error) {
} else {
// store tokens to be able to map the data correctly
var db = new DBConnector() // this can be DynamoDB, Firebase, etc..
var params = {
table: 'feed-users',
item: {
id: oauthToken,
secret: oauthTokenSecret,
idToken: idToken
// save tokens to use with the callback
db.put(params, function (err, data) {
if (err) {
console.error('Unable to add item. Error JSON:', JSON.stringify(err, null, 2))
} else {
console.log('Added item:', JSON.stringify(data, null, 2), token)
// redirect user to correct URL to acknowledge the new share settings
location: '' + oauthToken

This comment has been minimized.

Copy link

@RhysC RhysC commented Aug 7, 2016

hey - console.log('Added item:', JSON.stringify(data, null, 2), token) - token is not defined, you mean idToken/oauthToken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment