Webmaker auth client
This is the client-side library that adds support for Webmaker Login to your app. In order for it to work, you will need the following on your app's server:
- express
- webmaker-auth, the sister node module for this library
If you choose to use the create user form assets included in this package, you will also need node-webmaker-l18n for localization and nunjucks for server-side rendering.
Install
bower install webmaker-auth-client --save
What's included?
# Main js file webmaker-auth-client.js # Create new user form assets create-user/ create-user-form.css create-user-form.html # Localized strings for create new user form locale/ en_US/ create-user-form.json # Minified file (~11kb) packaged with dependencies. dist/ webmaker-auth-client.min.js
Example
There is a fully-featured example in the examples directory that you can run locally. It uses server-side rendering with nunjucks and webmaker-i18n, so you may need to modify the example to get it to work in your environment.
Require-js
requirejs; ;
Configure
var auth = host: '' paths: authenticate: '/authenticate' create: '/create' verify: '/verify' logout: '/logout' csrfToken: 'YOURCSRFTOKEN' audience: windowlocationorigin prefix: 'webmaker-' // for local storage timeout: 10 handleNewUserUI: true // Do you want to auto-open/close the new user UI?;
Listen to events
auth;auth;
login
(userData, [message])
When a user logs in or a session is automatically restored.
The message
parameter is one of:
null
: on a successful check from the serverrestored
: if the data was restored from local storageemail mismatch
: if the email was different in local storage v.s. on the serveruser created
: if a new user was created an logged in
error
(errorMessage)
When an error happens. Check the error message for more information.
logout
(no parameters)
When user logs out or is logged out due to an error, or when no user session exists.
Session restore and SSO
To automatically login users and set up SSO, you must call
auth;
Login/Logout
auth;auth;