@sphereon/ssi-sdk.ms-authenticator 0.33.1-next.3 → 0.33.1-next.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ MS_DID_ENDPOINT_EU: () => MS_DID_ENDPOINT_EU,
35
+ MS_DID_ENDPOINT_NON_EU: () => MS_DID_ENDPOINT_NON_EU,
36
+ UsernamePasswordAuthenticator: () => UsernamePasswordAuthenticator,
37
+ assertEntraCredentialManifestUrlInCorrectRegion: () => assertEntraCredentialManifestUrlInCorrectRegion,
38
+ determineMSAuthId: () => determineMSAuthId,
39
+ getEntraDIDEndpoint: () => getEntraDIDEndpoint,
40
+ getMSClientCredentialAccessToken: () => getMSClientCredentialAccessToken,
41
+ getMSOpenIDClientRegion: () => getMSOpenIDClientRegion,
42
+ newMSClientCredentialAuthenticator: () => newMSClientCredentialAuthenticator
43
+ });
44
+ module.exports = __toCommonJS(index_exports);
45
+
46
+ // src/authenticators/MsAuthenticator.ts
47
+ var import_msal_node = require("@azure/msal-node");
48
+ var import_cross_fetch = require("cross-fetch");
49
+ var import_object_hash = __toESM(require("object-hash"), 1);
50
+ var EU = "EU";
51
+ var HTTP_METHOD_GET = "GET";
52
+ var MS_DID_ENDPOINT_NON_EU = "https://beta.did.msidentity.com/v1.0/";
53
+ var MS_DID_ENDPOINT_EU = "https://beta.eu.did.msidentity.com/v1.0/";
54
+ var MS_LOGIN_PREFIX = "https://login.microsoftonline.com/";
55
+ var MS_LOGIN_OPENID_CONFIG_POSTFIX = "/v2.0/.well-known/openid-configuration";
56
+ var MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE = "3db474b9-6a0c-4840-96ac-1fceb342124f/.default";
57
+ var ERROR_CREDENTIAL_MANIFEST_REGION = `Error in config file. CredentialManifest URL configured for wrong tenant region. Should start with:`;
58
+ var ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT = "Could not acquire verifiableCredentials to access your Azure Key Vault:\n";
59
+ var ERROR_FAILED_AUTHENTICATION = "failed to authenticate: ";
60
+ async function getMSOpenIDClientRegion(azTenantId) {
61
+ return (0, import_cross_fetch.fetch)(MS_LOGIN_PREFIX + azTenantId + MS_LOGIN_OPENID_CONFIG_POSTFIX, {
62
+ method: HTTP_METHOD_GET
63
+ }).then((res) => res.json()).then(async (resp) => {
64
+ return resp.tenant_region_scope ?? EU;
65
+ });
66
+ }
67
+ __name(getMSOpenIDClientRegion, "getMSOpenIDClientRegion");
68
+ async function getEntraDIDEndpoint(opts) {
69
+ const region = opts?.region ?? await getMSOpenIDClientRegion(opts.azTenantId);
70
+ return region === EU ? MS_DID_ENDPOINT_EU : MS_DID_ENDPOINT_NON_EU;
71
+ }
72
+ __name(getEntraDIDEndpoint, "getEntraDIDEndpoint");
73
+ async function assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs) {
74
+ const msDIDEndpoint = await getEntraDIDEndpoint(authenticationArgs);
75
+ if (!authenticationArgs.credentialManifestUrl?.startsWith(msDIDEndpoint)) {
76
+ throw new Error(ERROR_CREDENTIAL_MANIFEST_REGION + msDIDEndpoint + `. value: ${authenticationArgs.credentialManifestUrl}`);
77
+ }
78
+ return msDIDEndpoint;
79
+ }
80
+ __name(assertEntraCredentialManifestUrlInCorrectRegion, "assertEntraCredentialManifestUrlInCorrectRegion");
81
+ async function getMSClientCredentialAccessToken(authenticationArgs, opts) {
82
+ const confidentialClient = opts?.confidentialClient ?? await newMSClientCredentialAuthenticator(authenticationArgs).then((cca) => cca.confidentialClient);
83
+ if (!confidentialClient) {
84
+ throw Error("No Credential Client Authenticator could be constructed");
85
+ }
86
+ if (authenticationArgs?.credentialManifestUrl) {
87
+ await assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs);
88
+ }
89
+ const msalClientCredentialRequest = {
90
+ scopes: authenticationArgs.scopes ?? (authenticationArgs?.credentialManifestUrl ? [
91
+ MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE
92
+ ] : []),
93
+ skipCache: authenticationArgs.skipCache ?? false
94
+ };
95
+ try {
96
+ const result = await confidentialClient.acquireTokenByClientCredential(msalClientCredentialRequest);
97
+ if (result) {
98
+ return result;
99
+ }
100
+ } catch (err) {
101
+ throw {
102
+ error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT + err
103
+ };
104
+ }
105
+ throw {
106
+ error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT
107
+ };
108
+ }
109
+ __name(getMSClientCredentialAccessToken, "getMSClientCredentialAccessToken");
110
+ async function newMSClientCredentialAuthenticator(authenticationArgs) {
111
+ const didEndpoint = authenticationArgs?.credentialManifestUrl ? await assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs) : void 0;
112
+ const auth = authOptions(authenticationArgs);
113
+ const id = (0, import_object_hash.default)(auth);
114
+ const msalConfig = {
115
+ auth,
116
+ system: {
117
+ loggerOptions: {
118
+ piiLoggingEnabled: authenticationArgs.piiLoggingEnabled ? authenticationArgs.piiLoggingEnabled : false,
119
+ logLevel: authenticationArgs.logLevel ? authenticationArgs.logLevel : import_msal_node.LogLevel.Verbose
120
+ }
121
+ }
122
+ };
123
+ const confidentialClientApp = new import_msal_node.ConfidentialClientApplication(msalConfig);
124
+ return {
125
+ confidentialClient: confidentialClientApp,
126
+ msalConfig,
127
+ authenticationArgs,
128
+ didEndpoint,
129
+ id
130
+ };
131
+ }
132
+ __name(newMSClientCredentialAuthenticator, "newMSClientCredentialAuthenticator");
133
+ async function UsernamePasswordAuthenticator(authenticationArgs) {
134
+ const msalConfig = {
135
+ auth: authOptions(authenticationArgs)
136
+ };
137
+ const pca = new import_msal_node.PublicClientApplication(msalConfig);
138
+ return await pca.acquireTokenByUsernamePassword(authenticationArgs).then((response) => {
139
+ return response;
140
+ }).catch((error) => {
141
+ throw new Error(ERROR_FAILED_AUTHENTICATION + error);
142
+ });
143
+ }
144
+ __name(UsernamePasswordAuthenticator, "UsernamePasswordAuthenticator");
145
+ function authOptions(authenticationArgs) {
146
+ return {
147
+ clientId: authenticationArgs.azClientId,
148
+ authority: authenticationArgs.authority ? authenticationArgs.authority : MS_LOGIN_PREFIX + authenticationArgs.azTenantId,
149
+ ...authenticationArgs && "azClientSecret" in authenticationArgs && {
150
+ clientSecret: authenticationArgs.azClientSecret
151
+ }
152
+ };
153
+ }
154
+ __name(authOptions, "authOptions");
155
+ function determineMSAuthId(authenticationArgs) {
156
+ return (0, import_object_hash.default)(authOptions(authenticationArgs));
157
+ }
158
+ __name(determineMSAuthId, "determineMSAuthId");
159
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/authenticators/MsAuthenticator.ts"],"sourcesContent":["export * from './authenticators'\nexport * from './types'\n","import {\n AuthenticationResult,\n ConfidentialClientApplication,\n Configuration,\n LogLevel,\n NodeAuthOptions,\n PublicClientApplication,\n UsernamePasswordRequest,\n} from '@azure/msal-node'\nimport { fetch } from 'cross-fetch'\nimport { IMSClientCredentialAuthInfo, IMsAuthenticationClientCredentialArgs, IMsAuthenticationUsernamePasswordArgs } from '../index'\n\nimport hash from 'object-hash'\n\nconst EU = 'EU'\n\nconst HTTP_METHOD_GET = 'GET'\n\n// Event though there are many regions, MS has only 2 DID identity host names (EU and NON_EU)\n// 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\nexport const MS_DID_ENDPOINT_NON_EU = 'https://beta.did.msidentity.com/v1.0/'\nexport const MS_DID_ENDPOINT_EU = 'https://beta.eu.did.msidentity.com/v1.0/'\nconst MS_LOGIN_PREFIX = 'https://login.microsoftonline.com/'\nconst MS_LOGIN_OPENID_CONFIG_POSTFIX = '/v2.0/.well-known/openid-configuration'\nconst MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE = '3db474b9-6a0c-4840-96ac-1fceb342124f/.default'\n\nconst ERROR_CREDENTIAL_MANIFEST_REGION = `Error in config file. CredentialManifest URL configured for wrong tenant region. Should start with:`\nconst ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT = 'Could not acquire verifiableCredentials to access your Azure Key Vault:\\n'\nconst ERROR_FAILED_AUTHENTICATION = 'failed to authenticate: '\n\n// todo: This is a pretty heavy operation. Getting all the OIDC discovery data from a fetch only to return the region. Probably wise to add some caching and refactor so we can do more with the other OIDC info as well\nexport async function getMSOpenIDClientRegion(azTenantId: string): Promise<string> {\n return fetch(MS_LOGIN_PREFIX + azTenantId + MS_LOGIN_OPENID_CONFIG_POSTFIX, { method: HTTP_METHOD_GET })\n .then((res) => res.json())\n .then(async (resp) => {\n return resp.tenant_region_scope ?? EU\n })\n}\n\nexport async function getEntraDIDEndpoint(opts: { region?: string; azTenantId: string }) {\n const region = opts?.region ?? (await getMSOpenIDClientRegion(opts.azTenantId))\n return region === EU ? MS_DID_ENDPOINT_EU : MS_DID_ENDPOINT_NON_EU\n}\n\nexport async function assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string> {\n const msDIDEndpoint = await getEntraDIDEndpoint(authenticationArgs)\n // Check that the Credential Manifest URL is in the same tenant Region and throw an error if it's not\n if (!authenticationArgs.credentialManifestUrl?.startsWith(msDIDEndpoint)) {\n throw new Error(ERROR_CREDENTIAL_MANIFEST_REGION + msDIDEndpoint + `. value: ${authenticationArgs.credentialManifestUrl}`)\n }\n return msDIDEndpoint\n}\n\n/**\n * necessary fields are:\n * azClientId: clientId of the application you're trying to login\n * azClientSecret: secret of the application you're trying to login\n * azTenantId: your MS Azure tenantId\n * optional fields:\n * credentialManifest: address of your credential manifest. usually in following format:\n * https://beta.eu.did.msidentity.com/v1.0/<tenant_id>/verifiableCredential/contracts/<verifiable_credential_schema>\n * @param authenticationArgs\n * @constructor\n */\nexport async function getMSClientCredentialAccessToken(\n authenticationArgs: IMsAuthenticationClientCredentialArgs,\n opts?: {\n confidentialClient?: ConfidentialClientApplication\n },\n): Promise<AuthenticationResult> {\n const confidentialClient =\n opts?.confidentialClient ?? (await newMSClientCredentialAuthenticator(authenticationArgs).then((cca) => cca.confidentialClient))\n if (!confidentialClient) {\n throw Error('No Credential Client Authenticator could be constructed')\n }\n if (authenticationArgs?.credentialManifestUrl) {\n await assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs)\n }\n\n const msalClientCredentialRequest = {\n scopes: authenticationArgs.scopes ?? (authenticationArgs?.credentialManifestUrl ? [MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE] : []),\n skipCache: authenticationArgs.skipCache ?? false,\n }\n\n // get the Access Token\n try {\n const result = await confidentialClient.acquireTokenByClientCredential(msalClientCredentialRequest)\n if (result) {\n return result\n }\n } catch (err) {\n throw {\n error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT + err,\n }\n }\n throw {\n error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT,\n }\n}\n\nexport async function newMSClientCredentialAuthenticator(\n authenticationArgs: IMsAuthenticationClientCredentialArgs,\n): Promise<IMSClientCredentialAuthInfo> {\n const didEndpoint = authenticationArgs?.credentialManifestUrl\n ? await assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs)\n : undefined\n const auth = authOptions(authenticationArgs)\n const id = hash(auth)\n const msalConfig: Configuration = {\n auth,\n system: {\n loggerOptions: {\n piiLoggingEnabled: authenticationArgs.piiLoggingEnabled ? authenticationArgs.piiLoggingEnabled : false,\n logLevel: authenticationArgs.logLevel ? authenticationArgs.logLevel : LogLevel.Verbose,\n },\n },\n }\n const confidentialClientApp = new ConfidentialClientApplication(msalConfig)\n\n return { confidentialClient: confidentialClientApp, msalConfig, authenticationArgs, didEndpoint, id }\n}\n\n/**\n * Logs in with provided authenticationArgs and returns access token\n * @param authenticationArgs\n * @constructor\n */\nexport async function UsernamePasswordAuthenticator(authenticationArgs: IMsAuthenticationUsernamePasswordArgs): Promise<string> {\n const msalConfig = {\n auth: authOptions(authenticationArgs),\n }\n const pca = new PublicClientApplication(msalConfig)\n return await pca\n .acquireTokenByUsernamePassword(authenticationArgs as UsernamePasswordRequest)\n .then((response: any) => {\n return response\n })\n .catch((error: any) => {\n throw new Error(ERROR_FAILED_AUTHENTICATION + error)\n })\n}\n\nfunction authOptions(authenticationArgs: IMsAuthenticationClientCredentialArgs | IMsAuthenticationUsernamePasswordArgs): NodeAuthOptions {\n return {\n clientId: authenticationArgs.azClientId,\n authority: authenticationArgs.authority ? authenticationArgs.authority : MS_LOGIN_PREFIX + authenticationArgs.azTenantId,\n ...(authenticationArgs && 'azClientSecret' in authenticationArgs && { clientSecret: authenticationArgs.azClientSecret }),\n }\n}\n\nexport function determineMSAuthId(authenticationArgs: IMsAuthenticationClientCredentialArgs | IMsAuthenticationUsernamePasswordArgs): string {\n return hash(authOptions(authenticationArgs))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;ACAA,uBAQO;AACP,yBAAsB;AAGtB,yBAAiB;AAEjB,IAAMA,KAAK;AAEX,IAAMC,kBAAkB;AAIjB,IAAMC,yBAAyB;AAC/B,IAAMC,qBAAqB;AAClC,IAAMC,kBAAkB;AACxB,IAAMC,iCAAiC;AACvC,IAAMC,qCAAqC;AAE3C,IAAMC,mCAAmC;AACzC,IAAMC,wCAAwC;AAC9C,IAAMC,8BAA8B;AAGpC,eAAsBC,wBAAwBC,YAAkB;AAC9D,aAAOC,0BAAMR,kBAAkBO,aAAaN,gCAAgC;IAAEQ,QAAQZ;EAAgB,CAAA,EACnGa,KAAK,CAACC,QAAQA,IAAIC,KAAI,CAAA,EACtBF,KAAK,OAAOG,SAAAA;AACX,WAAOA,KAAKC,uBAAuBlB;EACrC,CAAA;AACJ;AANsBU;AAQtB,eAAsBS,oBAAoBC,MAA6C;AACrF,QAAMC,SAASD,MAAMC,UAAW,MAAMX,wBAAwBU,KAAKT,UAAU;AAC7E,SAAOU,WAAWrB,KAAKG,qBAAqBD;AAC9C;AAHsBiB;AAKtB,eAAsBG,gDAAgDC,oBAAyD;AAC7H,QAAMC,gBAAgB,MAAML,oBAAoBI,kBAAAA;AAEhD,MAAI,CAACA,mBAAmBE,uBAAuBC,WAAWF,aAAAA,GAAgB;AACxE,UAAM,IAAIG,MAAMpB,mCAAmCiB,gBAAgB,YAAYD,mBAAmBE,qBAAqB,EAAE;EAC3H;AACA,SAAOD;AACT;AAPsBF;AAoBtB,eAAsBM,iCACpBL,oBACAH,MAEC;A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,MAAMU,IACVE,+BAA+BlC,kBAAAA,EAC/BT,KAAK,CAAC4C,aAAAA;AACL,WAAOA;EACT,CAAA,EACCC,MAAM,CAACrB,UAAAA;AACN,UAAM,IAAIX,MAAMlB,8BAA8B6B,KAAAA;EAChD,CAAA;AACJ;AAbsBgB;AAetB,SAASZ,YAAYnB,oBAAiG;AACpH,SAAO;IACLqC,UAAUrC,mBAAmBsC;IAC7BC,WAAWvC,mBAAmBuC,YAAYvC,mBAAmBuC,YAAY1D,kBAAkBmB,mBAAmBZ;IAC9G,GAAIY,sBAAsB,oBAAoBA,sBAAsB;MAAEwC,cAAcxC,mBAAmByC;IAAe;EACxH;AACF;AANStB;AAQF,SAASuB,kBAAkB1C,oBAAiG;AACjI,aAAOqB,mBAAAA,SAAKF,YAAYnB,kBAAAA,CAAAA;AAC1B;AAFgB0C;","names":["EU","HTTP_METHOD_GET","MS_DID_ENDPOINT_NON_EU","MS_DID_ENDPOINT_EU","MS_LOGIN_PREFIX","MS_LOGIN_OPENID_CONFIG_POSTFIX","MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE","ERROR_CREDENTIAL_MANIFEST_REGION","ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT","ERROR_FAILED_AUTHENTICATION","getMSOpenIDClientRegion","azTenantId","fetch","method","then","res","json","resp","tenant_region_scope","getEntraDIDEndpoint","opts","region","assertEntraCredentialManifestUrlInCorrectRegion","authenticationArgs","msDIDEndpoint","credentialManifestUrl","startsWith","Error","getMSClientCredentialAccessToken","confidentialClient","newMSClientCredentialAuthenticator","cca","msalClientCredentialRequest","scopes","skipCache","result","acquireTokenByClientCredential","err","error","didEndpoint","undefined","auth","authOptions","id","hash","msalConfig","system","loggerOptions","piiLoggingEnabled","logLevel","LogLevel","Verbose","confidentialClientApp","ConfidentialClientApplication","UsernamePasswordAuthenticator","pca","PublicClientApplication","acquireTokenByUsernamePassword","response","catch","clientId","azClientId","authority","clientSecret","azClientSecret","determineMSAuthId"]}
@@ -1,4 +1,36 @@
1
- import { ConfidentialClientApplication, Configuration, LogLevel } from '@azure/msal-node';
1
+ import { ConfidentialClientApplication, AuthenticationResult, LogLevel, Configuration } from '@azure/msal-node';
2
+
3
+ declare const MS_DID_ENDPOINT_NON_EU = "https://beta.did.msidentity.com/v1.0/";
4
+ declare const MS_DID_ENDPOINT_EU = "https://beta.eu.did.msidentity.com/v1.0/";
5
+ declare function getMSOpenIDClientRegion(azTenantId: string): Promise<string>;
6
+ declare function getEntraDIDEndpoint(opts: {
7
+ region?: string;
8
+ azTenantId: string;
9
+ }): Promise<"https://beta.did.msidentity.com/v1.0/" | "https://beta.eu.did.msidentity.com/v1.0/">;
10
+ declare function assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string>;
11
+ /**
12
+ * necessary fields are:
13
+ * azClientId: clientId of the application you're trying to login
14
+ * azClientSecret: secret of the application you're trying to login
15
+ * azTenantId: your MS Azure tenantId
16
+ * optional fields:
17
+ * credentialManifest: address of your credential manifest. usually in following format:
18
+ * https://beta.eu.did.msidentity.com/v1.0/<tenant_id>/verifiableCredential/contracts/<verifiable_credential_schema>
19
+ * @param authenticationArgs
20
+ * @constructor
21
+ */
22
+ declare function getMSClientCredentialAccessToken(authenticationArgs: IMsAuthenticationClientCredentialArgs, opts?: {
23
+ confidentialClient?: ConfidentialClientApplication;
24
+ }): Promise<AuthenticationResult>;
25
+ declare function newMSClientCredentialAuthenticator(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<IMSClientCredentialAuthInfo>;
26
+ /**
27
+ * Logs in with provided authenticationArgs and returns access token
28
+ * @param authenticationArgs
29
+ * @constructor
30
+ */
31
+ declare function UsernamePasswordAuthenticator(authenticationArgs: IMsAuthenticationUsernamePasswordArgs): Promise<string>;
32
+ declare function determineMSAuthId(authenticationArgs: IMsAuthenticationClientCredentialArgs | IMsAuthenticationUsernamePasswordArgs): string;
33
+
2
34
  /**
3
35
  * azClientId: clientId of the application you're trying to login
4
36
  * azClientSecret: secret of the application you're trying to login
@@ -20,7 +52,7 @@ import { ConfidentialClientApplication, Configuration, LogLevel } from '@azure/m
20
52
  * Trace = 4
21
53
  * if not provided defaults to LogLevel.Verbose
22
54
  */
23
- export interface IMsAuthenticationClientCredentialArgs {
55
+ interface IMsAuthenticationClientCredentialArgs {
24
56
  azClientId: string;
25
57
  azTenantId: string;
26
58
  azClientSecret: string;
@@ -42,7 +74,7 @@ export interface IMsAuthenticationClientCredentialArgs {
42
74
  * - Tenanted: https://login.microsoftonline.com/{tenant}/, where {tenant} is either the GUID representing the tenant ID or a domain name associated with the tenant.
43
75
  * - Work and school accounts: https://login.microsoftonline.com/organizations/.
44
76
  */
45
- export interface IMsAuthenticationUsernamePasswordArgs {
77
+ interface IMsAuthenticationUsernamePasswordArgs {
46
78
  azClientId: string;
47
79
  azTenantId: string;
48
80
  password: string;
@@ -50,11 +82,12 @@ export interface IMsAuthenticationUsernamePasswordArgs {
50
82
  username: string;
51
83
  authority?: string;
52
84
  }
53
- export interface IMSClientCredentialAuthInfo {
85
+ interface IMSClientCredentialAuthInfo {
54
86
  id: string;
55
87
  confidentialClient: ConfidentialClientApplication;
56
88
  msalConfig: Configuration;
57
89
  authenticationArgs: IMsAuthenticationClientCredentialArgs;
58
90
  didEndpoint?: string;
59
91
  }
60
- //# sourceMappingURL=IMsAuthenticator.d.ts.map
92
+
93
+ export { type IMSClientCredentialAuthInfo, type IMsAuthenticationClientCredentialArgs, type IMsAuthenticationUsernamePasswordArgs, MS_DID_ENDPOINT_EU, MS_DID_ENDPOINT_NON_EU, UsernamePasswordAuthenticator, assertEntraCredentialManifestUrlInCorrectRegion, determineMSAuthId, getEntraDIDEndpoint, getMSClientCredentialAccessToken, getMSOpenIDClientRegion, newMSClientCredentialAuthenticator };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,93 @@
1
- export * from './authenticators';
2
- export * from './types';
3
- //# sourceMappingURL=index.d.ts.map
1
+ import { ConfidentialClientApplication, AuthenticationResult, LogLevel, Configuration } from '@azure/msal-node';
2
+
3
+ declare const MS_DID_ENDPOINT_NON_EU = "https://beta.did.msidentity.com/v1.0/";
4
+ declare const MS_DID_ENDPOINT_EU = "https://beta.eu.did.msidentity.com/v1.0/";
5
+ declare function getMSOpenIDClientRegion(azTenantId: string): Promise<string>;
6
+ declare function getEntraDIDEndpoint(opts: {
7
+ region?: string;
8
+ azTenantId: string;
9
+ }): Promise<"https://beta.did.msidentity.com/v1.0/" | "https://beta.eu.did.msidentity.com/v1.0/">;
10
+ declare function assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string>;
11
+ /**
12
+ * necessary fields are:
13
+ * azClientId: clientId of the application you're trying to login
14
+ * azClientSecret: secret of the application you're trying to login
15
+ * azTenantId: your MS Azure tenantId
16
+ * optional fields:
17
+ * credentialManifest: address of your credential manifest. usually in following format:
18
+ * https://beta.eu.did.msidentity.com/v1.0/<tenant_id>/verifiableCredential/contracts/<verifiable_credential_schema>
19
+ * @param authenticationArgs
20
+ * @constructor
21
+ */
22
+ declare function getMSClientCredentialAccessToken(authenticationArgs: IMsAuthenticationClientCredentialArgs, opts?: {
23
+ confidentialClient?: ConfidentialClientApplication;
24
+ }): Promise<AuthenticationResult>;
25
+ declare function newMSClientCredentialAuthenticator(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<IMSClientCredentialAuthInfo>;
26
+ /**
27
+ * Logs in with provided authenticationArgs and returns access token
28
+ * @param authenticationArgs
29
+ * @constructor
30
+ */
31
+ declare function UsernamePasswordAuthenticator(authenticationArgs: IMsAuthenticationUsernamePasswordArgs): Promise<string>;
32
+ declare function determineMSAuthId(authenticationArgs: IMsAuthenticationClientCredentialArgs | IMsAuthenticationUsernamePasswordArgs): string;
33
+
34
+ /**
35
+ * azClientId: clientId of the application you're trying to login
36
+ * azClientSecret: secret of the application you're trying to login
37
+ * azTenantId: your MS Azure tenantId
38
+ * credentialManifestUrl: url of your credential manifest. usually in following format:
39
+ * https://beta.eu.did.msidentity.com/v1.0/<tenant_id>/verifiableCredential/contracts/<verifiable_credential_schema>
40
+ * authority: optional. if not provided, we'll use the azClientId to create the Tenanted format if provided should be one of these two formats:
41
+ * - Tenanted: https://login.microsoftonline.com/{tenant}/, where {tenant} is either the GUID representing the tenant ID or a domain name associated with the tenant.
42
+ * - Work and school accounts: https://login.microsoftonline.com/organizations/.
43
+ * region?: if present will use the provided, if not will make a request to determine the region
44
+ * scopes?: scopes that you want to access via this authentication
45
+ * skipCache?: whether to skip cache
46
+ * piiLoggingEnabled?: if not provided defaults to false
47
+ * logLevel?: can be one of these values:
48
+ * Error = 0,
49
+ * Warning = 1,
50
+ * Info = 2,
51
+ * Verbose = 3,
52
+ * Trace = 4
53
+ * if not provided defaults to LogLevel.Verbose
54
+ */
55
+ interface IMsAuthenticationClientCredentialArgs {
56
+ azClientId: string;
57
+ azTenantId: string;
58
+ azClientSecret: string;
59
+ credentialManifestUrl?: string;
60
+ authority?: string;
61
+ region?: string;
62
+ scopes?: string[];
63
+ skipCache?: boolean;
64
+ piiLoggingEnabled?: boolean;
65
+ logLevel?: LogLevel;
66
+ }
67
+ /**
68
+ * azClientId: clientId of the application you're trying to login
69
+ * azTenantId: your MS Azure tenantId
70
+ * username: username of the user
71
+ * password: password of the user
72
+ * scopes: scopes that you want to access via this authentication
73
+ * authority: optional. if not provided, we'll use the azClientId to create the Tenanted format if provided should be one of these two formats:
74
+ * - Tenanted: https://login.microsoftonline.com/{tenant}/, where {tenant} is either the GUID representing the tenant ID or a domain name associated with the tenant.
75
+ * - Work and school accounts: https://login.microsoftonline.com/organizations/.
76
+ */
77
+ interface IMsAuthenticationUsernamePasswordArgs {
78
+ azClientId: string;
79
+ azTenantId: string;
80
+ password: string;
81
+ scopes: string[];
82
+ username: string;
83
+ authority?: string;
84
+ }
85
+ interface IMSClientCredentialAuthInfo {
86
+ id: string;
87
+ confidentialClient: ConfidentialClientApplication;
88
+ msalConfig: Configuration;
89
+ authenticationArgs: IMsAuthenticationClientCredentialArgs;
90
+ didEndpoint?: string;
91
+ }
92
+
93
+ export { type IMSClientCredentialAuthInfo, type IMsAuthenticationClientCredentialArgs, type IMsAuthenticationUsernamePasswordArgs, MS_DID_ENDPOINT_EU, MS_DID_ENDPOINT_NON_EU, UsernamePasswordAuthenticator, assertEntraCredentialManifestUrlInCorrectRegion, determineMSAuthId, getEntraDIDEndpoint, getMSClientCredentialAccessToken, getMSOpenIDClientRegion, newMSClientCredentialAuthenticator };
package/dist/index.js CHANGED
@@ -1,19 +1,128 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/authenticators/MsAuthenticator.ts
5
+ import { ConfidentialClientApplication, LogLevel, PublicClientApplication } from "@azure/msal-node";
6
+ import { fetch } from "cross-fetch";
7
+ import hash from "object-hash";
8
+ var EU = "EU";
9
+ var HTTP_METHOD_GET = "GET";
10
+ var MS_DID_ENDPOINT_NON_EU = "https://beta.did.msidentity.com/v1.0/";
11
+ var MS_DID_ENDPOINT_EU = "https://beta.eu.did.msidentity.com/v1.0/";
12
+ var MS_LOGIN_PREFIX = "https://login.microsoftonline.com/";
13
+ var MS_LOGIN_OPENID_CONFIG_POSTFIX = "/v2.0/.well-known/openid-configuration";
14
+ var MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE = "3db474b9-6a0c-4840-96ac-1fceb342124f/.default";
15
+ var ERROR_CREDENTIAL_MANIFEST_REGION = `Error in config file. CredentialManifest URL configured for wrong tenant region. Should start with:`;
16
+ var ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT = "Could not acquire verifiableCredentials to access your Azure Key Vault:\n";
17
+ var ERROR_FAILED_AUTHENTICATION = "failed to authenticate: ";
18
+ async function getMSOpenIDClientRegion(azTenantId) {
19
+ return fetch(MS_LOGIN_PREFIX + azTenantId + MS_LOGIN_OPENID_CONFIG_POSTFIX, {
20
+ method: HTTP_METHOD_GET
21
+ }).then((res) => res.json()).then(async (resp) => {
22
+ return resp.tenant_region_scope ?? EU;
23
+ });
24
+ }
25
+ __name(getMSOpenIDClientRegion, "getMSOpenIDClientRegion");
26
+ async function getEntraDIDEndpoint(opts) {
27
+ const region = opts?.region ?? await getMSOpenIDClientRegion(opts.azTenantId);
28
+ return region === EU ? MS_DID_ENDPOINT_EU : MS_DID_ENDPOINT_NON_EU;
29
+ }
30
+ __name(getEntraDIDEndpoint, "getEntraDIDEndpoint");
31
+ async function assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs) {
32
+ const msDIDEndpoint = await getEntraDIDEndpoint(authenticationArgs);
33
+ if (!authenticationArgs.credentialManifestUrl?.startsWith(msDIDEndpoint)) {
34
+ throw new Error(ERROR_CREDENTIAL_MANIFEST_REGION + msDIDEndpoint + `. value: ${authenticationArgs.credentialManifestUrl}`);
35
+ }
36
+ return msDIDEndpoint;
37
+ }
38
+ __name(assertEntraCredentialManifestUrlInCorrectRegion, "assertEntraCredentialManifestUrlInCorrectRegion");
39
+ async function getMSClientCredentialAccessToken(authenticationArgs, opts) {
40
+ const confidentialClient = opts?.confidentialClient ?? await newMSClientCredentialAuthenticator(authenticationArgs).then((cca) => cca.confidentialClient);
41
+ if (!confidentialClient) {
42
+ throw Error("No Credential Client Authenticator could be constructed");
43
+ }
44
+ if (authenticationArgs?.credentialManifestUrl) {
45
+ await assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs);
46
+ }
47
+ const msalClientCredentialRequest = {
48
+ scopes: authenticationArgs.scopes ?? (authenticationArgs?.credentialManifestUrl ? [
49
+ MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE
50
+ ] : []),
51
+ skipCache: authenticationArgs.skipCache ?? false
52
+ };
53
+ try {
54
+ const result = await confidentialClient.acquireTokenByClientCredential(msalClientCredentialRequest);
55
+ if (result) {
56
+ return result;
7
57
  }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
58
+ } catch (err) {
59
+ throw {
60
+ error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT + err
61
+ };
62
+ }
63
+ throw {
64
+ error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT
65
+ };
66
+ }
67
+ __name(getMSClientCredentialAccessToken, "getMSClientCredentialAccessToken");
68
+ async function newMSClientCredentialAuthenticator(authenticationArgs) {
69
+ const didEndpoint = authenticationArgs?.credentialManifestUrl ? await assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs) : void 0;
70
+ const auth = authOptions(authenticationArgs);
71
+ const id = hash(auth);
72
+ const msalConfig = {
73
+ auth,
74
+ system: {
75
+ loggerOptions: {
76
+ piiLoggingEnabled: authenticationArgs.piiLoggingEnabled ? authenticationArgs.piiLoggingEnabled : false,
77
+ logLevel: authenticationArgs.logLevel ? authenticationArgs.logLevel : LogLevel.Verbose
78
+ }
79
+ }
80
+ };
81
+ const confidentialClientApp = new ConfidentialClientApplication(msalConfig);
82
+ return {
83
+ confidentialClient: confidentialClientApp,
84
+ msalConfig,
85
+ authenticationArgs,
86
+ didEndpoint,
87
+ id
88
+ };
89
+ }
90
+ __name(newMSClientCredentialAuthenticator, "newMSClientCredentialAuthenticator");
91
+ async function UsernamePasswordAuthenticator(authenticationArgs) {
92
+ const msalConfig = {
93
+ auth: authOptions(authenticationArgs)
94
+ };
95
+ const pca = new PublicClientApplication(msalConfig);
96
+ return await pca.acquireTokenByUsernamePassword(authenticationArgs).then((response) => {
97
+ return response;
98
+ }).catch((error) => {
99
+ throw new Error(ERROR_FAILED_AUTHENTICATION + error);
100
+ });
101
+ }
102
+ __name(UsernamePasswordAuthenticator, "UsernamePasswordAuthenticator");
103
+ function authOptions(authenticationArgs) {
104
+ return {
105
+ clientId: authenticationArgs.azClientId,
106
+ authority: authenticationArgs.authority ? authenticationArgs.authority : MS_LOGIN_PREFIX + authenticationArgs.azTenantId,
107
+ ...authenticationArgs && "azClientSecret" in authenticationArgs && {
108
+ clientSecret: authenticationArgs.azClientSecret
109
+ }
110
+ };
111
+ }
112
+ __name(authOptions, "authOptions");
113
+ function determineMSAuthId(authenticationArgs) {
114
+ return hash(authOptions(authenticationArgs));
115
+ }
116
+ __name(determineMSAuthId, "determineMSAuthId");
117
+ export {
118
+ MS_DID_ENDPOINT_EU,
119
+ MS_DID_ENDPOINT_NON_EU,
120
+ UsernamePasswordAuthenticator,
121
+ assertEntraCredentialManifestUrlInCorrectRegion,
122
+ determineMSAuthId,
123
+ getEntraDIDEndpoint,
124
+ getMSClientCredentialAccessToken,
125
+ getMSOpenIDClientRegion,
126
+ newMSClientCredentialAuthenticator
15
127
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./authenticators"), exports);
18
- __exportStar(require("./types"), exports);
19
128
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,0CAAuB"}
1
+ {"version":3,"sources":["../src/authenticators/MsAuthenticator.ts"],"sourcesContent":["import {\n AuthenticationResult,\n ConfidentialClientApplication,\n Configuration,\n LogLevel,\n NodeAuthOptions,\n PublicClientApplication,\n UsernamePasswordRequest,\n} from '@azure/msal-node'\nimport { fetch } from 'cross-fetch'\nimport { IMSClientCredentialAuthInfo, IMsAuthenticationClientCredentialArgs, IMsAuthenticationUsernamePasswordArgs } from '../index'\n\nimport hash from 'object-hash'\n\nconst EU = 'EU'\n\nconst HTTP_METHOD_GET = 'GET'\n\n// Event though there are many regions, MS has only 2 DID identity host names (EU and NON_EU)\n// 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\nexport const MS_DID_ENDPOINT_NON_EU = 'https://beta.did.msidentity.com/v1.0/'\nexport const MS_DID_ENDPOINT_EU = 'https://beta.eu.did.msidentity.com/v1.0/'\nconst MS_LOGIN_PREFIX = 'https://login.microsoftonline.com/'\nconst MS_LOGIN_OPENID_CONFIG_POSTFIX = '/v2.0/.well-known/openid-configuration'\nconst MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE = '3db474b9-6a0c-4840-96ac-1fceb342124f/.default'\n\nconst ERROR_CREDENTIAL_MANIFEST_REGION = `Error in config file. CredentialManifest URL configured for wrong tenant region. Should start with:`\nconst ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT = 'Could not acquire verifiableCredentials to access your Azure Key Vault:\\n'\nconst ERROR_FAILED_AUTHENTICATION = 'failed to authenticate: '\n\n// todo: This is a pretty heavy operation. Getting all the OIDC discovery data from a fetch only to return the region. Probably wise to add some caching and refactor so we can do more with the other OIDC info as well\nexport async function getMSOpenIDClientRegion(azTenantId: string): Promise<string> {\n return fetch(MS_LOGIN_PREFIX + azTenantId + MS_LOGIN_OPENID_CONFIG_POSTFIX, { method: HTTP_METHOD_GET })\n .then((res) => res.json())\n .then(async (resp) => {\n return resp.tenant_region_scope ?? EU\n })\n}\n\nexport async function getEntraDIDEndpoint(opts: { region?: string; azTenantId: string }) {\n const region = opts?.region ?? (await getMSOpenIDClientRegion(opts.azTenantId))\n return region === EU ? MS_DID_ENDPOINT_EU : MS_DID_ENDPOINT_NON_EU\n}\n\nexport async function assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string> {\n const msDIDEndpoint = await getEntraDIDEndpoint(authenticationArgs)\n // Check that the Credential Manifest URL is in the same tenant Region and throw an error if it's not\n if (!authenticationArgs.credentialManifestUrl?.startsWith(msDIDEndpoint)) {\n throw new Error(ERROR_CREDENTIAL_MANIFEST_REGION + msDIDEndpoint + `. value: ${authenticationArgs.credentialManifestUrl}`)\n }\n return msDIDEndpoint\n}\n\n/**\n * necessary fields are:\n * azClientId: clientId of the application you're trying to login\n * azClientSecret: secret of the application you're trying to login\n * azTenantId: your MS Azure tenantId\n * optional fields:\n * credentialManifest: address of your credential manifest. usually in following format:\n * https://beta.eu.did.msidentity.com/v1.0/<tenant_id>/verifiableCredential/contracts/<verifiable_credential_schema>\n * @param authenticationArgs\n * @constructor\n */\nexport async function getMSClientCredentialAccessToken(\n authenticationArgs: IMsAuthenticationClientCredentialArgs,\n opts?: {\n confidentialClient?: ConfidentialClientApplication\n },\n): Promise<AuthenticationResult> {\n const confidentialClient =\n opts?.confidentialClient ?? (await newMSClientCredentialAuthenticator(authenticationArgs).then((cca) => cca.confidentialClient))\n if (!confidentialClient) {\n throw Error('No Credential Client Authenticator could be constructed')\n }\n if (authenticationArgs?.credentialManifestUrl) {\n await assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs)\n }\n\n const msalClientCredentialRequest = {\n scopes: authenticationArgs.scopes ?? (authenticationArgs?.credentialManifestUrl ? [MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE] : []),\n skipCache: authenticationArgs.skipCache ?? false,\n }\n\n // get the Access Token\n try {\n const result = await confidentialClient.acquireTokenByClientCredential(msalClientCredentialRequest)\n if (result) {\n return result\n }\n } catch (err) {\n throw {\n error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT + err,\n }\n }\n throw {\n error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT,\n }\n}\n\nexport async function newMSClientCredentialAuthenticator(\n authenticationArgs: IMsAuthenticationClientCredentialArgs,\n): Promise<IMSClientCredentialAuthInfo> {\n const didEndpoint = authenticationArgs?.credentialManifestUrl\n ? await assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs)\n : undefined\n const auth = authOptions(authenticationArgs)\n const id = hash(auth)\n const msalConfig: Configuration = {\n auth,\n system: {\n loggerOptions: {\n piiLoggingEnabled: authenticationArgs.piiLoggingEnabled ? authenticationArgs.piiLoggingEnabled : false,\n logLevel: authenticationArgs.logLevel ? authenticationArgs.logLevel : LogLevel.Verbose,\n },\n },\n }\n const confidentialClientApp = new ConfidentialClientApplication(msalConfig)\n\n return { confidentialClient: confidentialClientApp, msalConfig, authenticationArgs, didEndpoint, id }\n}\n\n/**\n * Logs in with provided authenticationArgs and returns access token\n * @param authenticationArgs\n * @constructor\n */\nexport async function UsernamePasswordAuthenticator(authenticationArgs: IMsAuthenticationUsernamePasswordArgs): Promise<string> {\n const msalConfig = {\n auth: authOptions(authenticationArgs),\n }\n const pca = new PublicClientApplication(msalConfig)\n return await pca\n .acquireTokenByUsernamePassword(authenticationArgs as UsernamePasswordRequest)\n .then((response: any) => {\n return response\n })\n .catch((error: any) => {\n throw new Error(ERROR_FAILED_AUTHENTICATION + error)\n })\n}\n\nfunction authOptions(authenticationArgs: IMsAuthenticationClientCredentialArgs | IMsAuthenticationUsernamePasswordArgs): NodeAuthOptions {\n return {\n clientId: authenticationArgs.azClientId,\n authority: authenticationArgs.authority ? authenticationArgs.authority : MS_LOGIN_PREFIX + authenticationArgs.azTenantId,\n ...(authenticationArgs && 'azClientSecret' in authenticationArgs && { clientSecret: authenticationArgs.azClientSecret }),\n }\n}\n\nexport function determineMSAuthId(authenticationArgs: IMsAuthenticationClientCredentialArgs | IMsAuthenticationUsernamePasswordArgs): string {\n return hash(authOptions(authenticationArgs))\n}\n"],"mappings":";;;;AAAA,SAEEA,+BAEAC,UAEAC,+BAEK;AACP,SAASC,aAAa;AAGtB,OAAOC,UAAU;AAEjB,IAAMC,KAAK;AAEX,IAAMC,kBAAkB;AAIjB,IAAMC,y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IAAe;EACxH;AACF;AANStB;AAQF,SAASuB,kBAAkB1C,oBAAiG;AACjI,SAAOqB,KAAKF,YAAYnB,kBAAAA,CAAAA;AAC1B;AAFgB0C;","names":["ConfidentialClientApplication","LogLevel","PublicClientApplication","fetch","hash","EU","HTTP_METHOD_GET","MS_DID_ENDPOINT_NON_EU","MS_DID_ENDPOINT_EU","MS_LOGIN_PREFIX","MS_LOGIN_OPENID_CONFIG_POSTFIX","MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE","ERROR_CREDENTIAL_MANIFEST_REGION","ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT","ERROR_FAILED_AUTHENTICATION","getMSOpenIDClientRegion","azTenantId","fetch","method","then","res","json","resp","tenant_region_scope","getEntraDIDEndpoint","opts","region","assertEntraCredentialManifestUrlInCorrectRegion","authenticationArgs","msDIDEndpoint","credentialManifestUrl","startsWith","Error","getMSClientCredentialAccessToken","confidentialClient","newMSClientCredentialAuthenticator","cca","msalClientCredentialRequest","scopes","skipCache","result","acquireTokenByClientCredential","err","error","didEndpoint","undefined","auth","authOptions","id","hash","msalConfig","system","loggerOptions","piiLoggingEnabled","logLevel","LogLevel","Verbose","confidentialClientApp","ConfidentialClientApplication","UsernamePasswordAuthenticator","pca","PublicClientApplication","acquireTokenByUsernamePassword","response","catch","clientId","azClientId","authority","clientSecret","azClientSecret","determineMSAuthId"]}
package/package.json CHANGED
@@ -1,12 +1,24 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.ms-authenticator",
3
- "version": "0.33.1-next.3+fd1a6fba",
3
+ "version": "0.33.1-next.68+b6c8b366",
4
4
  "source": "src/index.ts",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ "react-native": "./dist/index.js",
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "require": "./dist/index.cjs"
18
+ }
19
+ },
7
20
  "scripts": {
8
- "build": "tsc --build",
9
- "build:clean": "tsc --build --clean && tsc --build"
21
+ "build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json"
10
22
  },
11
23
  "dependencies": {
12
24
  "@azure/msal-common": "^13.3.3",
@@ -15,18 +27,15 @@
15
27
  "object-hash": "^3.0.0"
16
28
  },
17
29
  "devDependencies": {
18
- "@types/jest": "^27.5.2",
19
30
  "@types/object-hash": "^3.0.6",
20
- "jest": "^27.5.1",
21
- "prettier": "^2.8.8",
22
- "ts-jest": "^27.1.5"
31
+ "prettier": "^2.8.8"
23
32
  },
24
33
  "engines": {
25
34
  "node": ">= 20.0.0 < 22"
26
35
  },
27
36
  "files": [
28
- "dist/**/*",
29
- "src/**/*",
37
+ "dist",
38
+ "src",
30
39
  "README.md",
31
40
  "plugin.schema.json",
32
41
  "LICENSE"
@@ -46,6 +55,5 @@
46
55
  "SSI",
47
56
  "Veramo"
48
57
  ],
49
- "nx": {},
50
- "gitHead": "fd1a6fba306a83a73ff7c531db87fa207dbf436d"
58
+ "gitHead": "b6c8b36636fa3777494f55860d6a75f2e5a5611e"
51
59
  }
@@ -0,0 +1,33 @@
1
+ import * as process from 'process'
2
+ import { AuthenticationResult } from '@azure/msal-node'
3
+ import { getMSClientCredentialAccessToken, UsernamePasswordAuthenticator } from '../index'
4
+ //jest.setTimeout(100000)
5
+ import { describe, expect, it } from 'vitest'
6
+
7
+ describe('@sphereon/ssi-sdk.ms-authenticator', (): void => {
8
+ it.skip('should authenticate using clientCredential', async (): Promise<void> => {
9
+ // TODO REVERT
10
+ const result: AuthenticationResult = await getMSClientCredentialAccessToken({
11
+ azClientId: process.env.SPHEREON_SSI_MSAL_CLIENT_ID ?? 'client_id',
12
+ azClientSecret: process.env.SPHEREON_SSI_MSAL_CLIENT_SECRET ?? 'client_secret',
13
+ azTenantId: process.env.SPHEREON_SSI_MSAL_TENANT_ID ?? 'tenant_id',
14
+ credentialManifestUrl:
15
+ 'https://beta.eu.did.msidentity.com/v1.0/e2a42b2f-7460-4499-afc2-425315ef058a/verifiableCredential/contracts/VerifiedCredentialExpert2',
16
+ })
17
+
18
+ expect(result).toBeDefined()
19
+ })
20
+
21
+ it.skip('should authenticate using usernamePassword', async (): Promise<void> => {
22
+ // TODO REVERT
23
+ const result: string = await UsernamePasswordAuthenticator({
24
+ azTenantId: process.env.SPHEREON_SSI_MSAL_TENANT_ID ?? 'tenant_id',
25
+ azClientId: process.env.SPHEREON_SSI_MSAL_CLIENT_ID ?? 'client_id',
26
+ scopes: ['user.read'],
27
+ username: process.env.SPHEREON_SSI_MSAL_USERNAME ?? 'username',
28
+ password: process.env.SPHEREON_SSI_MSAL_PASSWORD ?? 'password',
29
+ })
30
+
31
+ expect(result).toBeDefined()
32
+ })
33
+ })
@@ -1,33 +0,0 @@
1
- import { AuthenticationResult, ConfidentialClientApplication } from '@azure/msal-node';
2
- import { IMSClientCredentialAuthInfo, IMsAuthenticationClientCredentialArgs, IMsAuthenticationUsernamePasswordArgs } from '../index';
3
- export declare const MS_DID_ENDPOINT_NON_EU = "https://beta.did.msidentity.com/v1.0/";
4
- export declare const MS_DID_ENDPOINT_EU = "https://beta.eu.did.msidentity.com/v1.0/";
5
- export declare function getMSOpenIDClientRegion(azTenantId: string): Promise<string>;
6
- export declare function getEntraDIDEndpoint(opts: {
7
- region?: string;
8
- azTenantId: string;
9
- }): Promise<"https://beta.did.msidentity.com/v1.0/" | "https://beta.eu.did.msidentity.com/v1.0/">;
10
- export declare function assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string>;
11
- /**
12
- * necessary fields are:
13
- * azClientId: clientId of the application you're trying to login
14
- * azClientSecret: secret of the application you're trying to login
15
- * azTenantId: your MS Azure tenantId
16
- * optional fields:
17
- * credentialManifest: address of your credential manifest. usually in following format:
18
- * https://beta.eu.did.msidentity.com/v1.0/<tenant_id>/verifiableCredential/contracts/<verifiable_credential_schema>
19
- * @param authenticationArgs
20
- * @constructor
21
- */
22
- export declare function getMSClientCredentialAccessToken(authenticationArgs: IMsAuthenticationClientCredentialArgs, opts?: {
23
- confidentialClient?: ConfidentialClientApplication;
24
- }): Promise<AuthenticationResult>;
25
- export declare function newMSClientCredentialAuthenticator(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<IMSClientCredentialAuthInfo>;
26
- /**
27
- * Logs in with provided authenticationArgs and returns access token
28
- * @param authenticationArgs
29
- * @constructor
30
- */
31
- export declare function UsernamePasswordAuthenticator(authenticationArgs: IMsAuthenticationUsernamePasswordArgs): Promise<string>;
32
- export declare function determineMSAuthId(authenticationArgs: IMsAuthenticationClientCredentialArgs | IMsAuthenticationUsernamePasswordArgs): string;
33
- //# sourceMappingURL=MsAuthenticator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MsAuthenticator.d.ts","sourceRoot":"","sources":["../../src/authenticators/MsAuthenticator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,6BAA6B,EAM9B,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,2BAA2B,EAAE,qCAAqC,EAAE,qCAAqC,EAAE,MAAM,UAAU,CAAA;AAUpI,eAAO,MAAM,sBAAsB,0CAA0C,CAAA;AAC7E,eAAO,MAAM,kBAAkB,6CAA6C,CAAA;AAU5E,wBAAsB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMjF;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,iGAGtF;AAED,wBAAsB,+CAA+C,CAAC,kBAAkB,EAAE,qCAAqC,GAAG,OAAO,CAAC,MAAM,CAAC,CAOhJ;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gCAAgC,CACpD,kBAAkB,EAAE,qCAAqC,EACzD,IAAI,CAAC,EAAE;IACL,kBAAkB,CAAC,EAAE,6BAA6B,CAAA;CACnD,GACA,OAAO,CAAC,oBAAoB,CAAC,CA6B/B;AAED,wBAAsB,kCAAkC,CACtD,kBAAkB,EAAE,qCAAqC,GACxD,OAAO,CAAC,2BAA2B,CAAC,CAkBtC;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,CAAC,kBAAkB,EAAE,qCAAqC,GAAG,OAAO,CAAC,MAAM,CAAC,CAa9H;AAUD,wBAAgB,iBAAiB,CAAC,kBAAkB,EAAE,qCAAqC,GAAG,qCAAqC,GAAG,MAAM,CAE3I"}
@@ -1,156 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.MS_DID_ENDPOINT_EU = exports.MS_DID_ENDPOINT_NON_EU = void 0;
16
- exports.getMSOpenIDClientRegion = getMSOpenIDClientRegion;
17
- exports.getEntraDIDEndpoint = getEntraDIDEndpoint;
18
- exports.assertEntraCredentialManifestUrlInCorrectRegion = assertEntraCredentialManifestUrlInCorrectRegion;
19
- exports.getMSClientCredentialAccessToken = getMSClientCredentialAccessToken;
20
- exports.newMSClientCredentialAuthenticator = newMSClientCredentialAuthenticator;
21
- exports.UsernamePasswordAuthenticator = UsernamePasswordAuthenticator;
22
- exports.determineMSAuthId = determineMSAuthId;
23
- const msal_node_1 = require("@azure/msal-node");
24
- const cross_fetch_1 = require("cross-fetch");
25
- const object_hash_1 = __importDefault(require("object-hash"));
26
- const EU = 'EU';
27
- const HTTP_METHOD_GET = 'GET';
28
- // Event though there are many regions, MS has only 2 DID identity host names (EU and NON_EU)
29
- // 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
30
- exports.MS_DID_ENDPOINT_NON_EU = 'https://beta.did.msidentity.com/v1.0/';
31
- exports.MS_DID_ENDPOINT_EU = 'https://beta.eu.did.msidentity.com/v1.0/';
32
- const MS_LOGIN_PREFIX = 'https://login.microsoftonline.com/';
33
- const MS_LOGIN_OPENID_CONFIG_POSTFIX = '/v2.0/.well-known/openid-configuration';
34
- const MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE = '3db474b9-6a0c-4840-96ac-1fceb342124f/.default';
35
- const ERROR_CREDENTIAL_MANIFEST_REGION = `Error in config file. CredentialManifest URL configured for wrong tenant region. Should start with:`;
36
- const ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT = 'Could not acquire verifiableCredentials to access your Azure Key Vault:\n';
37
- const ERROR_FAILED_AUTHENTICATION = 'failed to authenticate: ';
38
- // todo: This is a pretty heavy operation. Getting all the OIDC discovery data from a fetch only to return the region. Probably wise to add some caching and refactor so we can do more with the other OIDC info as well
39
- function getMSOpenIDClientRegion(azTenantId) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return (0, cross_fetch_1.fetch)(MS_LOGIN_PREFIX + azTenantId + MS_LOGIN_OPENID_CONFIG_POSTFIX, { method: HTTP_METHOD_GET })
42
- .then((res) => res.json())
43
- .then((resp) => __awaiter(this, void 0, void 0, function* () {
44
- var _a;
45
- return (_a = resp.tenant_region_scope) !== null && _a !== void 0 ? _a : EU;
46
- }));
47
- });
48
- }
49
- function getEntraDIDEndpoint(opts) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- var _a;
52
- const region = (_a = opts === null || opts === void 0 ? void 0 : opts.region) !== null && _a !== void 0 ? _a : (yield getMSOpenIDClientRegion(opts.azTenantId));
53
- return region === EU ? exports.MS_DID_ENDPOINT_EU : exports.MS_DID_ENDPOINT_NON_EU;
54
- });
55
- }
56
- function assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- var _a;
59
- const msDIDEndpoint = yield getEntraDIDEndpoint(authenticationArgs);
60
- // Check that the Credential Manifest URL is in the same tenant Region and throw an error if it's not
61
- if (!((_a = authenticationArgs.credentialManifestUrl) === null || _a === void 0 ? void 0 : _a.startsWith(msDIDEndpoint))) {
62
- throw new Error(ERROR_CREDENTIAL_MANIFEST_REGION + msDIDEndpoint + `. value: ${authenticationArgs.credentialManifestUrl}`);
63
- }
64
- return msDIDEndpoint;
65
- });
66
- }
67
- /**
68
- * necessary fields are:
69
- * azClientId: clientId of the application you're trying to login
70
- * azClientSecret: secret of the application you're trying to login
71
- * azTenantId: your MS Azure tenantId
72
- * optional fields:
73
- * credentialManifest: address of your credential manifest. usually in following format:
74
- * https://beta.eu.did.msidentity.com/v1.0/<tenant_id>/verifiableCredential/contracts/<verifiable_credential_schema>
75
- * @param authenticationArgs
76
- * @constructor
77
- */
78
- function getMSClientCredentialAccessToken(authenticationArgs, opts) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- var _a, _b, _c;
81
- const confidentialClient = (_a = opts === null || opts === void 0 ? void 0 : opts.confidentialClient) !== null && _a !== void 0 ? _a : (yield newMSClientCredentialAuthenticator(authenticationArgs).then((cca) => cca.confidentialClient));
82
- if (!confidentialClient) {
83
- throw Error('No Credential Client Authenticator could be constructed');
84
- }
85
- if (authenticationArgs === null || authenticationArgs === void 0 ? void 0 : authenticationArgs.credentialManifestUrl) {
86
- yield assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs);
87
- }
88
- const msalClientCredentialRequest = {
89
- scopes: (_b = authenticationArgs.scopes) !== null && _b !== void 0 ? _b : ((authenticationArgs === null || authenticationArgs === void 0 ? void 0 : authenticationArgs.credentialManifestUrl) ? [MS_CLIENT_CREDENTIAL_DEFAULT_SCOPE] : []),
90
- skipCache: (_c = authenticationArgs.skipCache) !== null && _c !== void 0 ? _c : false,
91
- };
92
- // get the Access Token
93
- try {
94
- const result = yield confidentialClient.acquireTokenByClientCredential(msalClientCredentialRequest);
95
- if (result) {
96
- return result;
97
- }
98
- }
99
- catch (err) {
100
- throw {
101
- error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT + err,
102
- };
103
- }
104
- throw {
105
- error: ERROR_ACQUIRE_ACCESS_TOKEN_FOR_CLIENT,
106
- };
107
- });
108
- }
109
- function newMSClientCredentialAuthenticator(authenticationArgs) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const didEndpoint = (authenticationArgs === null || authenticationArgs === void 0 ? void 0 : authenticationArgs.credentialManifestUrl)
112
- ? yield assertEntraCredentialManifestUrlInCorrectRegion(authenticationArgs)
113
- : undefined;
114
- const auth = authOptions(authenticationArgs);
115
- const id = (0, object_hash_1.default)(auth);
116
- const msalConfig = {
117
- auth,
118
- system: {
119
- loggerOptions: {
120
- piiLoggingEnabled: authenticationArgs.piiLoggingEnabled ? authenticationArgs.piiLoggingEnabled : false,
121
- logLevel: authenticationArgs.logLevel ? authenticationArgs.logLevel : msal_node_1.LogLevel.Verbose,
122
- },
123
- },
124
- };
125
- const confidentialClientApp = new msal_node_1.ConfidentialClientApplication(msalConfig);
126
- return { confidentialClient: confidentialClientApp, msalConfig, authenticationArgs, didEndpoint, id };
127
- });
128
- }
129
- /**
130
- * Logs in with provided authenticationArgs and returns access token
131
- * @param authenticationArgs
132
- * @constructor
133
- */
134
- function UsernamePasswordAuthenticator(authenticationArgs) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- const msalConfig = {
137
- auth: authOptions(authenticationArgs),
138
- };
139
- const pca = new msal_node_1.PublicClientApplication(msalConfig);
140
- return yield pca
141
- .acquireTokenByUsernamePassword(authenticationArgs)
142
- .then((response) => {
143
- return response;
144
- })
145
- .catch((error) => {
146
- throw new Error(ERROR_FAILED_AUTHENTICATION + error);
147
- });
148
- });
149
- }
150
- function authOptions(authenticationArgs) {
151
- return Object.assign({ clientId: authenticationArgs.azClientId, authority: authenticationArgs.authority ? authenticationArgs.authority : MS_LOGIN_PREFIX + authenticationArgs.azTenantId }, (authenticationArgs && 'azClientSecret' in authenticationArgs && { clientSecret: authenticationArgs.azClientSecret }));
152
- }
153
- function determineMSAuthId(authenticationArgs) {
154
- return (0, object_hash_1.default)(authOptions(authenticationArgs));
155
- }
156
- //# sourceMappingURL=MsAuthenticator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MsAuthenticator.js","sourceRoot":"","sources":["../../src/authenticators/MsAuthenticator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AA+BA,0DAMC;AAED,kDAGC;AAED,0GAOC;AAaD,4EAkCC;AAED,gFAoBC;AAOD,sEAaC;AAUD,8CAEC;AAxJD,gDAQyB;AACzB,6CAAmC;AAGnC,8DAA8B;AAE9B,MAAM,EAAE,GAAG,IAAI,CAAA;AAEf,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,6FAA6F;AAC7F,iLAAiL;AACpK,QAAA,sBAAsB,GAAG,uCAAuC,CAAA;AAChE,QAAA,kBAAkB,GAAG,0CAA0C,CAAA;AAC5E,MAAM,eAAe,GAAG,oCAAoC,CAAA;AAC5D,MAAM,8BAA8B,GAAG,wCAAwC,CAAA;AAC/E,MAAM,kCAAkC,GAAG,+CAA+C,CAAA;AAE1F,MAAM,gCAAgC,GAAG,qGAAqG,CAAA;AAC9I,MAAM,qCAAqC,GAAG,2EAA2E,CAAA;AACzH,MAAM,2BAA2B,GAAG,0BAA0B,CAAA;AAE9D,wNAAwN;AACxN,SAAsB,uBAAuB,CAAC,UAAkB;;QAC9D,OAAO,IAA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BAAgB,IAAI,kBAAkB,IAAI,EAAE,YAAY,EAAE,kBAAkB,CAAC,cAAc,EAAE,CAAC,EACzH;AACH,CAAC;AAED,SAAgB,iBAAiB,CAAC,kBAAiG;IACjI,OAAO,IAAA,qBAAI,EAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAA;AAC9C,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './MsAuthenticator';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authenticators/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./MsAuthenticator"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authenticators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"IMsAuthenticator.d.ts","sourceRoot":"","sources":["../../src/types/IMsAuthenticator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACzF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,qCAAqC;IACpD,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,qCAAqC;IACpD,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,MAAM,CAAA;IACV,kBAAkB,EAAE,6BAA6B,CAAA;IACjD,UAAU,EAAE,aAAa,CAAA;IACzB,kBAAkB,EAAE,qCAAqC,CAAA;IACzD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IMsAuthenticator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IMsAuthenticator.js","sourceRoot":"","sources":["../../src/types/IMsAuthenticator.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export * from './IMsAuthenticator';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./IMsAuthenticator"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAkC"}