Giter VIP home page Giter VIP logo

authentic-service's Introduction

AuthenticService

This is the service component of authentic. This will help decode tokens so that you can authenticate users within a microservice.

Example

var http = require('http')
var Authentic = require('authentic-service')

var auth = Authentic({
  server: 'https://auth.scalehaus.io'
})

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)

Installation

npm install --save authentic-service

API

Authentic(opts)

This is the main entry point. Accepts an options object and returns a function that can parse and decrypt tokens from http requests.

var auth = Authentic({
  server: 'https://auth.scalehaus.io'
})

// auth is now a function that accepts req, res, and a callback
auth(req, res, function(err, authData) { ... })

options

Authentic() takes an options object as its first argument, one of them is required:

  • server: the url of the authentic-server, e.g. 'http://auth.yourdomain.com'

Optional:

  • prefix: defaults to '/auth' if you set a custom prefix for your authentic-server, use that same prefix here
  • cacheDuration: defaults to 3600000 (1 hour in milliseconds). To minimize latency and requests, this is how long authentic-service will cache the authentic-server public key.

License

MIT

authentic-service's People

Contributors

davidguttman avatar kahuna-celsius avatar santoshdeshpande avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.