README
This is a JS SDK library specifically for MySM SSO.
Testing
npm run test
Deployment
To update SDK JS library, stage value can be dev, qa and prod:
npm run build:js:{stage}
To publish on NPM:
npm run publish:package:{stage}
How to Use Packages
As a script tag library:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script src="/path/to/sdk/sm-sso-sdk-1.0.0.js"></script>
<script>
(function() {
const sso = new mySM.SSO({
env: 'dev',
apiKey: 'your api key',
appId: 'you app id here',
appSecret: 'your app secret here',
withPopup: true
});
const loginPayload = {
customer_email: 'test@email.com',
customer_password: 'Qwerty@12345'
}
sso.login(loginPayload)
.then(function(response){
// handle the response here
})
.catch(function(error){
// handle error response here
});
})();
</script>
</body>
</html>
As an NPM module:
import {SSO, IInitParams, ILogin} from 'sm-sso-sdk';
// Please contact jason.mullings@smprime.com from access configurations
...
const ssoConfig: IInitParams = {
env: 'dev',
apiKey: 'your api key',
appId: 'you app id here',
appSecret: 'your app secret here',
withPopup: true
};
const sso = new SSO(ssoConfig);
const loginPayload: ILogin = {
customer_email: 'test@email.com',
customer_password: 'Qwerty@12345'
}
sso.login(loginPayload)
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Available Functions
Auth Popup
// open authentication popup
sso.showAuthPopup();
// catch authentication popup response
sso.authPopupCallback((response, error)=>{
// handle response here or error
console.log({ response, error })
});
Login
sso.login({
customer_email: 'test@email.com',
customer_password: 'Qwerty@12345'
})
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Logged User
// persist token on web browser storage
sso.loggedUser('token you received from login');
Is Logged User
// Return if user is logged in
sso.isLoggedUser();
Logout User
// destroy token to logout user session
sso.logoutUser('token you received from login');
Register
sso.register({
customer_firstname: 'fnametest',
customer_lastname: 'lnametest',
customer_mobile: 639101234567,
customer_email: 'test@yopmail.com',
customer_password: 'Qwerty@123'
})
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Forgot Password
sso.forgotPassword({
customer_mobile: 639101234567,
customer_email: 'test@yopmail.com'
})
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Activate Account
sso.activateAccount({
customer_otp: '123456',
customer_mobile: 639101234567,
customer_email: 'test@yopmail.com'
})
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Verify Account
// token value here is from activate account request
sso.verifyAccount({
token: 't0k3n'
})
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Resend Verification
// reverify token value here is from verify account request or failed login request when account was activated more than 48 hours
sso.resendVerification({
token: 't0k3n'
})
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Get User
// Input parameters are user ID and user token from login request
sso.getUser('12345', 't0k3n')
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Update User
// Input parameters are user ID and user token from login request
sso.updateUser('12345', 't0k3n', {
customer_firstname: 'updated first name'
})
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
User Exists
// Input parameter is user email
sso.userExists('test@yopmail.com')
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Delete User
// Input parameters are user ID and user token from login request and account password
sso.deleteUser('12345', 't0k3n', 'password')
.then(response => {
// handle the response here
})
.catch(error => {
// handle error response here
});
Get User Token
// Returns user token
sso.userToken();
Get App Token
// Returns app token
sso.appToken();