Giter VIP home page Giter VIP logo

pmmon4privato / authentic-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from davidguttman/authentic-client

0.0 0.0 0.0 291 KB

The client component of Authentic. This helps interact with an `authentic-server` so that you can easily signup, confirm, login, and change-password for users. It will also help send tokens to microservices that require authentication.

JavaScript 100.00%

authentic-client's Introduction

AuthenticClient

The client component of authentic. This helps interact with an authentic-server so that you can easily signup, confirm, login, and change-password for users. It will also help send tokens to microservices that require authentication.

Example

var Authentic = require('authentic-client')

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

var creds = {
  email: '[email protected]',
  password: 'notswordfish'
}

// Step 1: log in
auth.login(creds, function (err) {
  if (err) return console.error(err)

  // Step 2: make a JSON request with authentication
  var url = 'https://reporting.scalehaus.io/report'
  auth.get(url, function (err, data) {
    // show that report
    console.log(data)
  })
})

Installation

npm install --save authentic-client

API

Authentic(opts)

This is the main entry point. Accepts an options object and returns an object with helper methods.

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

// auth is now an object with various methods:
auth.signup(opts, cb)
auth.confirm(opts, cb)
auth.login(opts, cb)
auth.changePasswordRequest(opts, cb)
auth.changePassword(opts, cb)

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
  • authToken: if you have an authToken from a previous login, you may pass it in for immediate use in get and post

auth.signup(opts, cb)

auth.confirm(opts, cb)

auth.login(opts, cb)

auth.changePasswordRequest(opts, cb)

auth.changePassword(opts, cb)

See authentic-server's Server API for usage

auth.get(url, opts, cb)

Will make a request using an authToken if one is available, has the same API as [jsonist.get] (https://github.com/rvagg/jsonist#jsonistgeturl--options--callback)

auth.post(url, data, opts, cb)

Will make a request using an authToken if one is available, has the same API as jsonist.post

auth.put(url, data, opts, cb)

Will make a request using an authToken if one is available, has the same API as jsonist.put

auth.delete(url, opts, cb)

Will make a request using an authToken if one is available, has the same API as [jsonist.delete] (https://github.com/rvagg/jsonist#jsonistdeleteurl--options--callback)

If token is present, it will be verified before request against authentic-server's public key, and options will be extended with authorization header prior to sending request. It will use Bearer ${token} scheme.

You can also call verifyToken explicitly yourself and provide a callback. (In case of invalid token, err is going to be provided by jsonwebtoken)

auth.verifyToken(function(err){ ... })

License

MIT

authentic-client's People

Contributors

davidguttman avatar kahuna-celsius avatar jvdanilo avatar 0xvolodya 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.