Socket
Socket
Sign inDemoInstall

@sphereon/ms-authenticator

Package Overview
Dependencies
Maintainers
4
Versions
247
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sphereon/ms-authenticator - npm Package Compare versions

Comparing version 0.9.1-unstable.17 to 0.9.1-unstable.27

4

dist/authenticators/index.d.ts

@@ -1,2 +0,2 @@

export * from './MsAuthenticator';
//# sourceMappingURL=index.d.ts.map
export * from './MsAuthenticator'
//# sourceMappingURL=index.d.ts.map

@@ -1,18 +0,29 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./MsAuthenticator"), exports);
//# sourceMappingURL=index.js.map
'use strict'
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k
var desc = Object.getOwnPropertyDescriptor(m, k)
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = {
enumerable: true,
get: function () {
return m[k]
},
}
}
Object.defineProperty(o, k2, desc)
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k
o[k2] = m[k]
})
var __exportStar =
(this && this.__exportStar) ||
function (m, exports) {
for (var p in m) if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
}
Object.defineProperty(exports, '__esModule', { value: true })
__exportStar(require('./MsAuthenticator'), exports)
//# sourceMappingURL=index.js.map

@@ -1,5 +0,5 @@

import { IMsAuthenticationClientCredentialArgs, IMsAuthenticationUsernamePasswordArgs } from '../index';
export declare const MS_IDENTITY_HOST_NAME_NONE_EU = "https://beta.did.msidentity.com/v1.0/";
export declare const MS_IDENTITY_HOST_NAME_EU = "https://beta.eu.did.msidentity.com/v1.0/";
export declare function checkMsIdentityHostname(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string>;
import { IMsAuthenticationClientCredentialArgs, IMsAuthenticationUsernamePasswordArgs } from '../index'
export declare const MS_IDENTITY_HOST_NAME_NONE_EU = 'https://beta.did.msidentity.com/v1.0/'
export declare const MS_IDENTITY_HOST_NAME_EU = 'https://beta.eu.did.msidentity.com/v1.0/'
export declare function checkMsIdentityHostname(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string>
/**

@@ -15,3 +15,3 @@ * necessary fields are:

*/
export declare function ClientCredentialAuthenticator(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string>;
export declare function ClientCredentialAuthenticator(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string>
/**

@@ -22,3 +22,3 @@ * Logs in with provided authenticationArgs and returns access token

*/
export declare function UsernamePasswordAuthenticator(authenticationArgs: IMsAuthenticationUsernamePasswordArgs): Promise<string>;
//# sourceMappingURL=MsAuthenticator.d.ts.map
export declare function UsernamePasswordAuthenticator(authenticationArgs: IMsAuthenticationUsernamePasswordArgs): Promise<string>
//# sourceMappingURL=MsAuthenticator.d.ts.map

@@ -1,50 +0,79 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
'use strict'
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UsernamePasswordAuthenticator = exports.ClientCredentialAuthenticator = exports.checkMsIdentityHostname = exports.MS_IDENTITY_HOST_NAME_EU = exports.MS_IDENTITY_HOST_NAME_NONE_EU = void 0;
const msal_node_1 = require("@azure/msal-node");
const cross_fetch_1 = require("cross-fetch");
const EU = 'EU';
const HTTP_METHOD_GET = 'GET';
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())
})
}
Object.defineProperty(exports, '__esModule', { value: true })
exports.UsernamePasswordAuthenticator =
exports.ClientCredentialAuthenticator =
exports.checkMsIdentityHostname =
exports.MS_IDENTITY_HOST_NAME_EU =
exports.MS_IDENTITY_HOST_NAME_NONE_EU =
void 0
const msal_node_1 = require('@azure/msal-node')
const cross_fetch_1 = require('cross-fetch')
const EU = 'EU'
const HTTP_METHOD_GET = 'GET'
// Event though there are many regions, MS has only 2 identity host names (EU and NONE_EU)
// https://docs.microsoft.com/en-us/azure/active-directory/verifiable-credentials/whats-new#are-there-any-changes-to-the-way-that-we-use-the-request-api-as-a-result-of-this-move
exports.MS_IDENTITY_HOST_NAME_NONE_EU = 'https://beta.did.msidentity.com/v1.0/';
exports.MS_IDENTITY_HOST_NAME_EU = 'https://beta.eu.did.msidentity.com/v1.0/';
const MS_LOGIN_PREFIX = 'https://login.microsoftonline.com/';
const MS_LOGIN_OPENID_CONFIG_POSTFIX = '/v2.0/.well-known/openid-configuration';
const MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE = '3db474b9-6a0c-4840-96ac-1fceb342124f/.default';
const ERROR_CREDENTIAL_MANIFEST_REGION = `Error in config file. CredentialManifest URL configured for wrong tenant region. Should start with:`;
const ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT = 'Could not acquire credentials to access your Azure Key Vault:\n';
const ERROR_FAILED_AUTHENTICATION = 'failed to authenticate: ';
exports.MS_IDENTITY_HOST_NAME_NONE_EU = 'https://beta.did.msidentity.com/v1.0/'
exports.MS_IDENTITY_HOST_NAME_EU = 'https://beta.eu.did.msidentity.com/v1.0/'
const MS_LOGIN_PREFIX = 'https://login.microsoftonline.com/'
const MS_LOGIN_OPENID_CONFIG_POSTFIX = '/v2.0/.well-known/openid-configuration'
const MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE = '3db474b9-6a0c-4840-96ac-1fceb342124f/.default'
const ERROR_CREDENTIAL_MANIFEST_REGION = `Error in config file. CredentialManifest URL configured for wrong tenant region. Should start with:`
const ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT = 'Could not acquire credentials to access your Azure Key Vault:\n'
const ERROR_FAILED_AUTHENTICATION = 'failed to authenticate: '
function getClientRegion(azTenantId) {
return __awaiter(this, void 0, void 0, function* () {
let region = EU;
yield (0, cross_fetch_1.fetch)(MS_LOGIN_PREFIX + azTenantId + MS_LOGIN_OPENID_CONFIG_POSTFIX, { method: HTTP_METHOD_GET })
.then((res) => res.json())
.then((resp) => __awaiter(this, void 0, void 0, function* () {
region = resp.tenant_region_scope;
}));
return region;
});
return __awaiter(this, void 0, void 0, function* () {
let region = EU
yield (0, cross_fetch_1.fetch)(MS_LOGIN_PREFIX + azTenantId + MS_LOGIN_OPENID_CONFIG_POSTFIX, { method: HTTP_METHOD_GET })
.then((res) => res.json())
.then((resp) =>
__awaiter(this, void 0, void 0, function* () {
region = resp.tenant_region_scope
})
)
return region
})
}
function checkMsIdentityHostname(authenticationArgs) {
return __awaiter(this, void 0, void 0, function* () {
const region = authenticationArgs.region ? authenticationArgs.region : yield getClientRegion(authenticationArgs.azTenantId);
const msIdentityHostName = region === EU ? exports.MS_IDENTITY_HOST_NAME_EU : exports.MS_IDENTITY_HOST_NAME_NONE_EU;
// Check that the Credential Manifest URL is in the same tenant Region and throw an error if it's not
if (!authenticationArgs.credentialManifestUrl.startsWith(msIdentityHostName)) {
throw new Error(ERROR_CREDENTIAL_MANIFEST_REGION + msIdentityHostName);
}
return msIdentityHostName;
});
return __awaiter(this, void 0, void 0, function* () {
const region = authenticationArgs.region ? authenticationArgs.region : yield getClientRegion(authenticationArgs.azTenantId)
const msIdentityHostName = region === EU ? exports.MS_IDENTITY_HOST_NAME_EU : exports.MS_IDENTITY_HOST_NAME_NONE_EU
// Check that the Credential Manifest URL is in the same tenant Region and throw an error if it's not
if (!authenticationArgs.credentialManifestUrl.startsWith(msIdentityHostName)) {
throw new Error(ERROR_CREDENTIAL_MANIFEST_REGION + msIdentityHostName)
}
return msIdentityHostName
})
}
exports.checkMsIdentityHostname = checkMsIdentityHostname;
exports.checkMsIdentityHostname = checkMsIdentityHostname
/**

@@ -61,38 +90,37 @@ * necessary fields are:

function ClientCredentialAuthenticator(authenticationArgs) {
return __awaiter(this, void 0, void 0, function* () {
const msalConfig = {
auth: {
clientId: authenticationArgs.azClientId,
authority: authenticationArgs.authority ? authenticationArgs.authority : MS_LOGIN_PREFIX + authenticationArgs.azTenantId,
clientSecret: authenticationArgs.azClientSecret,
},
system: {
loggerOptions: {
piiLoggingEnabled: authenticationArgs.piiLoggingEnabled ? authenticationArgs.piiLoggingEnabled : false,
logLevel: authenticationArgs.logLevel ? authenticationArgs.logLevel : msal_node_1.LogLevel.Verbose,
},
},
};
const cca = new msal_node_1.ConfidentialClientApplication(msalConfig);
const msalClientCredentialRequest = {
scopes: authenticationArgs.scopes ? authenticationArgs.scopes : [MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE],
skipCache: authenticationArgs.skipCache ? authenticationArgs.skipCache : false,
};
checkMsIdentityHostname(authenticationArgs);
// get the Access Token
try {
const result = yield cca.acquireTokenByClientCredential(msalClientCredentialRequest);
if (result && result.accessToken) {
return result.accessToken;
}
}
catch (err) {
throw {
error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT + err,
};
}
return '';
});
return __awaiter(this, void 0, void 0, function* () {
const msalConfig = {
auth: {
clientId: authenticationArgs.azClientId,
authority: authenticationArgs.authority ? authenticationArgs.authority : MS_LOGIN_PREFIX + authenticationArgs.azTenantId,
clientSecret: authenticationArgs.azClientSecret,
},
system: {
loggerOptions: {
piiLoggingEnabled: authenticationArgs.piiLoggingEnabled ? authenticationArgs.piiLoggingEnabled : false,
logLevel: authenticationArgs.logLevel ? authenticationArgs.logLevel : msal_node_1.LogLevel.Verbose,
},
},
}
const cca = new msal_node_1.ConfidentialClientApplication(msalConfig)
const msalClientCredentialRequest = {
scopes: authenticationArgs.scopes ? authenticationArgs.scopes : [MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE],
skipCache: authenticationArgs.skipCache ? authenticationArgs.skipCache : false,
}
checkMsIdentityHostname(authenticationArgs)
// get the Access Token
try {
const result = yield cca.acquireTokenByClientCredential(msalClientCredentialRequest)
if (result && result.accessToken) {
return result.accessToken
}
} catch (err) {
throw {
error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT + err,
}
}
return ''
})
}
exports.ClientCredentialAuthenticator = ClientCredentialAuthenticator;
exports.ClientCredentialAuthenticator = ClientCredentialAuthenticator
/**

@@ -104,21 +132,21 @@ * Logs in with provided authenticationArgs and returns access token

function UsernamePasswordAuthenticator(authenticationArgs) {
return __awaiter(this, void 0, void 0, function* () {
const msalConfig = {
auth: {
clientId: authenticationArgs.azClientId,
authority: authenticationArgs.authority ? authenticationArgs.authority : MS_LOGIN_PREFIX + authenticationArgs.azTenantId,
},
};
const pca = new msal_node_1.PublicClientApplication(msalConfig);
return yield pca
.acquireTokenByUsernamePassword(authenticationArgs)
.then((response) => {
return response;
})
.catch((error) => {
throw new Error(ERROR_FAILED_AUTHENTICATION + error);
});
});
return __awaiter(this, void 0, void 0, function* () {
const msalConfig = {
auth: {
clientId: authenticationArgs.azClientId,
authority: authenticationArgs.authority ? authenticationArgs.authority : MS_LOGIN_PREFIX + authenticationArgs.azTenantId,
},
}
const pca = new msal_node_1.PublicClientApplication(msalConfig)
return yield pca
.acquireTokenByUsernamePassword(authenticationArgs)
.then((response) => {
return response
})
.catch((error) => {
throw new Error(ERROR_FAILED_AUTHENTICATION + error)
})
})
}
exports.UsernamePasswordAuthenticator = UsernamePasswordAuthenticator;
//# sourceMappingURL=MsAuthenticator.js.map
exports.UsernamePasswordAuthenticator = UsernamePasswordAuthenticator
//# sourceMappingURL=MsAuthenticator.js.map

@@ -1,3 +0,3 @@

export * from './authenticators';
export * from './types';
//# sourceMappingURL=index.d.ts.map
export * from './authenticators'
export * from './types'
//# sourceMappingURL=index.d.ts.map

@@ -1,19 +0,30 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./authenticators"), exports);
__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map
'use strict'
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k
var desc = Object.getOwnPropertyDescriptor(m, k)
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = {
enumerable: true,
get: function () {
return m[k]
},
}
}
Object.defineProperty(o, k2, desc)
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k
o[k2] = m[k]
})
var __exportStar =
(this && this.__exportStar) ||
function (m, exports) {
for (var p in m) if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
}
Object.defineProperty(exports, '__esModule', { value: true })
__exportStar(require('./authenticators'), exports)
__exportStar(require('./types'), exports)
//# sourceMappingURL=index.js.map

@@ -1,3 +0,3 @@

import { IAgentContext } from '@veramo/core';
import { LogLevel } from '@azure/msal-node';
import { IAgentContext } from '@veramo/core'
import { LogLevel } from '@azure/msal-node'
/**

@@ -25,12 +25,12 @@ * azClientId: clientId of the application you're trying to login

export interface IMsAuthenticationClientCredentialArgs {
azClientId: string;
azTenantId: string;
azClientSecret: string;
credentialManifestUrl: string;
authority?: string;
region?: string;
scopes?: string[];
skipCache?: boolean;
piiLoggingEnabled?: boolean;
logLevel?: LogLevel;
azClientId: string
azTenantId: string
azClientSecret: string
credentialManifestUrl: string
authority?: string
region?: string
scopes?: string[]
skipCache?: boolean
piiLoggingEnabled?: boolean
logLevel?: LogLevel
}

@@ -48,11 +48,11 @@ /**

export interface IMsAuthenticationUsernamePasswordArgs {
azClientId: string;
azTenantId: string;
password: string;
scopes: string[];
username: string;
authority?: string;
azClientId: string
azTenantId: string
password: string
scopes: string[]
username: string
authority?: string
}
export type IRequiredContext = IAgentContext<Record<string, never>>;
export type IMsAuthenticationResponse = String;
//# sourceMappingURL=IMsAuthenticator.d.ts.map
export type IRequiredContext = IAgentContext<Record<string, never>>
export type IMsAuthenticationResponse = String
//# sourceMappingURL=IMsAuthenticator.d.ts.map

@@ -1,3 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IMsAuthenticator.js.map
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
//# sourceMappingURL=IMsAuthenticator.js.map

@@ -1,2 +0,2 @@

export * from './IMsAuthenticator';
//# sourceMappingURL=index.d.ts.map
export * from './IMsAuthenticator'
//# sourceMappingURL=index.d.ts.map

@@ -1,18 +0,29 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./IMsAuthenticator"), exports);
//# sourceMappingURL=index.js.map
'use strict'
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k
var desc = Object.getOwnPropertyDescriptor(m, k)
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = {
enumerable: true,
get: function () {
return m[k]
},
}
}
Object.defineProperty(o, k2, desc)
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k
o[k2] = m[k]
})
var __exportStar =
(this && this.__exportStar) ||
function (m, exports) {
for (var p in m) if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
}
Object.defineProperty(exports, '__esModule', { value: true })
__exportStar(require('./IMsAuthenticator'), exports)
//# sourceMappingURL=index.js.map
{
"name": "@sphereon/ms-authenticator",
"version": "0.9.1-unstable.17+9f929cb",
"version": "0.9.1-unstable.27+f588994",
"source": "src/index.ts",

@@ -11,4 +11,4 @@ "main": "dist/index.js",

"dependencies": {
"@azure/msal-common": "^7.0.0",
"@azure/msal-node": "^1.10.0",
"@azure/msal-common": "^11.0.0",
"@azure/msal-node": "^1.16.0",
"@veramo/core": "4.2.0",

@@ -22,4 +22,3 @@ "cross-fetch": "^3.1.5"

"prettier": "^2.4.1",
"ts-jest": "^27.0.7",
"typescript": "^4.6.4"
"ts-jest": "^27.0.7"
},

@@ -47,3 +46,3 @@ "files": [

],
"gitHead": "9f929cb88baf569a1b51d699d1cd2456c5d03255"
"gitHead": "f588994f2aad4f6e7554a3449df78a0816ee063a"
}

@@ -0,0 +0,0 @@ <!--suppress HtmlDeprecatedAttribute -->

export * from './MsAuthenticator'

@@ -0,0 +0,0 @@ import { ConfidentialClientApplication, LogLevel, PublicClientApplication, UsernamePasswordRequest } from '@azure/msal-node'

export * from './authenticators'
export * from './types'

@@ -0,0 +0,0 @@ import { IAgentContext } from '@veramo/core'

export * from './IMsAuthenticator'

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