authentication-adal-pkg
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,1 +0,1 @@ | ||
"use strict";function _defineProperty(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}var _slicedToArray=function(){function n(n,e){var t=[],r=!0,o=!1,i=void 0;try{for(var u,c=n[Symbol.iterator]();!(r=(u=c.next()).done)&&(t.push(u.value),!e||t.length!==e);r=!0);}catch(n){o=!0,i=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw i}}return t}return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return n(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();window.AuthenticationContext=require("adal-angular");var jwtDecode=require("jwt-decode"),eandisAuthenticator=function(n){var e={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,c=null,a=null,l=null,s=null,f=null,d=null,h=null,m=null,O="",g={},w=function(n){t=n.authority,r=n.tenant,o=n.redirectUriWeb,i=n.redirectUriIOS,u=n.redirectUriAndroid,c=n.redirectUriWindows,a=n.resourceUri,s=n.clientId,f=n.userId,l=n.loginResource},v=function(n){if(n===e.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(n,e){localStorage.setItem(this.prefix+"-"+n,e)},get:function(n){return localStorage.getItem(this.prefix+"-"+n)},remove:function(n){localStorage.removeItem(this.prefix+"-"+n)}};E.set(e.IN_PROGRESS,!1);var R=function(){return window.cordova&&window.cordova.platformId||"browser"},p=function(){return new Promise(function(n,e){C(n,e)})},I=function(){return new Promise(function(n,t){try{h||v(e.MOBILE),h.tokenCache.clear(),n()}catch(n){t(n)}})},y=function(){return new Promise(function(n,t){try{d||v(e.BROWSER),d.logOut(),E.remove(e.TOKEN),n()}catch(n){t(n)}})},S=function(){return R()===e.BROWSER?y():I()},T=function(n,t,r){return new Promise(function(n,o){var i=function(e,t,r){r?o(r):n(t)};r?(d||v(e.BROWSER),d.acquireTokenPopup(s,null,null,i)):n(t)})},k=function(n,t,r){var o=E.get(e.TOKEN);if(o)n(o);else{d||v(e.BROWSER),d.handleWindowCallback();var i=function(e,r,o){T(e,r,o).then(n).catch(function(n){if("login required"===n)new Promise(function(n,e){C(n,e)});else t(n)})};d.acquireToken(s,i)}},N=function(n,t){h||v(e.MOBILE),h.tokenCache.readItems().then(function(e){var r=e.length-1,o=e[r]&&e[r].accessToken;o?n(o):t(new Error("No token found"))})},b=function(n){return new Promise(function(t,r){try{R()===e.BROWSER?k(t,r,n):N(t,r)}catch(n){r(n)}})},A=function(n){switch(n.toLowerCase()){case"android":m=u;break;case"ios":m=i;break;case"windows":m=c}},P=function(){return"true"===E.get(e.IN_PROGRESS)},_=function(){var n=E.get(e.TOKEN),t=E.get(e.TOKEN_EXPIRATION);return t&&parseInt(t,10)>Date.now()/1e3?{response:n,error:null}:O?{response:null,error:O}:{response:null,error:null}},x=function(n,r){Microsoft.ADAL.AuthenticationSettings.setUseBroker(!0).then(function(){v(e.MOBILE),A(R()),h.tokenCache.readItems().then(function(o){o.length>0&&(t=o[0].authority,v(e.MOBILE)),h.acquireTokenSilentAsync(a,s,f).then(n,function(){h.acquireTokenAsync(a,s,m).then(n,r)})})})},B=function(n,t){v(e.BROWSER);var r=_().response;r||P()||O?(d.saveTokenFromHash(d.getRequestInfo(window.location.hash)),n({token:r,error:null})):(E.set(e.IN_PROGRESS,!1),d.login(),n({token:null,error:null}))},C=function(n,t){try{R()===e.BROWSER?B(n,t):x(n,t)}catch(n){t(n)}},W=function(n){try{return jwtDecode(n)}catch(n){return console.error("unable to decode token",n),{}}},U=function n(){return Object.keys(g).length?Promise.resolve(g):b(n).then(function(n){var e=W(n),t=e.family_name,r=e.given_name,o=e.name,i=e.upn;return i||(i=W(n).email),g=L(t,r,o,i)})},K=function(){return E.get(e.TOKEN)},q=function(){var n=E.get(e.TOKEN);if(n){var t=W(n),r=t.family_name,o=t.given_name,i=t.name,u=t.upn;return u||(u=W(n).email),g=L(r,o,i,u)}},L=function(n,e,t,r){return{familyName:n,givenName:e,name:t,upn:r}},j=function(n){function e(n){var e,t=/\+/g,r=/([^&=]+)=?([^&]*)/g,o=function(n){return decodeURIComponent(n.replace(t," "))},i={};for(e=r.exec(n);e;)i[o(e[1])]=o(e[2]),e=r.exec(n);return i}function t(n){var t="";return n.indexOf("#/")>-1?t=n.substring(n.indexOf("#/")+2):n.indexOf("#")>-1&&(t=n.substring(1)),t&&e(t)||null}function r(n){return n.substr(1).split("&").reduce(function(n,e){var t=e.split("="),r=_slicedToArray(t,2),o=r[0],i=r[1];return n.hasOwnProperty(o)?n:Object.assign({},n,_defineProperty({},o,decodeURIComponent(i)))},{})}return t(n||window.location.hash)||r(window.location.search)};return function(){var n=j(),t=function(e){return n[e]},r=t("id_token"),o=(t("state"),!0);if(r){var i=W(r),u=(i.nonce,i.aud,i.exp);i.family_name,i.given_name,i.name,i.upn;o&&(E.set(e.IN_PROGRESS,!1),E.set(e.TOKEN,r),E.set(e.TOKEN_EXPIRATION,u))}}(),{signIn:p,signOut:S,acquireToken:b,initialize:w,getUser:U,getUserFromCache:q,getTokenFromCache:K}}();module.exports={authentication:eandisAuthenticator}; | ||
"use strict";function _defineProperty(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}var _slicedToArray=function(){function n(n,e){var t=[],r=!0,o=!1,i=void 0;try{for(var u,a=n[Symbol.iterator]();!(r=(u=a.next()).done)&&(t.push(u.value),!e||t.length!==e);r=!0);}catch(n){o=!0,i=n}finally{try{!r&&a.return&&a.return()}finally{if(o)throw i}}return t}return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return n(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();window.AuthenticationContext=require("adal-angular");var jwtDecode=require("jwt-decode"),eandisAuthenticator=function(n){var e={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={},w=function(n){t=n.authority,r=n.tenant,o=n.redirectUriWeb,i=n.redirectUriIOS,u=n.redirectUriAndroid,a=n.redirectUriWindows,c=n.resourceUri,s=n.clientId,f=n.userId,l=n.loginResource},v=function(n){if(n===e.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(n,e){localStorage.setItem(this.prefix+"-"+n,e)},get:function(n){return localStorage.getItem(this.prefix+"-"+n)},remove:function(n){localStorage.removeItem(this.prefix+"-"+n)}};E.set(e.IN_PROGRESS,!1);var R=function(){return window.cordova&&window.cordova.platformId||"browser"},I=function(){return new Promise(function(n,e){C(n,e)})},p=function(){return new Promise(function(n,t){try{h||v(e.MOBILE),h.tokenCache.clear(),n()}catch(n){t(n)}})},y=function(){return new Promise(function(n,t){try{d||v(e.BROWSER),d.logOut(),E.remove(e.TOKEN),n()}catch(n){t(n)}})},S=function(){return R()===e.BROWSER?y():p()},T=function(n,t,r){return new Promise(function(n,o){var i=function(e,t,r){r?o(r):n(t)};r?(d||v(e.BROWSER),d.acquireTokenPopup(s,null,null,i)):n(t)})},N=function(n,t,r){var o=E.get(e.TOKEN);if(o)n(o);else{d||v(e.BROWSER),d.handleWindowCallback();var i=function(e,r,o){T(e,r,o).then(n).catch(function(n){if("login required"===n)new Promise(function(n,e){C(n,e)});else t(n)})};d.acquireToken(s,i)}},k=function(n,t){h||v(e.MOBILE),h.tokenCache.readItems().then(function(e){var r=e.length-1,o=e[r]&&e[r].accessToken;o?n(o):t(new Error("No token found"))})},A=function(n){return new Promise(function(t,r){try{R()===e.BROWSER?N(t,r,n):k(t,r)}catch(n){r(n)}})},b=function(n){switch(n.toLowerCase()){case"android":O=u;break;case"ios":O=i;break;case"windows":O=a}},P=function(){return"true"===E.get(e.IN_PROGRESS)},_=function(){var n=E.get(e.TOKEN),t=E.get(e.TOKEN_EXPIRATION);return t&&parseInt(t,10)>Date.now()/1e3?{response:n,error:null}:m?{response:null,error:m}:{response:null,error:null}},x=function(n,r){Microsoft.ADAL.AuthenticationSettings.setUseBroker(!0).then(function(){v(e.MOBILE),b(R()),h.tokenCache.readItems().then(function(o){o.length>0&&(t=o[0].authority,v(e.MOBILE)),h.acquireTokenSilentAsync(c,s,f).then(n,function(){h.acquireTokenAsync(c,s,O).then(n,r)})})})},B=function(n,t){v(e.BROWSER);var r=_().response;r||P()||m?(d.saveTokenFromHash(d.getRequestInfo(window.location.hash)),n({token:r,error:null})):(E.set(e.IN_PROGRESS,!1),d.login(),n({token:null,error:null}))},C=function(n,t){try{R()===e.BROWSER?B(n,t):x(n,t)}catch(n){t(n)}},W=function(n){try{return jwtDecode(n)}catch(n){return console.error("unable to decode token",n),{}}},K=function n(){return Object.keys(g).length?Promise.resolve(g):A(n).then(function(n){var e=W(n),t=e.family_name,r=e.given_name,o=e.name,i=e.upn;return i||(i=W(n).email),g=j(t,r,o,i)})},U=function(n){var t=E.get(e.TOKEN_EXPIRATION);return t&&parseInt(t,10)>Date.now()/1e3},q=function(){var n=E.get(e.TOKEN);return U(n)?n:null},L=function(){var n=E.get(e.TOKEN);if(U(n)){var t=W(n),r=t.family_name,o=t.given_name,i=t.name,u=t.upn;return u||(u=W(n).email),g=j(r,o,i,u)}},j=function(n,e,t,r){return{familyName:n,givenName:e,name:t,upn:r}},M=function(n){function e(n){var e,t=/\+/g,r=/([^&=]+)=?([^&]*)/g,o=function(n){return decodeURIComponent(n.replace(t," "))},i={};for(e=r.exec(n);e;)i[o(e[1])]=o(e[2]),e=r.exec(n);return i}function t(n){var t="";return n.indexOf("#/")>-1?t=n.substring(n.indexOf("#/")+2):n.indexOf("#")>-1&&(t=n.substring(1)),t&&e(t)||null}function r(n){return n.substr(1).split("&").reduce(function(n,e){var t=e.split("="),r=_slicedToArray(t,2),o=r[0],i=r[1];return n.hasOwnProperty(o)?n:Object.assign({},n,_defineProperty({},o,decodeURIComponent(i)))},{})}return t(n||window.location.hash)||r(window.location.search)};return function(){var n=M(),t=function(e){return n[e]},r=t("id_token"),o=(t("state"),!0);if(r){var i=W(r),u=(i.nonce,i.aud,i.exp);i.family_name,i.given_name,i.name,i.upn;o&&(E.set(e.IN_PROGRESS,!1),E.set(e.TOKEN,r),E.set(e.TOKEN_EXPIRATION,u))}}(),{signIn:I,signOut:S,acquireToken:A,initialize:w,getUser:K,getUserFromCache:L,getTokenFromCache:q}}();module.exports={authentication:eandisAuthenticator}; |
@@ -302,5 +302,13 @@ 'use strict'; | ||
}; | ||
var isValidToken = function(token){ | ||
var expiration = storage.get(constants.TOKEN_EXPIRATION); | ||
return expiration && (parseInt(expiration, 10) > (Date.now() / 1000)); | ||
} | ||
var getTokenFromCache = function getTokenFromCache() { | ||
return storage.get(constants.TOKEN); | ||
var token = storage.get(constants.TOKEN); | ||
if(!isValidToken(token)){ | ||
return null; | ||
} | ||
return token; | ||
}; | ||
@@ -310,3 +318,3 @@ | ||
var token = storage.get(constants.TOKEN); | ||
if (token) { | ||
if (isValidToken(token)) { | ||
var _decodeTokenPayload2 = decodeTokenPayload(token), | ||
@@ -313,0 +321,0 @@ family_name = _decodeTokenPayload2.family_name, |
{ | ||
"name": "authentication-adal-pkg", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "An authentication SDK based on MS ADAL ", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
54401
8
1414
1
61