Last active
November 13, 2015 22:58
-
-
Save davidguttman/7a5fdacd9f950e94ec6d to your computer and use it in GitHub Desktop.
dry.ly/authentic examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
"main": "index.js", | |
"scripts": { | |
"start": "wzrd index.js" | |
}, | |
"keywords": [], | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"success": true, | |
"message": "User created. Check email for confirmation link.", | |
"data": { | |
"email": "chet@scalehaus.io", | |
"createdDate": "2015-11-12T21:36:20.021Z" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openssl genrsa 4096 > rsa-private.pem | |
openssl rsa -in rsa-private.pem -pubout > rsa-public.pem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir scale-admin | |
cd scale-admin | |
npm init -y | |
touch index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir scale-auth | |
cd scale-auth | |
npm init -y | |
npm install --save authentic-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir scale-reports | |
cd scale-reports | |
npm init -y | |
npm install --save authentic-service | |
touch server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ type: 'signup', | |
email: 'chet@scalehaus.io', | |
confirmUrl: 'http://localhost:9966/?confirmToken=4d10ed4dd4321b265a2186694a3d786bba4b62ff01dd61b2311e17c46a40&email=chet%40scalehaus.io#/confirm', | |
confirmToken: '4d10ed4dd4321b265a2186694a3d786bba4b62ff01dd61b2311e17c46a40' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server.js | |
var fs = require('fs') | |
var http = require('http') | |
var Authentic = require('authentic-server') | |
var auth = Authentic({ | |
db: __dirname + '/db', | |
publicKey: fs.readFileSync(__dirname + '/rsa-public.pem'), | |
privateKey: fs.readFileSync(__dirname + '/rsa-private.pem'), | |
sendEmail: function (email, cb) { | |
console.log(email) | |
setImmediate(cb) | |
} | |
}) | |
http.createServer(auth).listen(1337) | |
console.log('Authentic enabled server listening on port', 1337) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http') | |
var Authentic = require('authentic-service') | |
var auth = Authentic({ | |
server: 'http://localhost:1337' | |
}) | |
var authorized = [ 'your@email.com' ] | |
http.createServer(function (req, res) { | |
auth(req, res, function (err, authData) { | |
if (err) return console.error(err) | |
if (!authData) return respond(res, 401, {error: 'Not authenticated.'}) | |
if (authorized.indexOf(authData.email) >= 0) { | |
return respond(res, 200, { | |
success: true, message: authData.email + ' is on the list.' | |
}) | |
} | |
respond(res, 403, {error: 'Not on the list.'}) | |
}) | |
}).listen(1338) | |
console.log('Protected microservice listening on port', 1338) | |
function respond (res, status, obj) { | |
res.writeHead(status, {'content-type': 'application/json'}) | |
res.end(JSON.stringify(obj)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl 'http://localhost:1337/auth/signup' -X POST -d '{ | |
"email": "chet@scalehaus.io", | |
"password": "notswordfish", | |
"confirmUrl": "http://localhost:9966/#/confirm" | |
}' -H 'Content-Type: application/json' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment