Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions portals/TokenEndpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
var callback = null;

//Force Login for Anonymous users. Below line can be commented if force login is not needed.
$.cookie("ImplicitGrantForceLogin", 1);
document.cookie = "ImplicitGrantForceLogin=1";

let clientId = "6d08757f-4f46-e911"; //Add the Client ID registered on CRM.

Expand All @@ -39,7 +39,7 @@
function handleGetAuthenticationTokenSuccess(data, status, jqXHR) {
var jsonResult = JSON.parse(jqXHR.getResponseHeader('X-Responded-JSON'));
if (jsonResult && jsonResult.status == 401) {
var forceLogin = Number($.cookie("ImplicitGrantForceLogin")) === 1;
var forceLogin = Number(getCookie("ImplicitGrantForceLogin")) === 1;
if (forceLogin) {
// If the user is not logged in, redirect to login page
redirectToLogin();
Expand All @@ -57,6 +57,22 @@
var loginUrl = window.location.origin + '/SignIn?returnUrl=' + encodeURIComponent(redirectUrl);
window.location = loginUrl;
}

function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

}(window.auth || (window.auth = {}), window.jQuery));

Expand Down Expand Up @@ -84,4 +100,4 @@ var callbackFn = function(data, err) {
}

// Fetch Token Call
window.auth.getAuthenticationToken(callbackFn);
window.auth.getAuthenticationToken(callbackFn);