Posted on 16/05/2017 08:40:04
Hi Per,
on the frontend side it is possible to use the javascript to read the cookie values and then make a request to the external provider login page:
http://head.local.dynamicweb.dk/Admin/Public/Social/ExternalLogin.aspx?action=login&providerID=[Your AD Provider ID]
That page will look for Request(Username) and Request(Password) and try to authenticate the user from AD provider.
I've written some code to read the cookie values and make the request, but the open question which remains is the password Decryption, as it is stored in the cookies in the Encrypted way.
Maybe it is possible to use the Dynamicweb API "Dynamicweb.SystemTools.Crypto.Decrypt" to decrypt that, but I don't know how to call the server method from frontend html template.
<!--@If(Global:Extranet.UserID==0)-->
<script type="text/javascript">
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
function getCookieValue(cookieName, keyName) {
var cookie = getCookie(cookieName);
if (cookie != null) {
var c = cookie.split("&");
for (i = 0; i < c.length; i++) {
var part = c[i].split('=');
if (part[0] == keyName) {
return part[1];
}
}
}
return null;
}
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
if (xmlhttp.status == 200) {
//handle the page response check if login was OK/Failed
}
}
};
xmlhttp.open("GET", "http://head.local.dynamicweb.dk/Admin/Public/Social/ExternalLogin.aspx?action=login&providerID=7&Username=" + getCookieValue("DW_Extranet", "DWExtranetUsername") + "&Password=" + getCookieValue("DW_Extranet", "DWExtranetPassword"), true);
xmlhttp.send();
</script>
<!--@EndIf-->
Regards, Dmitrij