authentic-service
Version:
This is the service component of Authentic. This will help decode tokens so that you can authenticate users within a microservice.
30 lines (24 loc) • 717 B
JavaScript
const http = require('http')
const Authentic = require('../')
const auth = Authentic({
server: 'https://auth.scalehaus.io',
checkExpiredList: true
})
http
.createServer(function (req, res) {
// Step 1: decrypt the token
auth(req, res, function (err, authData) {
if (err) return console.error(err)
// Step 2: if we get an email and it's one we like, let them in!
if (authData && authData.email.match(/@scalehaus\.io$/)) {
res.writeHead(200)
res.end("You're in!")
// otherwise, keep them out!
} else {
res.writeHead(403)
res.end('Nope.')
}
})
})
.listen(1338)
console.log('Protected microservice listening on port', 1338)