authentication-adal-pkg
Advanced tools
Comparing version 1.0.1 to 1.0.2
178
lib/index.js
@@ -31,3 +31,3 @@ window.AuthenticationContext = require('adal-angular'); | ||
const initialize = (config) => { | ||
const initialize = function(config){ | ||
authority = config.AUTHORITY; | ||
@@ -45,3 +45,3 @@ tenant = config.TENANT; | ||
const initAuthenticationContext = (platform) => { | ||
const initAuthenticationContext = function(platform){ | ||
if (platform === constants.BROWSER) { | ||
@@ -75,35 +75,41 @@ const config = { | ||
const getPlatform = () => (window.cordova && window.cordova.platformId) || 'browser'; | ||
const getPlatform = function(){ return (window.cordova && window.cordova.platformId) || 'browser'; } | ||
const signIn = () => new Promise((resolve, reject) => { | ||
authenticate(resolve, reject); | ||
}); | ||
const signIn = function(){ | ||
return new Promise(function(resolve, reject){ | ||
authenticate(resolve, reject); | ||
}); | ||
} | ||
const signOutMobile = () => new Promise((resolve, reject) => { | ||
try { | ||
if (!authContext) { | ||
initAuthenticationContext(constants.MOBILE); | ||
const signOutMobile = function(){ | ||
return new Promise(function(resolve, reject){ | ||
try { | ||
if (!authContext) { | ||
initAuthenticationContext(constants.MOBILE); | ||
} | ||
authContext.tokenCache.clear(); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
authContext.tokenCache.clear(); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
// request naar https://login.windows.net/{tenantid or "common"}/oauth2/logout?post_logout_redirect_uri={URL} | ||
}); | ||
// request naar https://login.windows.net/{tenantid or "common"}/oauth2/logout?post_logout_redirect_uri={URL} | ||
}); | ||
} | ||
const signOutBrowser = () => new Promise((resolve, reject) => { | ||
try { | ||
if (!auth) { | ||
initAuthenticationContext(constants.BROWSER); | ||
const signOutBrowser = function(){ | ||
return new Promise(function(resolve, reject){ | ||
try { | ||
if (!auth) { | ||
initAuthenticationContext(constants.BROWSER); | ||
} | ||
auth.logOut(); | ||
storage.remove(constants.TOKEN); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
auth.logOut(); | ||
storage.remove(constants.TOKEN); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
const signOut = () => { | ||
const signOut = function(){ | ||
if (getPlatform() === constants.BROWSER) { | ||
@@ -116,21 +122,23 @@ return signOutBrowser(); | ||
const onAcquireToken = (errorDesc, token, error) => new Promise((resolve, reject) => { | ||
const acquireTokenCallback = (desc, token, err) => { | ||
if (err) | ||
reject(err); | ||
else | ||
const onAcquireToken = function(errorDesc, token, error){ | ||
return new Promise(function(resolve, reject){ | ||
const acquireTokenCallback = function(desc, token, err){ | ||
if (err) | ||
reject(err); | ||
else | ||
resolve(token); | ||
} | ||
; | ||
if (error) { | ||
if (!auth) { | ||
initAuthenticationContext(constants.BROWSER); | ||
} | ||
auth.acquireTokenPopup(clientId, null, null, acquireTokenCallback); | ||
} else { | ||
resolve(token); | ||
} | ||
; | ||
if (error) { | ||
if (!auth) { | ||
initAuthenticationContext(constants.BROWSER); | ||
} | ||
auth.acquireTokenPopup(clientId, null, null, acquireTokenCallback); | ||
} else { | ||
resolve(token); | ||
} | ||
}); | ||
}); | ||
} | ||
const acquireTokenBrowser = (resolve, reject, cb) => { | ||
const acquireTokenBrowser = function(resolve, reject, cb){ | ||
const token = storage.get(constants.TOKEN); | ||
@@ -143,6 +151,6 @@ if (!token) { | ||
auth.handleWindowCallback(); | ||
const acquireTokenCallback = (errorDesc, token, error) => { | ||
onAcquireToken(errorDesc, token, error).then(resolve).catch((e) => { | ||
const acquireTokenCallback = function(errorDesc, token, error){ | ||
onAcquireToken(errorDesc, token, error).then(resolve).catch(function(e) { | ||
if (e === 'login required') { | ||
const authPromise = new Promise((resolve, reject) => { | ||
const authPromise = new Promise(function(resolve, reject){ | ||
authenticate(resolve, reject); | ||
@@ -161,7 +169,7 @@ }); | ||
const acquireTokenMobile = (resolve, reject) => { | ||
const acquireTokenMobile = function(resolve, reject){ | ||
if (!authContext) { | ||
initAuthenticationContext(constants.MOBILE); | ||
} | ||
authContext.tokenCache.readItems().then((items) => { | ||
authContext.tokenCache.readItems().then(function(items){ | ||
const index = items.length - 1; | ||
@@ -174,18 +182,20 @@ const token = items[index] && items[index].accessToken; | ||
} | ||
}) | ||
}); | ||
} | ||
const acquireToken = (cb) => new Promise((resolve, reject) => { | ||
try { | ||
if (getPlatform() === constants.BROWSER) { | ||
acquireTokenBrowser(resolve, reject, cb); | ||
} else { | ||
acquireTokenMobile(resolve, reject); | ||
const acquireToken = function(cb){ | ||
return new Promise(function(resolve, reject){ | ||
try { | ||
if (getPlatform() === constants.BROWSER) { | ||
acquireTokenBrowser(resolve, reject, cb); | ||
} else { | ||
acquireTokenMobile(resolve, reject); | ||
} | ||
} catch (err) { | ||
reject(err); | ||
} | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
const setPlatformRedirectUri = (platform) => { | ||
const setPlatformRedirectUri = function(platform){ | ||
switch (platform.toLowerCase()) { | ||
@@ -204,5 +214,7 @@ case 'android': | ||
const isInProgress = () => storage.get(constants.IN_PROGRESS) === 'true'; | ||
const isInProgress = function(){ | ||
return storage.get(constants.IN_PROGRESS) === 'true'; | ||
} | ||
const getCachedToken = () => { | ||
const getCachedToken = function(){ | ||
const token = storage.get(constants.TOKEN); | ||
@@ -219,5 +231,5 @@ const expiration = storage.get(constants.TOKEN_EXPIRATION); | ||
const authenticateMobile = (resolve, reject) => { | ||
const authenticateMobile = function(resolve, reject){ | ||
// Check if MS ADAL cordova library is installed | ||
Microsoft.ADAL.AuthenticationSettings.setUseBroker(true).then(() => { | ||
Microsoft.ADAL.AuthenticationSettings.setUseBroker(true).then(function(){ | ||
initAuthenticationContext(constants.MOBILE); | ||
@@ -227,3 +239,3 @@ setPlatformRedirectUri(getPlatform()); | ||
// This prevents an additional prompt | ||
authContext.tokenCache.readItems().then((items) => { | ||
authContext.tokenCache.readItems().then(function(items){ | ||
if (items.length > 0) { | ||
@@ -234,3 +246,3 @@ authority = items[0].authority; | ||
// Attempt to authorize user silently | ||
authContext.acquireTokenSilentAsync(resourceUri, clientId, userId).then(resolve, () => { | ||
authContext.acquireTokenSilentAsync(resourceUri, clientId, userId).then(resolve, function(){ | ||
// We require user credentials so triggers authentication dialog | ||
@@ -242,3 +254,3 @@ authContext.acquireTokenAsync(resourceUri, clientId, platformRedirectUri).then(resolve, reject); | ||
} | ||
const authenticateBrowser = (resolve, reject) => { | ||
const authenticateBrowser = function(resolve, reject){ | ||
initAuthenticationContext(constants.BROWSER); | ||
@@ -255,3 +267,3 @@ const {response: token} = getCachedToken(); | ||
} | ||
const authenticate = (resolve, reject) => { | ||
const authenticate = function(resolve, reject){ | ||
try { | ||
@@ -269,3 +281,3 @@ // Check platformId | ||
const decodeTokenPayload = (token) => { | ||
const decodeTokenPayload = function(token){ | ||
try { | ||
@@ -279,5 +291,5 @@ return jwtDecode(token); | ||
const getUser = () => { | ||
const getUser = function(){ | ||
if (!Object.keys(user).length) { | ||
return acquireToken(getUser).then((token) => { | ||
return acquireToken(getUser).then(function(token){ | ||
var {family_name, given_name, name, upn} = decodeTokenPayload(token); | ||
@@ -294,7 +306,7 @@ if (!upn) { | ||
const getTokenFromCache = () => { | ||
const getTokenFromCache = function(){ | ||
return storage.get(constants.TOKEN); | ||
} | ||
const getUserFromCache = () => { | ||
const getUserFromCache = function(){ | ||
const token = storage.get(constants.TOKEN); | ||
@@ -311,7 +323,7 @@ if(token){ | ||
const createUser = (familyName, givenName, name, upn) => { | ||
const createUser = function(familyName, givenName, name, upn){ | ||
return {familyName, givenName, name, upn}; | ||
} | ||
const getUrlParameters = (hash) => { | ||
const getUrlParameters = function(hash){ | ||
function deserializeHash(query) { | ||
@@ -321,3 +333,5 @@ var match; | ||
const search = /([^&=]+)=?([^&]*)/g; | ||
const decode = s => decodeURIComponent(s.replace(pl, ' ')); | ||
const decode = function(){ | ||
return decodeURIComponent(s.replace(pl, ' ')); | ||
} | ||
const parameters = {}; | ||
@@ -343,3 +357,3 @@ match = search.exec(query); | ||
function getQueryParams(url) { | ||
return url.substr(1).split('&').reduce((params, item) => { | ||
return url.substr(1).split('&').reduce(function(params, item){ | ||
const [key, | ||
@@ -357,6 +371,8 @@ value] = item.split('='); | ||
const handleWindowCallback = () => { | ||
const handleWindowCallback = function(){ | ||
//get token from parameter and push to session storage | ||
const parameters = getUrlParameters(); | ||
const getParameter = key => parameters[key]; | ||
const getParameter = function(key){ | ||
return parameters[key]; | ||
} | ||
const token = getParameter('id_token'); | ||
@@ -363,0 +379,0 @@ const state = getParameter('state'); |
{ | ||
"name": "authentication-adal-pkg", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"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
43863
5
1366