Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@equinor/fusion-framework-module-msal

Package Overview
Dependencies
Maintainers
3
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@equinor/fusion-framework-module-msal - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## 1.0.10 (2022-10-03)
**Note:** Version bump only for package @equinor/fusion-framework-module-msal
## [1.0.9](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module-msal@1.0.8...@equinor/fusion-framework-module-msal@1.0.9) (2022-09-29)

@@ -8,0 +16,0 @@

107

dist/esm/client/client.js

@@ -0,12 +1,25 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { PublicClientApplication, } from '@azure/msal-browser';
import { defaultBehavior } from './behavior';
export class AuthClient extends PublicClientApplication {
tenantId;
constructor(tenantId, config) {
super(config);
this.tenantId = tenantId;
}
get account() {
const accounts = this.getAllAccounts();
const account = accounts.find((a) => a.idTokenClaims?.aud === this.clientId);
const account = accounts.find((a) => { var _a; return ((_a = a.idTokenClaims) === null || _a === void 0 ? void 0 : _a.aud) === this.clientId; });
return account;
}
get hasValidClaims() {
const idTokenClaims = this.account?.idTokenClaims;
var _a;
const idTokenClaims = (_a = this.account) === null || _a === void 0 ? void 0 : _a.idTokenClaims;
if (idTokenClaims) {

@@ -19,3 +32,4 @@ const epoch = Math.ceil(Date.now() / 1000);

get clientId() {
return this.config.auth?.clientId;
var _a;
return (_a = this.config.auth) === null || _a === void 0 ? void 0 : _a.clientId;
}

@@ -25,49 +39,50 @@ get requestOrigin() {

}
constructor(tenantId, config) {
super(config);
this.tenantId = tenantId;
}
async login(options, behavior = defaultBehavior, silent = true) {
const loginHint = options?.loginHint || this.account?.username;
const scopes = options?.scopes || [];
const request = { ...options, loginHint, scopes };
if (loginHint && silent) {
this.logger.verbose('Attempting to login in silently');
try {
const res = await this.ssoSilent(request);
return res;
login(options, behavior = defaultBehavior, silent = true) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const loginHint = (options === null || options === void 0 ? void 0 : options.loginHint) || ((_a = this.account) === null || _a === void 0 ? void 0 : _a.username);
const scopes = (options === null || options === void 0 ? void 0 : options.scopes) || [];
const request = Object.assign(Object.assign({}, options), { loginHint, scopes });
if (loginHint && silent) {
this.logger.verbose('Attempting to login in silently');
try {
const res = yield this.ssoSilent(request);
return res;
}
catch (_b) {
this.logger.verbose('Silent login attempt failed');
}
}
catch {
this.logger.verbose('Silent login attempt failed');
this.logger.verbose(`Attempting to login in by [${behavior}]`);
switch (behavior) {
case 'popup':
return this.loginPopup(request);
case 'redirect': {
return this.loginRedirect(request);
}
}
}
this.logger.verbose(`Attempting to login in by [${behavior}]`);
switch (behavior) {
case 'popup':
return this.loginPopup(request);
case 'redirect': {
return this.loginRedirect(request);
}
}
});
}
async acquireToken(options = { scopes: [] }, behavior = defaultBehavior, silent = true) {
const account = await this.account;
if (silent && account) {
this.logger.verbose('Attempting to acquire token in silently');
try {
const token = await this.acquireTokenSilent({ account, ...options });
return token;
acquireToken(options = { scopes: [] }, behavior = defaultBehavior, silent = true) {
return __awaiter(this, void 0, void 0, function* () {
const account = yield this.account;
if (silent && account) {
this.logger.verbose('Attempting to acquire token in silently');
try {
const token = yield this.acquireTokenSilent(Object.assign({ account }, options));
return token;
}
catch (err) {
this.logger.info('Expected to navigate away from the current page but timeout occurred.');
}
}
catch (err) {
this.logger.info('Expected to navigate away from the current page but timeout occurred.');
this.logger.verbose(`Attempting to acquire token by [${behavior}]`);
switch (behavior) {
case 'popup':
return this.acquireTokenPopup(options);
case 'redirect': {
return this.acquireTokenRedirect(options);
}
}
}
this.logger.verbose(`Attempting to acquire token by [${behavior}]`);
switch (behavior) {
case 'popup':
return this.acquireTokenPopup(options);
case 'redirect': {
return this.acquireTokenRedirect(options);
}
}
});
}

@@ -74,0 +89,0 @@ }

import { AuthClient } from './client';
import { normalizeUri } from './util/url';
export const createAuthClient = (tenantId, clientId, redirectUri, config, ctor) => {
const auth = {
clientId,
redirectUri: normalizeUri(redirectUri || ''),
navigateToLoginRequestUrl: false,
authority: `https://login.microsoftonline.com/${tenantId}`,
...config?.auth,
};
const cache = { cacheLocation: 'localStorage', ...config?.cache };
const system = config?.system;
const auth = Object.assign({ clientId, redirectUri: normalizeUri(redirectUri || ''), navigateToLoginRequestUrl: false, authority: `https://login.microsoftonline.com/${tenantId}` }, config === null || config === void 0 ? void 0 : config.auth);
const cache = Object.assign({ cacheLocation: 'localStorage' }, config === null || config === void 0 ? void 0 : config.cache);
const system = config === null || config === void 0 ? void 0 : config.system;
return new (ctor || AuthClient)(tenantId, { auth, cache, system });

@@ -14,0 +8,0 @@ };

@@ -8,2 +8,15 @@ import { Logger, LogLevel } from '@azure/msal-browser';

});
this.getLogType = (lvl) => {
switch (lvl) {
case LogLevel.Error:
return 'error';
case LogLevel.Warning:
return 'warn';
case LogLevel.Info:
return 'info';
case LogLevel.Verbose:
default:
return 'debug';
}
};
}

@@ -13,17 +26,4 @@ loggerCallback(lvl, msg, _containsPii) {

}
getLogType = (lvl) => {
switch (lvl) {
case LogLevel.Error:
return 'error';
case LogLevel.Warning:
return 'warn';
case LogLevel.Info:
return 'info';
case LogLevel.Verbose:
default:
return 'debug';
}
};
}
export default ConsoleLogger;
//# sourceMappingURL=console.js.map
const DEFAULT_CONFIG_KEY = 'default';
export class AuthConfigurator {
_configs = {};
constructor() {
this._configs = {};
}
get defaultConfig() {

@@ -5,0 +7,0 @@ return this._configs[DEFAULT_CONFIG_KEY];

@@ -0,1 +1,10 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { AuthConfigurator } from './configurator';

@@ -6,4 +15,5 @@ import { AuthProvider } from './provider';

configure: (refModules) => {
var _a;
const configurator = new AuthConfigurator();
if (refModules?.auth?.defaultConfig) {
if ((_a = refModules === null || refModules === void 0 ? void 0 : refModules.auth) === null || _a === void 0 ? void 0 : _a.defaultConfig) {
configurator.configureDefault(refModules.auth.defaultConfig);

@@ -13,10 +23,10 @@ }

},
initialize: async ({ config, requireInstance }) => {
initialize: ({ config, requireInstance }) => __awaiter(void 0, void 0, void 0, function* () {
const authProvider = new AuthProvider(config);
try {
const httpModule = await requireInstance('http');
httpModule.defaultHttpRequestHandler.set('MSAL', async (request) => {
const httpModule = yield requireInstance('http');
httpModule.defaultHttpRequestHandler.set('MSAL', (request) => __awaiter(void 0, void 0, void 0, function* () {
const { scopes = [] } = request;
if (scopes.length) {
const token = await authProvider.acquireToken({
const token = yield authProvider.acquireToken({
scopes,

@@ -27,6 +37,6 @@ });

headers.set('Authorization', `Bearer ${token.accessToken}`);
return { ...request, headers };
return Object.assign(Object.assign({}, request), { headers });
}
}
});
}));
}

@@ -37,3 +47,3 @@ catch (err) {

return authProvider;
},
}),
};

@@ -44,3 +54,3 @@ export const configureMsal = (defaultClient, args) => ({

config.configureDefault(defaultClient);
const { clients } = args ?? {};
const { clients } = args !== null && args !== void 0 ? args : {};
if (clients) {

@@ -50,12 +60,12 @@ Object.entries(clients).forEach(([key, opt]) => config.configureClient(key, opt));

},
afterInit: async (auth) => {
if (args?.requiresAuth) {
await auth.handleRedirect();
afterInit: (auth) => __awaiter(void 0, void 0, void 0, function* () {
if (args === null || args === void 0 ? void 0 : args.requiresAuth) {
yield auth.handleRedirect();
if (!auth.defaultAccount) {
await auth.login();
yield auth.login();
}
}
},
}),
});
export default module;
//# sourceMappingURL=module.js.map

@@ -0,6 +1,17 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { createAuthClient, ConsoleLogger } from './client';
const DEFAULT_CLIENT_NAME = 'default';
export class AuthProvider {
_config;
_clients = {};
constructor(_config) {
this._config = _config;
this._clients = {};
}
get defaultClient() {

@@ -15,5 +26,2 @@ return this.getClient(DEFAULT_CLIENT_NAME);

}
constructor(_config) {
this._config = _config;
}
getClient(name) {

@@ -34,18 +42,20 @@ if (!this._clients[name]) {

}
async handleRedirect() {
const { redirectUri } = this.defaultConfig || {};
if (window.location.pathname === redirectUri) {
const client = this.defaultClient;
const logger = client.getLogger();
const { requestOrigin } = client;
await client.handleRedirectPromise();
if (requestOrigin === redirectUri) {
logger.warning(`detected callback loop from url ${redirectUri}, redirecting to root`);
window.location.replace('/');
handleRedirect() {
return __awaiter(this, void 0, void 0, function* () {
const { redirectUri } = this.defaultConfig || {};
if (window.location.pathname === redirectUri) {
const client = this.defaultClient;
const logger = client.getLogger();
const { requestOrigin } = client;
yield client.handleRedirectPromise();
if (requestOrigin === redirectUri) {
logger.warning(`detected callback loop from url ${redirectUri}, redirecting to root`);
window.location.replace('/');
}
else {
window.location.replace(requestOrigin || '/');
}
}
else {
window.location.replace(requestOrigin || '/');
}
}
return null;
return null;
});
}

@@ -55,10 +65,14 @@ acquireToken(req) {

}
async acquireAccessToken(req) {
const token = await this.acquireToken(req);
return token ? token.accessToken : undefined;
acquireAccessToken(req) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this.acquireToken(req);
return token ? token.accessToken : undefined;
});
}
async login() {
await this.defaultClient.login();
login() {
return __awaiter(this, void 0, void 0, function* () {
yield this.defaultClient.login();
});
}
}
//# sourceMappingURL=provider.js.map
{
"name": "@equinor/fusion-framework-module-msal",
"version": "1.0.9",
"version": "1.0.10",
"description": "",

@@ -36,3 +36,3 @@ "main": "dist/esm/index.js",

"@equinor/fusion-framework-module": "^1.2.2",
"@equinor/fusion-framework-module-http": "^2.0.9"
"@equinor/fusion-framework-module-http": "^2.0.10"
},

@@ -42,3 +42,3 @@ "devDependencies": {

},
"gitHead": "81198e7772ed6e1f0c318fc37c5b4f2a9fe72ada"
"gitHead": "8b7efac3ab5b1db6531a89b884714dd90cb482e8"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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