Skip to main content

JQuery JDK

Below is an example usage of the Smartbridge JQuery plugin for use as part of your registration/association/login process.

Import the plugin into your html:

<script src="js/jquery.smartbridge.js" type = "text/javascript"></script>

Assume you have defined the following button in html:

<button id="log-in" style="...">
Log In
</button>

Some values are necessary to connect back to the Smartbridge CAC Interceptor which will be provided by our team, this value in the following snippet would be the cacLoginUrl.

Another value required is the loginCallbackUrl which points to where in your API the login results will be POSTed to.

In your javascript, use the smartbridge plugin and handle the returning promise as you’d like:


$("#log-in").on("click", function () {
console.log("FOTAR LOGIN request to Smartbridge to handle the CAC.");
validateCac(cacLoginUrl,loginCallbackUrl);
});

function validateCac(url, callbackUrl){
//Usage of the smartbridge plugin
$.smartbridge(url,callbackUrl)
.done(function (data, textStatus, jqXHR) { //handle the returning promise
if(data.success == 'true'){
console.log("Smartbridge accepted the cert and returned the following data:\n"+data.token);
//optional:
//location.href = userUrl+'?jwt='+data.jwt;
}else if(data.success == 'false') {
console.log("error transactionId = "+data.jwt);
console.log("Error Message: "+data.error);
alert(data.error);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log("failed to get a successful response back from smartbridge");
// Determine type of error from status code.
if (jqXHR.status === 0){
alert(`Invalid CAC or no CAC chosen. If you were not prompted to enter a certificate, the browser may have cached an invalid cac and you may need to restart your browser.`)
} else if (jqXHR.status >= 400 && jqXHR.status < 500){
alert(`Client Error: ${jqXHR.status} ${jqXHR.statusText}`)
} else if (jqXHR.status >= 500 && jqXHR.status < 600){
alert(`Smartbridge Server Error: ${jqXHR.status} ${jqXHR.statusText}`)
} else {
alert(`Error: ${jqXHR.status} ${jqXHR.statusText}`)
}
});
}

Example successful data return:

{"success":"true","jwt":"c159dabf-5279-4352-ae00-b599a78913cd"}

Example error response:

{"success":"false","error":"Callback is unauthorized"}

or:

{"success":"false","error":"This certificate has a revoked status."}