Skip to content

Instantly share code, notes, and snippets.

View tr00gle's full-sized avatar

Ryan Trontz tr00gle

View GitHub Profile
@tr00gle
tr00gle / basic_auth_nodejs_test.js
Created June 21, 2018 18:27 — forked from charlesdaniel/basic_auth_nodejs_test.js
Example of HTTP Basic Auth in NodeJS
var http = require('http');
var server = http.createServer(function(req, res) {
// console.log(req); // debug dump the request
// If they pass in a basic auth credential it'll be in a header called "Authorization" (note NodeJS lowercases the names of headers in its request object)
var auth = req.headers['authorization']; // auth is in base64(username:password) so we need to decode the base64
console.log("Authorization Header is: ", auth);