eh-auth
v0.3.5
Published
Employment Hero Authentication SDK
Downloads
4
Readme
Auth JS
Auth flow
Access token expired and user session expired
Access token expired and create new token success
How to Use
Inject this code into your HTML file.
<script id="auth-sdk" src="../lib/EAuth.min.js" />
<script>
var apiURL = <authServiceURL>;
var eauth = new EAuth(apiURL);
eauth.setRedirectLoginURL(<loginURL>);
eauth.onTokenReceived = function(data) {
console.log('data', data);
// Save your token here
<authDataHandler>
}
eauth.onTokenReceivedError = function(error) {
console.log('data', data);
<authDataErrorHandler>
}
Your need to replace:
<authServiceURL>
- URL to auth service<loginURL>
- Redirect URL when you get response 401<authDataHandler>
- Data handler, usually use to store access token to redux store<authDataErrorHandler>
- Beside redirect to login page, what do you want to do? Usually use to handle status code !== 401
Auth instance method
constructor(authURL)
- Create Auth instance with auth service URLsetRedirectLoginURL
- Set redirect link to login page. ifrequestToken
orforceRequestToken
response status is 401, it will redirect to login pagerequestToken
- Request token from local storage and validate it. If invalidate, call to Auth service to get newforceRequestToken
- call to Auth service to get new access tokenonTokenReceived
- Callback to handle access token return byrequestToken
orforceRequestToken
onTokenReceivedError
- Callback to handle error return byrequestToken
orforceRequestToken
. Note: if status is 401, it will redirect to login page.
Development
Scripts
npm run build
- produces production version of your library under thelib
foldernpm run diagrams
- Re draw diagramsnpm run dev
- produces development version of your library and runs a watchernpm run test
- well ... it runs the tests :)npm run test:watch
- same as above but in a watch mode
Demo
pushstate-server ./
Go to http://localhost:9000/demo/