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.
var Authentic = require('authentic-client')
var auth = Authentic({
server: 'https://auth.scalehaus.io'
})
var creds = {
email: 'chet@scalehaus.io',
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)
})
})
npm install --save authentic-client
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)
Authentic()
takes an options object as its first argument, one of them is required:
server
: the url of theauthentic-server
, e.g.'http://auth.yourdomain.com'
Optional:
prefix
: defaults to'/auth'
if you set a custom prefix for yourauthentic-server
, use that same prefix hereauthToken
: if you have an authToken from a previous login, you may pass it in for immediate use inget
andpost
See authentic-server's Server API for usage
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)
Will make a request using an authToken if one is available, has the same API as jsonist.post
Will make a request using an authToken if one is available, has the same API as jsonist.put
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
)
MIT