New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

authentication-adal-pkg

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

authentication-adal-pkg - npm Package Compare versions

Comparing version 1.0.29 to 1.0.30

251

index.js

@@ -31,3 +31,3 @@ window.AuthenticationContext = require('adal-angular');

const initialize = (config) => {
const initialize = config => {
authority = config.authority;

@@ -43,5 +43,5 @@ tenant = config.tenant;

loginResource = config.loginResource;
}
};
const initAuthenticationContext = (platform) => {
const initAuthenticationContext = platform => {
if (platform === constants.BROWSER) {

@@ -52,3 +52,3 @@ const config = {

redirectUri: redirectUriWeb,
loginResource: loginResource,
loginResource: loginResource
};

@@ -59,3 +59,3 @@ auth = new AuthenticationContext(config);

}
}
};

@@ -77,33 +77,37 @@ const storage = {

const getPlatform = () => (window.cordova && window.cordova.platformId) || 'browser';
const getPlatform = () =>
(window.cordova && window.cordova.platformId) || 'browser';
const signIn = () => new Promise((resolve, reject) => {
authenticate(resolve, reject);
});
const signIn = () =>
new Promise((resolve, reject) => {
authenticate(resolve, reject);
});
const signOutMobile = () => new Promise((resolve, reject) => {
try {
if (!authContext) {
initAuthenticationContext(constants.MOBILE);
const signOutMobile = () =>
new Promise((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 = () =>
new Promise((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);
}
});
});

@@ -116,21 +120,19 @@ const signOut = () => {

}
}
};
const onAcquireToken = (errorDesc, token, error) => new Promise((resolve, reject) => {
const acquireTokenCallback = (desc, token, err) => {
if (err)
reject(err);
else
const onAcquireToken = (errorDesc, token, error) =>
new Promise((resolve, reject) => {
const acquireTokenCallback = (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);
}
});
});

@@ -146,12 +148,14 @@ const acquireTokenBrowser = (resolve, reject, cb) => {

const acquireTokenCallback = (errorDesc, token, error) => {
onAcquireToken(errorDesc, token, error).then(resolve).catch((e) => {
if (e === 'login required') {
const authPromise = new Promise((resolve, reject) => {
authenticate(resolve, reject);
});
} else{
reject(e);
}
});
}
onAcquireToken(errorDesc, token, error)
.then(resolve)
.catch(e => {
if (e === 'login required') {
const authPromise = new Promise((resolve, reject) => {
authenticate(resolve, reject);
});
} else {
reject(e);
}
});
};
auth.acquireToken(clientId, acquireTokenCallback);

@@ -161,3 +165,3 @@ } else {

}
}
};

@@ -168,3 +172,3 @@ const acquireTokenMobile = (resolve, reject) => {

}
authContext.tokenCache.readItems().then((items) => {
authContext.tokenCache.readItems().then(items => {
const index = items.length - 1;

@@ -177,18 +181,19 @@ 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 = cb =>
new Promise((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 = platform => {
switch (platform.toLowerCase()) {

@@ -205,3 +210,3 @@ case 'android':

}
}
};

@@ -213,10 +218,10 @@ const isInProgress = () => storage.get(constants.IN_PROGRESS) === 'true';

const expiration = storage.get(constants.TOKEN_EXPIRATION);
if (expiration && (parseInt(expiration, 10) > (Date.now() / 1000))) {
if (expiration && parseInt(expiration, 10) > Date.now() / 1000) {
// log.info('valid cached token');
return {response: token, error: null};
return { response: token, error: null };
} else if (localError) {
return {response: null, error: localError};
return { response: null, error: localError };
}
return {response: null, error: null};
}
return { response: null, error: null };
};

@@ -230,3 +235,3 @@ const authenticateMobile = (resolve, reject) => {

// This prevents an additional prompt
authContext.tokenCache.readItems().then((items) => {
authContext.tokenCache.readItems().then(items => {
if (items.length > 0) {

@@ -237,21 +242,25 @@ authority = items[0].authority;

// Attempt to authorize user silently
authContext.acquireTokenSilentAsync(resourceUri, clientId, userId).then(resolve, () => {
// We require user credentials so triggers authentication dialog
authContext.acquireTokenAsync(resourceUri, clientId, platformRedirectUri).then(resolve, reject);
});
authContext
.acquireTokenSilentAsync(resourceUri, clientId, userId)
.then(resolve, () => {
// We require user credentials so triggers authentication dialog
authContext
.acquireTokenAsync(resourceUri, clientId, platformRedirectUri)
.then(resolve, reject);
});
});
});
}
};
const authenticateBrowser = (resolve, reject) => {
initAuthenticationContext(constants.BROWSER);
const {response: token} = getCachedToken();
const { response: token } = getCachedToken();
if (!token && !isInProgress() && !localError) {
storage.set(constants.IN_PROGRESS, false);
auth.login();
resolve({token: null, error: null});
resolve({ token: null, error: null });
} else {
auth.saveTokenFromHash(auth.getRequestInfo(window.location.hash));
resolve({token, error: null});
resolve({ token, error: null });
}
}
};
const authenticate = (resolve, reject) => {

@@ -268,5 +277,5 @@ try {

}
}
};
const decodeTokenPayload = (token) => {
const decodeTokenPayload = token => {
try {

@@ -278,8 +287,8 @@ return jwtDecode(token);

}
}
};
const getUser = () => {
if (!Object.keys(user).length) {
return acquireToken(getUser).then((token) => {
var {family_name, given_name, name, upn} = decodeTokenPayload(token);
return acquireToken(getUser).then(token => {
var { family_name, given_name, name, upn } = decodeTokenPayload(token);
if (!upn) {

@@ -293,12 +302,12 @@ upn = decodeTokenPayload(token).email;

return Promise.resolve(user);
}
};
const getTokenFromCache = () => {
return storage.get(constants.TOKEN);
}
};
const getUserFromCache = () => {
const token = storage.get(constants.TOKEN);
if(token){
var {family_name, given_name, name, upn} = decodeTokenPayload(token);
if (token) {
var { family_name, given_name, name, upn } = decodeTokenPayload(token);
if (!upn) {

@@ -310,9 +319,9 @@ upn = decodeTokenPayload(token).email;

}
}
};
const createUser = (familyName, givenName, name, upn) => {
return {familyName, givenName, name, upn};
}
return { familyName, givenName, name, upn };
};
const getUrlParameters = (hash) => {
const getUrlParameters = hash => {
function deserializeHash(query) {

@@ -343,14 +352,22 @@ var match;

function getQueryParams(url) {
return url.substr(1).split('&').reduce((params, item) => {
const [key,
value] = item.split('=');
if (!params.hasOwnProperty(key)) { // eslint-disable-line no-prototype-builtins
return Object.assign({}, params, {[key]: decodeURIComponent(value)});
}
return params;
}, {});
return url
.substr(1)
.split('&')
.reduce((params, item) => {
const [key, value] = item.split('=');
if (!params.hasOwnProperty(key)) {
// eslint-disable-line no-prototype-builtins
return Object.assign({}, params, {
[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)
);
};

@@ -381,5 +398,13 @@ const handleWindowCallback = () => {

}
}
};
handleWindowCallback();
return {signIn, signOut, acquireToken, initialize, getUser, getUserFromCache, getTokenFromCache}
return {
signIn,
signOut,
acquireToken,
initialize,
getUser,
getUserFromCache,
getTokenFromCache
};
})();

@@ -386,0 +411,0 @@

@@ -242,5 +242,10 @@ 'use strict';

} else {
// No token found
authenticateMobile(resolve, reject);
// reject(new Error('No token found'));
var token = getTokenFromCache();
if (token) {
resolve(token);
} else {
// No token found
authenticateMobile(resolve, reject);
// reject(new Error('No token found'));
}
}

@@ -247,0 +252,0 @@ });

{
"name": "authentication-adal-pkg",
"version": "1.0.29",
"version": "1.0.30",
"description": "An authentication SDK based on MS ADAL ",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc