cordova-plugin-mas-core
Version:
Cordova MAS Foundation Plugin
187 lines (154 loc) • 7.54 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: MASPluginCallbacks.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: MASPluginCallbacks.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/*
* Copyright (c) 2016 CA, Inc. All rights reserved.
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*/
var MASPluginConstants = require("./MASPluginConstants"),
MASPluginUtils = require("./MASPluginUtils");
var MASPluginCallbacks = {
customAuthHandler:null,
setCustomAuthHandler: function(authHandler){
this.customAuthHandler = authHandler;
},
removeCustomAuthHandler: function(){
this.customAuthHandler = null;
},
/**
* Callback where it will prompt for login Credentials.
* @param {function} callbackResp user defined callback object containing the relevant details of callback.
*/
MASAuthenticationCallback: function(callbackResp) {
const error = callbackResp.error;
const result = callbackResp.result;
const requestType = result.requestType;
if(requestType === 'Login'){
if(document.getElementById('popUp') !== null || document.getElementById('popup') !== null){
return;
}
if(result.requestId !== 'undefined' && !MASPluginUtils.isEmpty(result.requestId)){
MASPluginConstants.MASLoginAuthRequestId = result.requestId;
}
if(!MASPluginUtils.isEmpty(MASPluginCallbacks.customAuthHandler)){
MASPluginCallbacks.customAuthHandler(result);
return;
}
let oncloseFunc = function(){
MASPluginUtils.closePopup();
};
let onLoadFunc = function(){
window.localStorage.removeItem("masCallbackResult")
};
MASPluginUtils.setPopUpStyle(MASPluginConstants.MASPopupStyle.MASPopupLoginStyle);
MASPluginUtils.MASPopupUI(MASPluginConstants.MASLoginPage,result,oncloseFunc,onLoadFunc);
}else if(requestType == "removeQRCode"){
let event = null;
if(!MASPluginUtils.isEmpty(error)){
const callbackJSON = {"requestType":requestType,"error":error};
if(!MASPluginUtils.isEmpty(MASPluginCallbacks.customAuthHandler)){
MASPluginCallbacks.customAuthHandler(callbackJSON);
return;
}
event = new CustomEvent("errorEvent",{"detail":callbackJSON});
}else{
if(!MASPluginUtils.isEmpty(MASPluginCallbacks.customAuthHandler)){
MASPluginCallbacks.customAuthHandler(result);
return;
}
event = new CustomEvent(requestType);
}
document.body.dispatchEvent(event);
}else if(requestType == "qrCodeAuthorizationComplete"){
if(!MASPluginUtils.isEmpty(error)){
const callbackJSON = {"requestType":requestType,"error":error};
if(!MASPluginUtils.isEmpty(MASPluginCallbacks.customAuthHandler)){
MASPluginCallbacks.customAuthHandler(callbackJSON);
return;
}
let errorEvent = new CustomEvent("errorEvent",{"detail":callbackJSON});
document.body.dispatchEvent(errorEvent);
}else{
if(!MASPluginUtils.isEmpty(MASPluginCallbacks.customAuthHandler)){
MASPluginCallbacks.customAuthHandler(result);
return;
}
MASPluginUtils.closePopup();
}
}
},
/**
* Callback which is used to prompt for the OTP provided channels
* @param {function} callbackResp user defined callback object containing the OTP Channels as defined by MAG Server.
*/
MASOTPChannelSelectCallback: function(callbackResp) {
const error = callbackResp.error;
// TODO: How to handle error here, since the popup is still not open
if(!MASPluginUtils.isEmpty(error)){
console.log("Error in OTPChannelCallback:"+JSON.stringify(error));
return;
}
const result = callbackResp.result;
let oncloseFunc = function(){
MASPluginUtils.closePopup();
};
let onLoadFunc = function() {
window.localStorage.removeItem("masCallbackResult")
}
MASPluginUtils.setPopUpStyle(MASPluginConstants.MASPopupStyle.MASPopupOTPStyle);
MASPluginUtils.MASPopupUI(MASPluginConstants.MASOTPChannelsPage,result,oncloseFunc,onLoadFunc);
},
/**
* Callback for the OTP Listener
* @param {function} callbackResp user defined callback object containing the OTP failure error message. Called in case of invalid/expired OTP.
*/
MASOTPAuthenticationCallback: function(callbackResp){
const error = callbackResp.error;
// TODO: How to handle error here, since the popup is still not open
if(!MASPluginUtils.isEmpty(error)){
console.log("Error in OTPChannelCallback:"+JSON.stringify(error));
return;
}
const result = callbackResp.result;
let oncloseFunc = function(){
MASPluginUtils.closePopup();
};
let onLoadFunc = function() {
window.localStorage.removeItem("masCallbackResult")
};
MASPluginUtils.setPopUpStyle(MASPluginConstants.MASPopupStyle.MASPopupOTPStyle);
MASPluginUtils.MASPopupUI(MASPluginConstants.MASOTPPage,result,oncloseFunc,onLoadFunc);
}
};
module.exports = MASPluginCallbacks;</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="MASPlugin.html">MASPlugin</a></li><li><a href="MASPluginApplication.html">MASPluginApplication</a></li><li><a href="MASPluginAuthProviders.html">MASPluginAuthProviders</a></li><li><a href="MASPluginConstants.html">MASPluginConstants</a></li><li><a href="MASPluginDevice.html">MASPluginDevice</a></li><li><a href="MASPluginMAS.html">MASPluginMAS</a></li><li><a href="MASPluginMultipartForm.html">MASPluginMultipartForm</a></li><li><a href="MASPluginSecurityConfiguration.html">MASPluginSecurityConfiguration</a></li><li><a href="MASPluginUser.html">MASPluginUser</a></li><li><a href="MASPluginUtils.html">MASPluginUtils</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Tue Feb 18 2020 21:13:36 GMT+0530 (India Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>