Skip to content

Commit

Permalink
Deprecated idToken methods (#42)
Browse files Browse the repository at this point in the history
Resolves: OKTA-94713
  • Loading branch information
lboyette-okta authored Sep 30, 2016
1 parent 28a1700 commit b21b9b7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
40 changes: 21 additions & 19 deletions lib/clientBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ function OktaAuthBuilder(args) {
}

sdk.session = {
close: util.bind(session.closeSession, sdk, sdk),
exists: util.bind(session.sessionExists, sdk, sdk),
get: util.bind(session.getSession, sdk, sdk),
refresh: util.bind(session.refreshSession, sdk, sdk),
setCookieAndRedirect: util.bind(session.setCookieAndRedirect, sdk, sdk)
close: util.bind(session.closeSession, null, sdk),
exists: util.bind(session.sessionExists, null, sdk),
get: util.bind(session.getSession, null, sdk),
refresh: util.bind(session.refreshSession, null, sdk),
setCookieAndRedirect: util.bind(session.setCookieAndRedirect, null, sdk)
};

sdk.tx = {
status: util.bind(tx.transactionStatus, sdk, sdk),
resume: util.bind(tx.resumeTransaction, sdk, sdk),
exists: util.bind(tx.transactionExists, sdk, sdk)
status: util.bind(tx.transactionStatus, null, sdk),
resume: util.bind(tx.resumeTransaction, null, sdk),
exists: util.bind(tx.transactionExists, null, sdk)
};

// This is exposed so we can mock document.cookie in our tests
Expand All @@ -81,10 +81,12 @@ function OktaAuthBuilder(args) {
};

sdk.idToken = {
authorize: util.bind(token.getToken, 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
authorize: util.deprecateWrap('Use token.getWithoutPrompt, token.getWithPopup, or token.getWithRedirect ' +
'instead of idToken.authorize.', util.bind(token.getToken, null, sdk)),
verify: util.bind(token.verifyIdToken, null, sdk),
refresh: util.deprecateWrap('Use token.refresh instead of idToken.refresh',
util.bind(token.refreshIdToken, null, sdk)),
decode: util.deprecateWrap('Use token.decode instead of idToken.decode', token.decodeToken)
};

// This is exposed so we can mock window.location.href in our tests
Expand All @@ -93,13 +95,13 @@ 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),
refresh: util.bind(token.refreshToken, sdk, sdk),
getUserInfo: util.bind(token.getUserInfo, sdk, sdk)
getWithoutPrompt: util.bind(token.getWithoutPrompt, null, sdk),
getWithPopup: util.bind(token.getWithPopup, null, sdk),
getWithRedirect: util.bind(token.getWithRedirect, null, sdk),
parseFromUrl: util.bind(token.parseFromUrl, null, sdk),
decode: token.decodeToken,
refresh: util.bind(token.refreshToken, null, sdk),
getUserInfo: util.bind(token.getUserInfo, null, sdk)
};

// This is exposed so we can set window.location in our tests
Expand Down
4 changes: 2 additions & 2 deletions lib/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function verifyIdToken(sdk, idToken, options) {
if (!res) {
return false;
}
var jwt = sdk.idToken.decode(idToken);
var jwt = sdk.token.decode(idToken);

if (isExpired(jwt.payload.exp)) {
return false;
Expand Down Expand Up @@ -257,7 +257,7 @@ function handleOAuthResponse(sdk, oauthParams, res) {
var tokenDict = {};

if (res['id_token']) {
var jwt = sdk.idToken.decode(res['id_token']);
var jwt = sdk.token.decode(res['id_token']);
if (jwt.payload.nonce !== oauthParams.nonce) {
throw new AuthSdkError('OAuth flow response nonce doesn\'t match request nonce');
}
Expand Down
10 changes: 9 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ function deprecate(text) {
/* eslint-enable */
}

function deprecateWrap(text, fn) {
return function() {
deprecate(text);
return fn.apply(null, arguments);
};
}

module.exports = {
base64UrlToBase64: base64UrlToBase64,
base64UrlToString: base64UrlToString,
Expand All @@ -219,5 +226,6 @@ module.exports = {
omit: omit,
find: find,
getLink: getLink,
deprecate: deprecate
deprecate: deprecate,
deprecateWrap: deprecateWrap
};

0 comments on commit b21b9b7

Please sign in to comment.