Skip to content

Commit

Permalink
Added token.getWithRedirect and token.parseFromUrl
Browse files Browse the repository at this point in the history
Resolves: OKTA-94711
  • Loading branch information
lboyette-okta committed Jul 21, 2016
1 parent 928a55e commit 3ae8341
Show file tree
Hide file tree
Showing 9 changed files with 564 additions and 174 deletions.
12 changes: 12 additions & 0 deletions lib/clientBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,20 @@ function OktaAuthBuilder(args) {
sdk.token = {
getWithoutPrompt: util.bind(token.getWithoutPrompt, sdk, sdk),
getWithPopup: util.bind(token.getWithPopup, sdk, sdk),
getWithRedirect: util.bind(token.getWithRedirect, sdk, sdk),
parseFromUrl: util.bind(token.parseFromUrl, sdk, sdk),
decode: util.bind(token.decodeToken, sdk)
};

// This is exposed so we can set window.location in our tests
sdk.token.getWithRedirect._setLocation = function(url) {
window.location = url;
};

// This is exposed so we can mock window.location.hash in our tests
sdk.token.parseFromUrl._getLocationHash = function(url) {
return window.location.hash;
};
}

var proto = OktaAuthBuilder.prototype;
Expand Down
14 changes: 12 additions & 2 deletions lib/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,31 @@ function setCookie(name, value, expiresAt) {
}

var cookieText = name + '=' + value + ';' + expiresText;
document.cookie = cookieText;
setCookie._setDocumentCookie(cookieText);

return cookieText;
}

// Exposed for testing
setCookie._setDocumentCookie = function(cookieText) {
document.cookie = cookieText;
};

function getCookie(name) {
var pattern = new RegExp(name + '=([^;]*)'),
matched = document.cookie.match(pattern);
matched = getCookie._getDocumentCookie().match(pattern);

if (matched) {
var cookie = matched[1];
return cookie;
}
}

// Exposed for testing
getCookie._getDocumentCookie = function() {
return document.cookie;
};

function deleteCookie(name) {
setCookie(name, '', '1970-01-01T00:00:00Z');
}
Expand Down
Loading

0 comments on commit 3ae8341

Please sign in to comment.