4.2.2 Using user pools with Bayun AWSS3 wrapper 'SecureAuthentication'
Here User Registration, SignUp Confirmation, SignIn, SignOut needs to be done with SecureAuthentication instance.
Before creating SecureAuthentication instance, user have to declear these following parameters of AWS and Bayun which will be further used by Bayun AWSS3 wrapper 'SecureAuthentication'.
window._config = {
cognito: {
userPoolId: "<userPoolId>", // e.g. us-east-2_uXboG5pAb
region: "<region>", // e.g. us-east-2
clientId: "<clientId>", // e.g. 7asdfvasdasdufe7hf47fhasd
},
};
const BayunConstants = {
BAYUN_APP_ID: "<BAYUN_APP_ID>", // provided on admin panel
BAYUN_APP_SALT: "<BAYUN_APP_SALT>", // provided on admin panel
BAYUN_APP_SECRET: "<BAYUN_APP_SECRET>", // provided on admin panel
ENABLE_FACE_RECOGNITION: false | true,
BASE_URL: "<BASE_URL>", // provided on admin panel
};
Set Up the SecureAuthentication object
The SecureAuthentication is a JavaScript class, and must be provided with companyName before using it.
var secureAuthentication = new SecureAuthentication("<companyName>");
Register a User
Use SecureAuthentication's method register to register a new user instead of relying on standard AWS SDK's signUp method.
var registerBayunWithPwd = true | false;
var companyName = "<CompanyName>";
var companyEmployeeId = "<companyEmployeeId>";
var email = "<email>";
var password = "<password>";
var confirmPassword = "<confirmPassword>";
if (password != confirmPassword) {
throw "Passwords Do Not Match!"
}
var secureAuth = new SecureAuthentication(companyName);
let sessionId = "<sessionId>"; // eg. "4h5u45u45"
await secureAuth.register(sessionId, companyEmployeeId, email, password, registerBayunWithPwd);
Confirm Signup
Confirm a users' sign up with the confirmation code using SecureAuthentication's confirmSignUp method. Use this method instead of CognitoUser's method, to confirm signup with both Cognito and Bayun.
let email = "<email>";
let code = "<code>";
var companyName = "<CompanyName>";
var secureAuth = new SecureAuthentication(companyName);
secureAuth.confirmSignUp(email,code);
Sign in a user
Use SecureAuthentication's signIn method to get a session, using email and password, with both Cognito and Bayun, instead of CognitoUser's method.
var loginWithPwd = false | true;
var email = "<email>"; //required if loginWithPwd is false
var companyName = "<CompanyName>";
var companyEmployeeId = "<companyEmployeeId>";
var password = "<password>"; //required if loginWithPwd is true
let sessionId = "<sessionId>"; // eg. "4h5u45u45"
var secureAuth = new SecureAuthentication(companyName);
sessionId = await secureAuth.login(sessionId, companyEmployeeId, email, password, loginWithPwd);
Sign out a user
Use SecureAuthentication's signOut method to clear all tokens and logout of Bayun as well, instead of using CognitoUser's method. User will have to go through the authentication process to get tokens.
var companyName = "<CompanyName>";
var secureAuth = new SecureAuthentication(companyName));
secureAuth.signOut();