Skip to content

Instantly share code, notes, and snippets.

@secretshardul
Created January 29, 2021 13:37
Show Gist options
  • Save secretshardul/2297681803be2a510f8e6f2b3f24800a to your computer and use it in GitHub Desktop.
Save secretshardul/2297681803be2a510f8e6f2b3f24800a to your computer and use it in GitHub Desktop.
The SDK is not accepting `secretKey` parameter. It should be accepted so authenticator can be displayed.
<html>
<head>
</head>
<body>
<h1>Sawo</h1>
<source>
<div id="sawo-container" style="height: 300px; width: 300px;"></div>
<!-- SDK broken -->
<!-- <script src="http://websdk.sawolabs.com/sawo.min.js"></script> -->
<script>
var DEV_MODE = !1,
baseURL = DEV_MODE ? "http://localhost:3000" : "https://websdk.sawolabs.com";
class Sawo {
constructor(e) {
(this.config = e),
(this.config.hostName = window.location.hostname),
(this.iframeID = Math.random().toString(36).substring(2, 15) + "sawo-iframe"),
(this.eventPrefix = Math.random().toString(36).substring(2, 15)),
window.addEventListener("message", (e) => {
if (e.origin === baseURL)
switch (e.data.event) {
case this.eventPrefix + "LOGIN_SUCCESS":
this.config.onSuccess && this.config.onSuccess(e.data.payload), this.removeForm();
break;
case this.eventPrefix + "LOAD_SUCCESS":
document
.getElementById(this.iframeID)
.contentWindow.postMessage({
event: this.eventPrefix + "LOAD_CONFIG",
payload: {
identifierType: this.config.identifierType,
apiKey: this.config.apiKey,
hostName: this.config.hostName,
secretKey: this.config.secretKey /** MISSING PARAM **/
}
}, "*");
break;
default:
console.log(e.data);
}
});
}
showForm() {
var e = document.getElementById(this.config.containerID),
t = document.createElement("iframe");
(t.id = this.iframeID), (t.style.border = 0), e.appendChild(t), (t.style.width = "100%"), (t.style.height = "100%"), (t.style.overflow = "scroll");
var i = `${baseURL}/?eventPrefix=${this.eventPrefix}`;
t.setAttribute("src", encodeURI(i));
}
removeForm() {
document.getElementById(this.iframeID).remove();
}
}
var config = {
// should be same as the id of the container created on 3rd step
containerID: "sawo-container",
// can be one of 'email' or 'phone_number_sms'
identifierType: "email",
// Add the API key copied from 2nd step
apiKey: "API_KEY",
secretKey: "SECRET_KEY", /** MISSING PARAM **/
// Add a callback here to handle the payload sent by sdk
onSuccess: (payload) => {
console.log(payload)
},
onError: (error) => {
console.log('Failed to connect', error)
}
};
try {
var sawo = new Sawo(config);
sawo.showForm();
} catch (error) {
console.error(error)
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment