authentication-adal-pkg
Advanced tools
Comparing version 1.0.8 to 1.0.9
348
lib/index.js
@@ -1,1 +0,347 @@ | ||
"use strict";function _defineProperty(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}var _slicedToArray=function(){function e(e,n){var t=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(t.push(u.value),!n||t.length!==n);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&a.return&&a.return()}finally{if(o)throw i}}return t}return function(n,t){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return e(n,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();window.AuthenticationContext=require("adal-angular");var jwtDecode=require("jwt-decode"),eandisAuthenticator=function(e){var n={MOBILE:"mobile",BROWSER:"browser",STATE:"state",NONCE:"nonce",TOKEN:"token",TOKEN_EXPIRATION:"token.expiration",IN_PROGRESS:"progess"},t=null,r=null,o=null,i=null,u=null,a=null,c=null,l=null,s=null,f=null,d=null,h=null,O=null,m="",g={},v=function(e){t=e.authority,r=e.tenant,o=e.redirectUriWeb,i=e.redirectUriIOS,u=e.redirectUriAndroid,a=e.redirectUriWindows,c=e.resourceUri,s=e.clientId,f=e.userId,l=e.loginResource},w=function(e){if(e===n.BROWSER){var i={tenant:r,clientId:s,redirectUri:o,loginResource:l};d=new AuthenticationContext(i)}else h=new Microsoft.ADAL.AuthenticationContext(t)},E={prefix:"auth",set:function(e,n){localStorage.setItem(this.prefix+"-"+e,n)},get:function(e){return localStorage.getItem(this.prefix+"-"+e)},remove:function(e){localStorage.removeItem(this.prefix+"-"+e)}};E.set(n.IN_PROGRESS,!1);var R=function(){return window.cordova&&window.cordova.platformId||"browser"},I=function(){return new Promise(function(e,n){C(e,n)})},p=function(){return new Promise(function(e,t){try{h||w(n.MOBILE),h.tokenCache.clear(),e()}catch(e){t(e)}})},y=function(){return new Promise(function(e,t){try{d||w(n.BROWSER),d.logOut(),E.remove(n.TOKEN),e()}catch(e){t(e)}})},T=function(){return R()===n.BROWSER?y():p()},S=function(e,t,r){return new Promise(function(e,o){var i=function(n,t,r){r?o(r):e(t)};r?(d||w(n.BROWSER),d.acquireTokenPopup(s,null,null,i)):e(t)})},N=function(e,t,r){var o=E.get(n.TOKEN);if(o)e(o);else{d||w(n.BROWSER),d.handleWindowCallback();var i=function(n,r,o){S(n,r,o).then(e).catch(function(e){if("login required"===e)new Promise(function(e,n){C(e,n)});else t(e)})};d.acquireToken(s,i)}},k=function(e,t){h||w(n.MOBILE),h.tokenCache.readItems().then(function(n){var r=n.length-1,o=n[r]&&n[r].accessToken;o?e(o):t(new Error("No token found"))})},A=function(e){return new Promise(function(t,r){try{R()===n.BROWSER?N(t,r,e):k(t,r)}catch(e){r(e)}})},b=function(e){switch(e.toLowerCase()){case"android":O=u;break;case"ios":O=i;break;case"windows":O=a}},P=function(){return"true"===E.get(n.IN_PROGRESS)},_=function(){var e=E.get(n.TOKEN),t=E.get(n.TOKEN_EXPIRATION);return t&&parseInt(t,10)>Date.now()/1e3?{response:e,error:null}:m?{response:null,error:m}:{response:null,error:null}},x=function(e,r){Microsoft.ADAL.AuthenticationSettings.setUseBroker(!0).then(function(){w(n.MOBILE),b(R()),h.tokenCache.readItems().then(function(o){o.length>0&&(t=o[0].authority,w(n.MOBILE)),h.acquireTokenSilentAsync(c,s,f).then(e,function(){h.acquireTokenAsync(c,s,O).then(e,r)})})})},B=function(e,t){w(n.BROWSER);var r=_().response;r||P()||m?(d.saveTokenFromHash(d.getRequestInfo(window.location.hash)),e({token:r,error:null})):(E.set(n.IN_PROGRESS,!1),d.login(),e({token:null,error:null}))},C=function(e,t){try{R()===n.BROWSER?B(e,t):x(e,t)}catch(e){t(e)}},K=function(e){try{return jwtDecode(e)}catch(e){return console.error("unable to decode token",e),{}}},W=function e(){return Object.keys(g).length?Promise.resolve(g):A(e).then(function(e){var n=K(e),t=n.family_name,r=n.given_name,o=n.name,i=n.upn;return i||(i=K(e).email),g=j(t,r,o,i)})},U=function(e){var t=E.get(n.TOKEN_EXPIRATION);return t&&parseInt(t,10)>Date.now()/1e3},q=function(){var e=E.get(n.TOKEN);return U(e)?e:(E.remove(n.TOKEN),null)},L=function(){var e=E.get(n.TOKEN);if(U(e)){var t=K(e),r=t.family_name,o=t.given_name,i=t.name,u=t.upn;return u||(u=K(e).email),g=j(r,o,i,u)}},j=function(e,n,t,r){return{familyName:e,givenName:n,name:t,upn:r}},M=function(e){function n(e){var n,t=/\+/g,r=/([^&=]+)=?([^&]*)/g,o=function(e){return decodeURIComponent(e.replace(t," "))},i={};for(n=r.exec(e);n;)i[o(n[1])]=o(n[2]),n=r.exec(e);return i}function t(e){var t="";return e.indexOf("#/")>-1?t=e.substring(e.indexOf("#/")+2):e.indexOf("#")>-1&&(t=e.substring(1)),t&&n(t)||null}function r(e){return e.substr(1).split("&").reduce(function(e,n){var t=n.split("="),r=_slicedToArray(t,2),o=r[0],i=r[1];return e.hasOwnProperty(o)?e:Object.assign({},e,_defineProperty({},o,decodeURIComponent(i)))},{})}return t(e||window.location.hash)||r(window.location.search)};return function(){var e=M(),t=function(n){return e[n]},r=t("id_token"),o=(t("state"),!0);if(r){var i=K(r),u=(i.nonce,i.aud,i.exp);i.family_name,i.given_name,i.name,i.upn;o&&(E.set(n.IN_PROGRESS,!1),E.set(n.TOKEN,r),E.set(n.TOKEN_EXPIRATION,u))}}(),{signIn:I,signOut:T,acquireToken:A,initialize:v,getUser:W,getUserFromCache:L,getTokenFromCache:q}}();module.exports={authentication:eandisAuthenticator}; | ||
'use strict'; | ||
function _defineProperty(e, n, t) { | ||
return ( | ||
n in e | ||
? Object.defineProperty(e, n, { | ||
value: t, | ||
enumerable: !0, | ||
configurable: !0, | ||
writable: !0 | ||
}) | ||
: (e[n] = t), | ||
e | ||
); | ||
} | ||
var _slicedToArray = (function() { | ||
function e(e, n) { | ||
var t = [], | ||
r = !0, | ||
o = !1, | ||
i = void 0; | ||
try { | ||
for ( | ||
var u, a = e[Symbol.iterator](); | ||
!(r = (u = a.next()).done) && (t.push(u.value), !n || t.length !== n); | ||
r = !0 | ||
); | ||
} catch (e) { | ||
(o = !0), (i = e); | ||
} finally { | ||
try { | ||
!r && a.return && a.return(); | ||
} finally { | ||
if (o) throw i; | ||
} | ||
} | ||
return t; | ||
} | ||
return function(n, t) { | ||
if (Array.isArray(n)) return n; | ||
if (Symbol.iterator in Object(n)) return e(n, t); | ||
throw new TypeError('Invalid attempt to destructure non-iterable instance'); | ||
}; | ||
})(); | ||
window.AuthenticationContext = require('adal-angular'); | ||
var jwtDecode = require('jwt-decode'), | ||
eandisAuthenticator = (function(e) { | ||
var n = { | ||
MOBILE: 'mobile', | ||
BROWSER: 'browser', | ||
STATE: 'state', | ||
NONCE: 'nonce', | ||
TOKEN: 'token', | ||
TOKEN_EXPIRATION: 'token.expiration', | ||
IN_PROGRESS: 'progess' | ||
}, | ||
t = null, | ||
r = null, | ||
o = null, | ||
i = null, | ||
u = null, | ||
a = null, | ||
c = null, | ||
l = null, | ||
s = null, | ||
f = null, | ||
d = null, | ||
h = null, | ||
O = null, | ||
m = '', | ||
g = {}, | ||
E = function(e) { | ||
(t = e.authority), | ||
(r = e.tenant), | ||
(o = e.redirectUriWeb), | ||
(i = e.redirectUriIOS), | ||
(u = e.redirectUriAndroid), | ||
(a = e.redirectUriWindows), | ||
(c = e.resourceUri), | ||
(s = e.clientId), | ||
(f = e.userId), | ||
(l = e.loginResource); | ||
}, | ||
v = function(e) { | ||
if (e === n.BROWSER) { | ||
var i = { tenant: r, clientId: s, redirectUri: o, loginResource: l }; | ||
d = new AuthenticationContext(i); | ||
} else h = new Microsoft.ADAL.AuthenticationContext(t); | ||
}, | ||
w = { | ||
prefix: 'auth', | ||
set: function(e, n) { | ||
localStorage.setItem(this.prefix + '-' + e, n); | ||
}, | ||
get: function(e) { | ||
return localStorage.getItem(this.prefix + '-' + e); | ||
}, | ||
remove: function(e) { | ||
localStorage.removeItem(this.prefix + '-' + e); | ||
} | ||
}; | ||
w.set(n.IN_PROGRESS, !1); | ||
var R = function() { | ||
return (window.cordova && window.cordova.platformId) || 'browser'; | ||
}, | ||
I = function() { | ||
return new Promise(function(e, n) { | ||
C(e, n); | ||
}); | ||
}, | ||
p = function() { | ||
return new Promise(function(e, t) { | ||
try { | ||
h || v(n.MOBILE), h.tokenCache.clear(), e(); | ||
} catch (e) { | ||
t(e); | ||
} | ||
}); | ||
}, | ||
T = function() { | ||
return new Promise(function(e, t) { | ||
try { | ||
d || v(n.BROWSER), d.logOut(), w.remove(n.TOKEN), e(); | ||
} catch (e) { | ||
t(e); | ||
} | ||
}); | ||
}, | ||
y = function() { | ||
return R() === n.BROWSER ? T() : p(); | ||
}, | ||
S = function(e, t, r) { | ||
return new Promise(function(e, o) { | ||
var i = function(n, t, r) { | ||
r ? o(r) : e(t); | ||
}; | ||
r ? (d || v(n.BROWSER), d.acquireTokenPopup(s, null, null, i)) : e(t); | ||
}); | ||
}, | ||
N = function(e, t, r) { | ||
var o = w.get(n.TOKEN); | ||
if (o) e(o); | ||
else { | ||
d || v(n.BROWSER), d.handleWindowCallback(); | ||
var i = function(n, r, o) { | ||
S(n, r, o) | ||
.then(e) | ||
.catch(function(e) { | ||
if ('login required' === e) | ||
new Promise(function(e, n) { | ||
C(e, n); | ||
}); | ||
else t(e); | ||
}); | ||
}; | ||
d.acquireToken(s, i); | ||
} | ||
}, | ||
k = function(e, t) { | ||
h || v(n.MOBILE), | ||
h.tokenCache.readItems().then(function(n) { | ||
var r = n.length - 1, | ||
o = n[r] && n[r].accessToken; | ||
o ? e(o) : t(new Error('No token found')); | ||
}); | ||
}, | ||
A = function(e) { | ||
return new Promise(function(t, r) { | ||
try { | ||
R() === n.BROWSER ? N(t, r, e) : k(t, r); | ||
} catch (e) { | ||
r(e); | ||
} | ||
}); | ||
}, | ||
P = function(e) { | ||
switch (e.toLowerCase()) { | ||
case 'android': | ||
O = u; | ||
break; | ||
case 'ios': | ||
O = i; | ||
break; | ||
case 'windows': | ||
O = a; | ||
} | ||
}, | ||
b = function() { | ||
return 'true' === w.get(n.IN_PROGRESS); | ||
}, | ||
_ = function() { | ||
var e = w.get(n.TOKEN), | ||
t = w.get(n.TOKEN_EXPIRATION); | ||
return t && parseInt(t, 10) > Date.now() / 1e3 | ||
? { response: e, error: null } | ||
: m ? { response: null, error: m } : { response: null, error: null }; | ||
}, | ||
x = function(e, r) { | ||
Microsoft.ADAL.AuthenticationSettings.setUseBroker(!0).then(function() { | ||
v(n.MOBILE), | ||
P(R()), | ||
h.tokenCache.readItems().then(function(o) { | ||
if (o.length > 0) { | ||
var i = o.length - 1; | ||
(t = o[i].authority), v(n.MOBILE); | ||
} | ||
h.acquireTokenSilentAsync(c, s, f).then(e, function() { | ||
h.acquireTokenAsync(c, s, O).then(function(t) { | ||
var r = t.idToken, | ||
o = K(r).exp; | ||
w.set(n.IN_PROGRESS, !1), | ||
w.set(n.TOKEN, r), | ||
w.set(n.TOKEN_EXPIRATION, o), | ||
e(t); | ||
}, r); | ||
}); | ||
}); | ||
}); | ||
}, | ||
B = function(e, t) { | ||
v(n.BROWSER); | ||
var r = _().response; | ||
r || b() || m | ||
? (d.saveTokenFromHash(d.getRequestInfo(window.location.hash)), | ||
e({ token: r, error: null })) | ||
: (w.set(n.IN_PROGRESS, !1), | ||
d.login(), | ||
e({ token: null, error: null })); | ||
}, | ||
C = function(e, t) { | ||
try { | ||
R() === n.BROWSER ? B(e, t) : x(e, t); | ||
} catch (e) { | ||
t(e); | ||
} | ||
}, | ||
K = function(e) { | ||
try { | ||
return jwtDecode(e); | ||
} catch (e) { | ||
return console.error('unable to decode token', e), {}; | ||
} | ||
}, | ||
W = function e() { | ||
return Object.keys(g).length | ||
? Promise.resolve(g) | ||
: A(e).then(function(e) { | ||
var n = K(e), | ||
t = n.family_name, | ||
r = n.given_name, | ||
o = n.name, | ||
i = n.upn; | ||
return i || (i = K(e).email), (g = j(t, r, o, i)); | ||
}); | ||
}, | ||
U = function(e) { | ||
var t = w.get(n.TOKEN_EXPIRATION); | ||
return t && parseInt(t, 10) > Date.now() / 1e3; | ||
}, | ||
q = function() { | ||
var e = w.get(n.TOKEN); | ||
return U(e) ? e : (w.remove(n.TOKEN), null); | ||
}, | ||
L = function() { | ||
var e = w.get(n.TOKEN); | ||
if (U(e)) { | ||
var t = K(e), | ||
r = t.family_name, | ||
o = t.given_name, | ||
i = t.name, | ||
u = t.upn; | ||
return u || (u = K(e).email), (g = j(r, o, i, u)); | ||
} | ||
}, | ||
j = function(e, n, t, r) { | ||
return { familyName: e, givenName: n, name: t, upn: r }; | ||
}, | ||
M = function(e) { | ||
function n(e) { | ||
var n, | ||
t = /\+/g, | ||
r = /([^&=]+)=?([^&]*)/g, | ||
o = function(e) { | ||
return decodeURIComponent(e.replace(t, ' ')); | ||
}, | ||
i = {}; | ||
for (n = r.exec(e); n; ) (i[o(n[1])] = o(n[2])), (n = r.exec(e)); | ||
return i; | ||
} | ||
function t(e) { | ||
var t = ''; | ||
return ( | ||
e.indexOf('#/') > -1 | ||
? (t = e.substring(e.indexOf('#/') + 2)) | ||
: e.indexOf('#') > -1 && (t = e.substring(1)), | ||
(t && n(t)) || null | ||
); | ||
} | ||
function r(e) { | ||
return e | ||
.substr(1) | ||
.split('&') | ||
.reduce(function(e, n) { | ||
var t = n.split('='), | ||
r = _slicedToArray(t, 2), | ||
o = r[0], | ||
i = r[1]; | ||
return e.hasOwnProperty(o) | ||
? e | ||
: Object.assign( | ||
{}, | ||
e, | ||
_defineProperty({}, o, decodeURIComponent(i)) | ||
); | ||
}, {}); | ||
} | ||
return t(e || window.location.hash) || r(window.location.search); | ||
}; | ||
return ( | ||
(function() { | ||
var e = M(), | ||
t = function(n) { | ||
return e[n]; | ||
}, | ||
r = t('id_token'), | ||
o = (t('state'), !0); | ||
if (r) { | ||
var i = K(r), | ||
u = (i.nonce, i.aud, i.exp); | ||
i.family_name, i.given_name, i.name, i.upn; | ||
o && | ||
(w.set(n.IN_PROGRESS, !1), | ||
w.set(n.TOKEN, r), | ||
w.set(n.TOKEN_EXPIRATION, u)); | ||
} | ||
})(), | ||
{ | ||
signIn: I, | ||
signOut: y, | ||
acquireToken: A, | ||
initialize: E, | ||
getUser: W, | ||
getUserFromCache: L, | ||
getTokenFromCache: q | ||
} | ||
); | ||
})(); | ||
module.exports = { authentication: eandisAuthenticator }; |
'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _slicedToArray = (function() { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for ( | ||
var _i = arr[Symbol.iterator](), _s; | ||
!(_n = (_s = _i.next()).done); | ||
_n = true | ||
) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i['return']) _i['return'](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function(arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError( | ||
'Invalid attempt to destructure non-iterable instance' | ||
); | ||
} | ||
}; | ||
})(); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
@@ -10,3 +60,3 @@ window.AuthenticationContext = require('adal-angular'); | ||
var eandisAuthenticator = function auth(config) { | ||
var eandisAuthenticator = (function auth(config) { | ||
var constants = { | ||
@@ -81,7 +131,7 @@ MOBILE: 'mobile', | ||
var getPlatform = function getPlatform() { | ||
return window.cordova && window.cordova.platformId || 'browser'; | ||
return (window.cordova && window.cordova.platformId) || 'browser'; | ||
}; | ||
var signIn = function signIn() { | ||
return new Promise(function (resolve, reject) { | ||
return new Promise(function(resolve, reject) { | ||
authenticate(resolve, reject); | ||
@@ -92,3 +142,3 @@ }); | ||
var signOutMobile = function signOutMobile() { | ||
return new Promise(function (resolve, reject) { | ||
return new Promise(function(resolve, reject) { | ||
try { | ||
@@ -108,3 +158,3 @@ if (!authContext) { | ||
var signOutBrowser = function signOutBrowser() { | ||
return new Promise(function (resolve, reject) { | ||
return new Promise(function(resolve, reject) { | ||
try { | ||
@@ -132,5 +182,10 @@ if (!auth) { | ||
var onAcquireToken = function onAcquireToken(errorDesc, token, error) { | ||
return new Promise(function (resolve, reject) { | ||
var acquireTokenCallback = function acquireTokenCallback(desc, token, err) { | ||
if (err) reject(err);else resolve(token); | ||
return new Promise(function(resolve, reject) { | ||
var acquireTokenCallback = function acquireTokenCallback( | ||
desc, | ||
token, | ||
err | ||
) { | ||
if (err) reject(err); | ||
else resolve(token); | ||
}; | ||
@@ -156,12 +211,18 @@ if (error) { | ||
auth.handleWindowCallback(); | ||
var acquireTokenCallback = function acquireTokenCallback(errorDesc, token, error) { | ||
onAcquireToken(errorDesc, token, error).then(resolve).catch(function (e) { | ||
if (e === 'login required') { | ||
var authPromise = new Promise(function (resolve, reject) { | ||
authenticate(resolve, reject); | ||
}); | ||
} else { | ||
reject(e); | ||
} | ||
}); | ||
var acquireTokenCallback = function acquireTokenCallback( | ||
errorDesc, | ||
token, | ||
error | ||
) { | ||
onAcquireToken(errorDesc, token, error) | ||
.then(resolve) | ||
.catch(function(e) { | ||
if (e === 'login required') { | ||
var authPromise = new Promise(function(resolve, reject) { | ||
authenticate(resolve, reject); | ||
}); | ||
} else { | ||
reject(e); | ||
} | ||
}); | ||
}; | ||
@@ -178,3 +239,3 @@ auth.acquireToken(clientId, acquireTokenCallback); | ||
} | ||
authContext.tokenCache.readItems().then(function (items) { | ||
authContext.tokenCache.readItems().then(function(items) { | ||
var index = items.length - 1; | ||
@@ -191,3 +252,3 @@ var token = items[index] && items[index].accessToken; | ||
var acquireToken = function acquireToken(cb) { | ||
return new Promise(function (resolve, reject) { | ||
return new Promise(function(resolve, reject) { | ||
try { | ||
@@ -237,3 +298,3 @@ if (getPlatform() === constants.BROWSER) { | ||
// Check if MS ADAL cordova library is installed | ||
Microsoft.ADAL.AuthenticationSettings.setUseBroker(true).then(function () { | ||
Microsoft.ADAL.AuthenticationSettings.setUseBroker(true).then(function() { | ||
initAuthenticationContext(constants.MOBILE); | ||
@@ -243,12 +304,25 @@ setPlatformRedirectUri(getPlatform()); | ||
// This prevents an additional prompt | ||
authContext.tokenCache.readItems().then(function (items) { | ||
authContext.tokenCache.readItems().then(function(items) { | ||
if (items.length > 0) { | ||
authority = items[0].authority; | ||
var index = items.length - 1; | ||
authority = items[index].authority; | ||
initAuthenticationContext(constants.MOBILE); | ||
} | ||
// Attempt to authorize user silently | ||
authContext.acquireTokenSilentAsync(resourceUri, clientId, userId).then(resolve, function () { | ||
// We require user credentials so triggers authentication dialog | ||
authContext.acquireTokenAsync(resourceUri, clientId, platformRedirectUri).then(resolve, reject); | ||
}); | ||
authContext | ||
.acquireTokenSilentAsync(resourceUri, clientId, userId) | ||
.then(resolve, function() { | ||
// We require user credentials so triggers authentication dialog | ||
authContext | ||
.acquireTokenAsync(resourceUri, clientId, platformRedirectUri) | ||
.then(function(authResult) { | ||
var idToken = authResult.idToken; | ||
var _decodeTokenPayload3 = decodeTokenPayload(idToken); | ||
var exp = _decodeTokenPayload3.exp; | ||
storage.set(constants.IN_PROGRESS, false); | ||
storage.set(constants.TOKEN, idToken); | ||
storage.set(constants.TOKEN_EXPIRATION, exp); | ||
resolve(authResult); | ||
}, reject); | ||
}); | ||
}); | ||
@@ -261,3 +335,3 @@ }); | ||
var _getCachedToken = getCachedToken(), | ||
token = _getCachedToken.response; | ||
token = _getCachedToken.response; | ||
@@ -297,8 +371,8 @@ if (!token && !isInProgress() && !localError) { | ||
if (!Object.keys(user).length) { | ||
return acquireToken(getUser).then(function (token) { | ||
return acquireToken(getUser).then(function(token) { | ||
var _decodeTokenPayload = decodeTokenPayload(token), | ||
family_name = _decodeTokenPayload.family_name, | ||
given_name = _decodeTokenPayload.given_name, | ||
name = _decodeTokenPayload.name, | ||
upn = _decodeTokenPayload.upn; | ||
family_name = _decodeTokenPayload.family_name, | ||
given_name = _decodeTokenPayload.given_name, | ||
name = _decodeTokenPayload.name, | ||
upn = _decodeTokenPayload.upn; | ||
@@ -314,10 +388,10 @@ if (!upn) { | ||
}; | ||
var isValidToken = function(token){ | ||
var isValidToken = function(token) { | ||
var expiration = storage.get(constants.TOKEN_EXPIRATION); | ||
return expiration && (parseInt(expiration, 10) > (Date.now() / 1000)); | ||
} | ||
return expiration && parseInt(expiration, 10) > Date.now() / 1000; | ||
}; | ||
var getTokenFromCache = function getTokenFromCache() { | ||
var token = storage.get(constants.TOKEN); | ||
if(!isValidToken(token)){ | ||
if (!isValidToken(token)) { | ||
storage.remove(constants.TOKEN); | ||
@@ -333,6 +407,6 @@ return null; | ||
var _decodeTokenPayload2 = decodeTokenPayload(token), | ||
family_name = _decodeTokenPayload2.family_name, | ||
given_name = _decodeTokenPayload2.given_name, | ||
name = _decodeTokenPayload2.name, | ||
upn = _decodeTokenPayload2.upn; | ||
family_name = _decodeTokenPayload2.family_name, | ||
given_name = _decodeTokenPayload2.given_name, | ||
name = _decodeTokenPayload2.name, | ||
upn = _decodeTokenPayload2.upn; | ||
@@ -348,3 +422,8 @@ if (!upn) { | ||
var createUser = function createUser(familyName, givenName, name, upn) { | ||
return { familyName: familyName, givenName: givenName, name: name, upn: upn }; | ||
return { | ||
familyName: familyName, | ||
givenName: givenName, | ||
name: name, | ||
upn: upn | ||
}; | ||
}; | ||
@@ -376,8 +455,11 @@ | ||
} | ||
return hashString && deserializeHash(hashString) || null; | ||
return (hashString && deserializeHash(hashString)) || null; | ||
} | ||
function getQueryParams(url) { | ||
return url.substr(1).split('&').reduce(function (params, item) { | ||
var _item$split = item.split('='), | ||
return url | ||
.substr(1) | ||
.split('&') | ||
.reduce(function(params, item) { | ||
var _item$split = item.split('='), | ||
_item$split2 = _slicedToArray(_item$split, 2), | ||
@@ -387,11 +469,18 @@ key = _item$split2[0], | ||
if (!params.hasOwnProperty(key)) { | ||
// eslint-disable-line no-prototype-builtins | ||
return Object.assign({}, params, _defineProperty({}, key, decodeURIComponent(value))); | ||
} | ||
return params; | ||
}, {}); | ||
if (!params.hasOwnProperty(key)) { | ||
// eslint-disable-line no-prototype-builtins | ||
return Object.assign( | ||
{}, | ||
params, | ||
_defineProperty({}, key, decodeURIComponent(value)) | ||
); | ||
} | ||
return params; | ||
}, {}); | ||
} | ||
return getHash(hash || window.location.hash) || getQueryParams(window.location.search); | ||
return ( | ||
getHash(hash || window.location.hash) || | ||
getQueryParams(window.location.search) | ||
); | ||
}; | ||
@@ -410,9 +499,9 @@ | ||
var _decodeTokenPayload3 = decodeTokenPayload(token), | ||
nonce = _decodeTokenPayload3.nonce, | ||
aud = _decodeTokenPayload3.aud, | ||
exp = _decodeTokenPayload3.exp, | ||
family_name = _decodeTokenPayload3.family_name, | ||
given_name = _decodeTokenPayload3.given_name, | ||
name = _decodeTokenPayload3.name, | ||
upn = _decodeTokenPayload3.upn; | ||
nonce = _decodeTokenPayload3.nonce, | ||
aud = _decodeTokenPayload3.aud, | ||
exp = _decodeTokenPayload3.exp, | ||
family_name = _decodeTokenPayload3.family_name, | ||
given_name = _decodeTokenPayload3.given_name, | ||
name = _decodeTokenPayload3.name, | ||
upn = _decodeTokenPayload3.upn; | ||
@@ -427,4 +516,12 @@ if (validToken) { | ||
handleWindowCallback(); | ||
return { signIn: signIn, signOut: signOut, acquireToken: acquireToken, initialize: initialize, getUser: getUser, getUserFromCache: getUserFromCache, getTokenFromCache: getTokenFromCache }; | ||
}(); | ||
return { | ||
signIn: signIn, | ||
signOut: signOut, | ||
acquireToken: acquireToken, | ||
initialize: initialize, | ||
getUser: getUser, | ||
getUserFromCache: getUserFromCache, | ||
getTokenFromCache: getTokenFromCache | ||
}; | ||
})(); | ||
@@ -431,0 +528,0 @@ module.exports = { |
{ | ||
"name": "authentication-adal-pkg", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "An authentication SDK based on MS ADAL ", | ||
@@ -9,6 +9,3 @@ "main": "lib/index.js", | ||
}, | ||
"keywords": [ | ||
"authentication", | ||
"adal" | ||
], | ||
"keywords": ["authentication", "adal"], | ||
"author": "Donovan De Smedt", | ||
@@ -15,0 +12,0 @@ "license": "ISC", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
59810
1837
2