Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added token.getWithPopup, token.getWithRedirect, and token.parseFromUrl #30

Merged
merged 6 commits into from
Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 14 additions & 1 deletion lib/clientBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function OktaAuthBuilder(args) {
};

sdk.idToken = {
authorize: util.bind(token.getIdToken, sdk, sdk), // deprecated for sessionToken
authorize: util.bind(token.getIdToken, sdk, sdk), // deprecated for sessionToken and idp flows
verify: util.bind(token.verifyIdToken, sdk, sdk),
refresh: util.bind(token.refreshIdToken, sdk, sdk),
decode: util.bind(token.decodeToken, sdk) // deprecated
Expand All @@ -79,8 +79,21 @@ 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) {
Copy link
Contributor

@rchild-okta rchild-okta Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to create some util helper functions "util.redirect" and "util.getLocation" - in that case, we wouldn't be able to easily test those methods, but it would be easy to test everything that depends on them, i.e. would be able to mock without having to expose private methods.

Edit: On further thought, maybe not since you want to be able to test it from the sdk level. Will need to think about this some more.

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