Skip to content

Instantly share code, notes, and snippets.

Avatar

Perry Donham pdonham

View GitHub Profile
@pdonham
pdonham / UserWithCrypto.js
Last active November 24, 2020 06:16
Sample code for Using JWTs for Authentication in RESTful Applications (http://sites.bu.edu/perryd/?p=259)
View UserWithCrypto.js
/*
For this version we'll add a register method to add a user to the database using proper
password encryption. It also demonstrates how to add and use a method on a schema.
Reference: https://www.sitepoint.com/user-authentication-mean-stack
*/
const mongoose = require('mongoose')
const crypto = require('crypto')
//const findOrCreate = require('mongoose-findorcreate')
//Set up ES6 Promises
@pdonham
pdonham / oauthTwitterNoPassport.js
Last active December 2, 2017 16:34
Three-step OAuth with Twitter demonstrating both authentication and authorization
View oauthTwitterNoPassport.js
/* An example showing OAuth 1.0 against Twitter, based on a post at
http://moonlitscript.com/post.cfm/how-to-use-oauth-and-twitter-in-your-node-js-expressjs-app/
Comments are mine - PCD
*/
//Get a router instance
//
const express = require('express')
const router = express.Router()
@pdonham
pdonham / request-promises.js
Created July 12, 2017 01:08
Using async.waterfall to synchronize aggregation of results when using promises
View request-promises.js
/*
Small demo to show chaining of API calls. We're using these APIs:
https://weathers.co for current weather in 3 cities, and
https://api.github.com/search/repositories?q=<term> to search GitHub repos for
the 'hottest' city. For example, we'll grab weather for 3 cities, pick the hottest one,
then hit GitHub with a search for repos that have that city's name. A bit nonsensical
but I just wanted to demonstrate using the results of one API call to populate a second.
The problem we're trying to solve is that the API calls are asynch, and one of them
(getCityTemperatures) loops through several asynch calls (one for each city), and they