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

@coveo/auth

Package Overview
Dependencies
Maintainers
12
Versions
467
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coveo/auth - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

8

CHANGELOG.md

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

## [1.1.3](https://github.com/coveo/ui-kit/compare/@coveo/auth@1.1.2...@coveo/auth@1.1.3) (2021-12-09)
**Note:** Version bump only for package @coveo/auth
## [1.1.2](https://github.com/coveo/ui-kit/compare/@coveo/auth@1.1.1...@coveo/auth@1.1.2) (2021-11-30)

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

256

dist/auth.esm.js

@@ -1,154 +0,156 @@

/**
* Copyright 2021 Coveo Solutions Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
Copyright 2021 Coveo Solutions Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// src/saml/browser-fetch.ts
function getBrowserFetch() {
const isBrowser = typeof window !== 'undefined';
return isBrowser ? fetch : () => Promise.resolve(new Response());
const isBrowser = typeof window !== "undefined";
return isBrowser ? fetch : () => Promise.resolve(new Response());
}
// src/saml/browser-history.ts
function getBrowserHistory() {
const isBrowser = typeof window !== 'undefined';
return isBrowser ? history : { replaceState: () => { } };
const isBrowser = typeof window !== "undefined";
return isBrowser ? history : { replaceState: () => {
} };
}
// src/saml/browser-location.ts
function getBrowserLocation() {
const isBrowser = typeof window !== 'undefined';
return isBrowser ? location : { href: '', hash: '' };
const isBrowser = typeof window !== "undefined";
return isBrowser ? location : { href: "", hash: "" };
}
const handshakeTokenParamName = 'handshake_token';
// src/saml/saml-flow.ts
var handshakeTokenParamName = "handshake_token";
function buildSamlFlow(config) {
const options = buildOptions(config);
const api = `${options.platformOrigin}/rest/search/v2/login`;
return {
login() {
const { organizationId, provider, location } = options;
const redirectUri = encodeURIComponent(location.href);
const params = `organizationId=${organizationId}&redirectUri=${redirectUri}`;
location.href = `${api}/${provider}?${params}`;
},
async exchangeHandshakeToken() {
const { location, history, request } = options;
const handshakeToken = getHandshakeToken(location);
removeHandshakeToken(location, history);
try {
const response = await request(`${api}/handshake/token`, {
method: 'POST',
body: JSON.stringify({ handshakeToken }),
headers: {
'content-type': 'application/json; charset=UTF-8',
},
});
const data = await response.json();
return data.token;
}
catch (e) {
return '';
}
},
get handshakeTokenAvailable() {
return !!getHandshakeToken(options.location);
},
};
const options = buildOptions(config);
const api = `${options.platformOrigin}/rest/search/v2/login`;
return {
login() {
const { organizationId, provider, location: location2 } = options;
const redirectUri = encodeURIComponent(location2.href);
const params = `organizationId=${organizationId}&redirectUri=${redirectUri}`;
location2.href = `${api}/${provider}?${params}`;
},
async exchangeHandshakeToken() {
const { location: location2, history: history2, request } = options;
const handshakeToken = getHandshakeToken(location2);
removeHandshakeToken(location2, history2);
try {
const response = await request(`${api}/handshake/token`, {
method: "POST",
body: JSON.stringify({ handshakeToken }),
headers: {
"content-type": "application/json; charset=UTF-8"
}
});
const data = await response.json();
return data.token;
} catch (e) {
return "";
}
},
get handshakeTokenAvailable() {
return !!getHandshakeToken(options.location);
}
};
}
function buildOptions(config) {
return {
location: getBrowserLocation(),
history: getBrowserHistory(),
request: getBrowserFetch(),
platformOrigin: 'https://platform.cloud.coveo.com',
...config,
};
return {
location: getBrowserLocation(),
history: getBrowserHistory(),
request: getBrowserFetch(),
platformOrigin: "https://platform.cloud.coveo.com",
...config
};
}
function getHandshakeToken(location) {
const params = getHashParamsAfterAdjustingForAngular(location);
const handshakeParam = params.get(handshakeTokenParamName);
return handshakeParam || '';
function getHandshakeToken(location2) {
const params = getHashParamsAfterAdjustingForAngular(location2);
const handshakeParam = params.get(handshakeTokenParamName);
return handshakeParam || "";
}
function getHashParamsAfterAdjustingForAngular(location) {
const hash = location.hash;
const adjustedHash = isAngularHash(location) ? hash.slice(2) : hash.slice(1);
return new URLSearchParams(adjustedHash);
function getHashParamsAfterAdjustingForAngular(location2) {
const hash = location2.hash;
const adjustedHash = isAngularHash(location2) ? hash.slice(2) : hash.slice(1);
return new URLSearchParams(adjustedHash);
}
function isAngularHash(location) {
const hash = location.hash;
return hash.indexOf('#/') === 0;
function isAngularHash(location2) {
const hash = location2.hash;
return hash.indexOf("#/") === 0;
}
function removeHandshakeToken(location, history) {
const params = getHashParamsAfterAdjustingForAngular(location);
params.delete(handshakeTokenParamName);
const newHash = params.toString();
const adjustedHash = isAngularHash(location) ? `/${newHash}` : newHash;
history.replaceState(null, '', `#${adjustedHash}`);
function removeHandshakeToken(location2, history2) {
const params = getHashParamsAfterAdjustingForAngular(location2);
params.delete(handshakeTokenParamName);
const newHash = params.toString();
const adjustedHash = isAngularHash(location2) ? `/${newHash}` : newHash;
history2.replaceState(null, "", `#${adjustedHash}`);
}
// src/saml/browser-storage.ts
function getBrowserStorage() {
try {
return window.localStorage;
}
catch (_a) {
return {
getItem: () => null,
setItem: () => { },
removeItem: () => { },
};
}
try {
return window.localStorage;
} catch (e) {
return {
getItem: () => null,
setItem: () => {
},
removeItem: () => {
}
};
}
}
// src/saml/saml-state.ts
function buildSamlState(config = {}) {
const loginPendingFlag = 'samlLoginPending';
const storage = config.storage || getBrowserStorage();
return {
get isLoginPending() {
return storage.getItem(loginPendingFlag) === 'true';
},
removeLoginPending() {
storage.removeItem(loginPendingFlag);
},
setLoginPending() {
storage.setItem(loginPendingFlag, 'true');
},
};
const loginPendingFlag = "samlLoginPending";
const storage = config.storage || getBrowserStorage();
return {
get isLoginPending() {
return storage.getItem(loginPendingFlag) === "true";
},
removeLoginPending() {
storage.removeItem(loginPendingFlag);
},
setLoginPending() {
storage.setItem(loginPendingFlag, "true");
}
};
}
/**
* Instantiates a SAML client.
*
* @param config - The SAML client options.
* @returns A SAML client instance.
*/
// src/saml/saml-client.ts
function buildSamlClient(config) {
const provider = buildSamlFlow(config);
const state = buildSamlState();
return {
async authenticate() {
if (provider.handshakeTokenAvailable) {
state.removeLoginPending();
return await provider.exchangeHandshakeToken();
}
if (state.isLoginPending) {
state.removeLoginPending();
console.warn('No handshake token found in url. Skipping redirect to avoid an infinite loop. Manually refresh the page to restart SAML authentication flow.');
return '';
}
state.setLoginPending();
provider.login();
return '';
},
};
const provider = buildSamlFlow(config);
const state = buildSamlState();
return {
async authenticate() {
if (provider.handshakeTokenAvailable) {
state.removeLoginPending();
return await provider.exchangeHandshakeToken();
}
if (state.isLoginPending) {
state.removeLoginPending();
console.warn("No handshake token found in url. Skipping redirect to avoid an infinite loop. Manually refresh the page to restart SAML authentication flow.");
return "";
}
state.setLoginPending();
provider.login();
return "";
}
};
}
export { buildSamlClient };
export {
buildSamlClient
};

@@ -1,158 +0,166 @@

/**
* Copyright 2021 Coveo Solutions Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
Copyright 2021 Coveo Solutions Inc.
'use strict';
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var __defProp = Object.defineProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
Object.defineProperty(exports, '__esModule', { value: true });
// src/auth.ts
__export(exports, {
buildSamlClient: () => buildSamlClient
});
// src/saml/browser-fetch.ts
function getBrowserFetch() {
const isBrowser = typeof window !== 'undefined';
return isBrowser ? fetch : () => Promise.resolve(new Response());
const isBrowser = typeof window !== "undefined";
return isBrowser ? fetch : () => Promise.resolve(new Response());
}
// src/saml/browser-history.ts
function getBrowserHistory() {
const isBrowser = typeof window !== 'undefined';
return isBrowser ? history : { replaceState: () => { } };
const isBrowser = typeof window !== "undefined";
return isBrowser ? history : { replaceState: () => {
} };
}
// src/saml/browser-location.ts
function getBrowserLocation() {
const isBrowser = typeof window !== 'undefined';
return isBrowser ? location : { href: '', hash: '' };
const isBrowser = typeof window !== "undefined";
return isBrowser ? location : { href: "", hash: "" };
}
const handshakeTokenParamName = 'handshake_token';
// src/saml/saml-flow.ts
var handshakeTokenParamName = "handshake_token";
function buildSamlFlow(config) {
const options = buildOptions(config);
const api = `${options.platformOrigin}/rest/search/v2/login`;
return {
login() {
const { organizationId, provider, location } = options;
const redirectUri = encodeURIComponent(location.href);
const params = `organizationId=${organizationId}&redirectUri=${redirectUri}`;
location.href = `${api}/${provider}?${params}`;
},
async exchangeHandshakeToken() {
const { location, history, request } = options;
const handshakeToken = getHandshakeToken(location);
removeHandshakeToken(location, history);
try {
const response = await request(`${api}/handshake/token`, {
method: 'POST',
body: JSON.stringify({ handshakeToken }),
headers: {
'content-type': 'application/json; charset=UTF-8',
},
});
const data = await response.json();
return data.token;
}
catch (e) {
return '';
}
},
get handshakeTokenAvailable() {
return !!getHandshakeToken(options.location);
},
};
const options = buildOptions(config);
const api = `${options.platformOrigin}/rest/search/v2/login`;
return {
login() {
const { organizationId, provider, location: location2 } = options;
const redirectUri = encodeURIComponent(location2.href);
const params = `organizationId=${organizationId}&redirectUri=${redirectUri}`;
location2.href = `${api}/${provider}?${params}`;
},
async exchangeHandshakeToken() {
const { location: location2, history: history2, request } = options;
const handshakeToken = getHandshakeToken(location2);
removeHandshakeToken(location2, history2);
try {
const response = await request(`${api}/handshake/token`, {
method: "POST",
body: JSON.stringify({ handshakeToken }),
headers: {
"content-type": "application/json; charset=UTF-8"
}
});
const data = await response.json();
return data.token;
} catch (e) {
return "";
}
},
get handshakeTokenAvailable() {
return !!getHandshakeToken(options.location);
}
};
}
function buildOptions(config) {
return {
location: getBrowserLocation(),
history: getBrowserHistory(),
request: getBrowserFetch(),
platformOrigin: 'https://platform.cloud.coveo.com',
...config,
};
return {
location: getBrowserLocation(),
history: getBrowserHistory(),
request: getBrowserFetch(),
platformOrigin: "https://platform.cloud.coveo.com",
...config
};
}
function getHandshakeToken(location) {
const params = getHashParamsAfterAdjustingForAngular(location);
const handshakeParam = params.get(handshakeTokenParamName);
return handshakeParam || '';
function getHandshakeToken(location2) {
const params = getHashParamsAfterAdjustingForAngular(location2);
const handshakeParam = params.get(handshakeTokenParamName);
return handshakeParam || "";
}
function getHashParamsAfterAdjustingForAngular(location) {
const hash = location.hash;
const adjustedHash = isAngularHash(location) ? hash.slice(2) : hash.slice(1);
return new URLSearchParams(adjustedHash);
function getHashParamsAfterAdjustingForAngular(location2) {
const hash = location2.hash;
const adjustedHash = isAngularHash(location2) ? hash.slice(2) : hash.slice(1);
return new URLSearchParams(adjustedHash);
}
function isAngularHash(location) {
const hash = location.hash;
return hash.indexOf('#/') === 0;
function isAngularHash(location2) {
const hash = location2.hash;
return hash.indexOf("#/") === 0;
}
function removeHandshakeToken(location, history) {
const params = getHashParamsAfterAdjustingForAngular(location);
params.delete(handshakeTokenParamName);
const newHash = params.toString();
const adjustedHash = isAngularHash(location) ? `/${newHash}` : newHash;
history.replaceState(null, '', `#${adjustedHash}`);
function removeHandshakeToken(location2, history2) {
const params = getHashParamsAfterAdjustingForAngular(location2);
params.delete(handshakeTokenParamName);
const newHash = params.toString();
const adjustedHash = isAngularHash(location2) ? `/${newHash}` : newHash;
history2.replaceState(null, "", `#${adjustedHash}`);
}
// src/saml/browser-storage.ts
function getBrowserStorage() {
try {
return window.localStorage;
}
catch (_a) {
return {
getItem: () => null,
setItem: () => { },
removeItem: () => { },
};
}
try {
return window.localStorage;
} catch (e) {
return {
getItem: () => null,
setItem: () => {
},
removeItem: () => {
}
};
}
}
// src/saml/saml-state.ts
function buildSamlState(config = {}) {
const loginPendingFlag = 'samlLoginPending';
const storage = config.storage || getBrowserStorage();
return {
get isLoginPending() {
return storage.getItem(loginPendingFlag) === 'true';
},
removeLoginPending() {
storage.removeItem(loginPendingFlag);
},
setLoginPending() {
storage.setItem(loginPendingFlag, 'true');
},
};
const loginPendingFlag = "samlLoginPending";
const storage = config.storage || getBrowserStorage();
return {
get isLoginPending() {
return storage.getItem(loginPendingFlag) === "true";
},
removeLoginPending() {
storage.removeItem(loginPendingFlag);
},
setLoginPending() {
storage.setItem(loginPendingFlag, "true");
}
};
}
/**
* Instantiates a SAML client.
*
* @param config - The SAML client options.
* @returns A SAML client instance.
*/
// src/saml/saml-client.ts
function buildSamlClient(config) {
const provider = buildSamlFlow(config);
const state = buildSamlState();
return {
async authenticate() {
if (provider.handshakeTokenAvailable) {
state.removeLoginPending();
return await provider.exchangeHandshakeToken();
}
if (state.isLoginPending) {
state.removeLoginPending();
console.warn('No handshake token found in url. Skipping redirect to avoid an infinite loop. Manually refresh the page to restart SAML authentication flow.');
return '';
}
state.setLoginPending();
provider.login();
return '';
},
};
const provider = buildSamlFlow(config);
const state = buildSamlState();
return {
async authenticate() {
if (provider.handshakeTokenAvailable) {
state.removeLoginPending();
return await provider.exchangeHandshakeToken();
}
if (state.isLoginPending) {
state.removeLoginPending();
console.warn("No handshake token found in url. Skipping redirect to avoid an infinite loop. Manually refresh the page to restart SAML authentication flow.");
return "";
}
state.setLoginPending();
provider.login();
return "";
}
};
}
exports.buildSamlClient = buildSamlClient;
{
"name": "@coveo/auth",
"private": false,
"version": "1.1.2",
"version": "1.1.3",
"description": "Functions to help authenticate with the Coveo platform.",
"main": "dist/auth.js",
"module": "dist/auth.esm.js",
"main": "./dist/auth.js",
"module": "./dist/auth.esm.js",
"browser": {
"./dist/auth.esm.js": "./dist/auth.esm.js"
},
"types": "./dist/definitions/auth.d.ts",
"files": [
"dist/"
],
"scripts": {
"build": "npm run typedefinitions & rollup -c",
"build": "npm run typedefinitions & node esbuild.js",
"test": "jest",

@@ -34,8 +40,5 @@ "test:watch": "jest --watch --colors --no-cache --silent=false",

"devDependencies": {
"@rollup/plugin-typescript": "^8.3.0",
"@types/jest": "^27.0.3",
"jest": "^27.3.0",
"rimraf": "^3.0.2",
"rollup": "^2.60.1",
"rollup-plugin-license": "^2.6.0",
"ts-jest": "^27.0.7",

@@ -42,0 +45,0 @@ "vite": "^2.6.14"

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