plug-auth-client
Client library for third-party authentication with plug.dj.
Installation
npm install --save plug-auth-client
Usage
plug-auth-client uses Promises, which are not supported in Internet Explorer. If you want to support Internet Explorer, also include es6-promise in your script:
// After `npm install --save es6-promise`:
// or use AMD:
API
authenticate(options: object)
Authenticate with a remote server.
Options:
transport
: A transport instance. Required.user
: User ID to authenticate as. Defaults toAPI.getUser().id
, which is the current user ID on plug.dj.
httpTransport(options: object)
Create a transport that talks to a plug-auth-server-style HTTP authentication endpoint.
Options:
url
: URL of the endpoint to authenticate to. Use this option if thetoken
andverify
steps should both use the same URL, like when using the default plug-auth-server middleware.tokenUrl
: URL of the endpoint used to get a unique token that will be used to verify the user's identity. Defaults to the value of theurl
option.verifyUrl
: URL of the endpoint used to verify the user's identity. Defaults to the value of theurl
option.
Custom Transports
Transports are objects with a getToken
and a verify
method.
transport.getToken(options: {user: number})
Generate the verification token that will be put in the user's blurb. Should return a Promise for an object of the shape:
blurb
: Token to store in the blurb.
transport.verify(options: {user: number})
Ask the authentication endpoint to verify the token in the user's blurb. Should return a Promise for an object of the shape:
token
: Authentication token.