@azure/msal-node-extensions 1.1.0 → 1.2.0
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/bin/arm64/dpapi.node +0 -0
- package/bin/ia32/dpapi.node +0 -0
- package/bin/x64/dpapi.node +0 -0
- package/dist/Dpapi.mjs +1 -1
- package/dist/broker/NativeBrokerPlugin.d.ts +2 -2
- package/dist/broker/NativeBrokerPlugin.mjs +19 -10
- package/dist/broker/NativeBrokerPlugin.mjs.map +1 -1
- package/dist/error/NativeAuthError.d.ts +1 -1
- package/dist/error/NativeAuthError.mjs +2 -2
- package/dist/error/PersistenceError.mjs +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.mjs +1 -1
- package/dist/lib/msal-common/dist/constants/AADServerParamKeys.mjs +7 -0
- package/dist/lib/msal-common/dist/constants/AADServerParamKeys.mjs.map +1 -0
- package/dist/lib/msal-common/dist/error/AuthError.mjs +27 -0
- package/dist/lib/msal-common/dist/error/AuthError.mjs.map +1 -0
- package/dist/lib/msal-common/dist/error/ClientAuthError.mjs +81 -0
- package/dist/lib/msal-common/dist/error/ClientAuthError.mjs.map +1 -0
- package/dist/lib/msal-common/dist/error/ClientAuthErrorCodes.mjs +54 -0
- package/dist/lib/msal-common/dist/error/ClientAuthErrorCodes.mjs.map +1 -0
- package/dist/lib/msal-common/dist/error/ClientConfigurationError.mjs +51 -0
- package/dist/lib/msal-common/dist/error/ClientConfigurationError.mjs.map +1 -0
- package/dist/lib/msal-common/dist/error/ClientConfigurationErrorCodes.mjs +32 -0
- package/dist/lib/msal-common/dist/error/ClientConfigurationErrorCodes.mjs.map +1 -0
- package/dist/lib/msal-common/dist/error/InteractionRequiredAuthError.mjs +24 -0
- package/dist/lib/msal-common/dist/error/InteractionRequiredAuthError.mjs.map +1 -0
- package/dist/lib/msal-common/dist/error/ServerError.mjs +25 -0
- package/dist/lib/msal-common/dist/error/ServerError.mjs.map +1 -0
- package/dist/lib/msal-common/dist/logger/Logger.mjs +197 -0
- package/dist/lib/msal-common/dist/logger/Logger.mjs.map +1 -0
- package/dist/lib/msal-common/dist/telemetry/server/ServerTelemetryManager.mjs +270 -0
- package/dist/lib/msal-common/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -0
- package/dist/lib/msal-common/dist/utils/Constants.mjs +124 -0
- package/dist/lib/msal-common/dist/utils/Constants.mjs.map +1 -0
- package/dist/lock/CrossPlatformLock.d.ts +2 -2
- package/dist/lock/CrossPlatformLock.mjs +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/persistence/BasePersistence.d.ts +1 -1
- package/dist/persistence/BasePersistence.mjs +1 -1
- package/dist/persistence/DataProtectionScope.mjs +1 -1
- package/dist/persistence/FilePersistence.d.ts +3 -3
- package/dist/persistence/FilePersistence.mjs +2 -2
- package/dist/persistence/FilePersistenceWithDataProtection.d.ts +4 -4
- package/dist/persistence/FilePersistenceWithDataProtection.mjs +1 -1
- package/dist/persistence/IPersistence.d.ts +1 -1
- package/dist/persistence/IPersistenceConfiguration.d.ts +2 -2
- package/dist/persistence/KeychainPersistence.d.ts +3 -3
- package/dist/persistence/KeychainPersistence.mjs +1 -1
- package/dist/persistence/LibSecretPersistence.d.ts +3 -3
- package/dist/persistence/LibSecretPersistence.mjs +1 -1
- package/dist/persistence/PersistenceCachePlugin.d.ts +3 -3
- package/dist/persistence/PersistenceCachePlugin.mjs +1 -1
- package/dist/persistence/PersistenceCachePlugin.mjs.map +1 -1
- package/dist/persistence/PersistenceCreator.d.ts +2 -2
- package/dist/persistence/PersistenceCreator.mjs +1 -1
- package/dist/utils/Constants.mjs +1 -1
- package/dist/utils/Environment.mjs +1 -1
- package/dist/utils/TypeGuards.d.ts +1 -1
- package/dist/utils/TypeGuards.mjs +1 -1
- package/lib/msal-node-extensions.cjs +2230 -0
- package/lib/msal-node-extensions.cjs.map +1 -0
- package/lib/package.json +1 -0
- package/lib/types/Dpapi.d.ts +6 -0
- package/lib/types/broker/NativeBrokerPlugin.d.ts +20 -0
- package/lib/types/error/NativeAuthError.d.ts +6 -0
- package/lib/types/error/PersistenceError.d.ts +57 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/lock/CrossPlatformLock.d.ts +24 -0
- package/lib/types/lock/CrossPlatformLockOptions.d.ts +10 -0
- package/lib/types/packageMetadata.d.ts +2 -0
- package/lib/types/persistence/BasePersistence.d.ts +5 -0
- package/{dist/persistence/DataProtectionScope.cjs → lib/types/persistence/DataProtectionScope.d.ts} +5 -15
- package/lib/types/persistence/FilePersistence.d.ts +29 -0
- package/lib/types/persistence/FilePersistenceWithDataProtection.d.ts +24 -0
- package/lib/types/persistence/IPersistence.d.ts +11 -0
- package/lib/types/persistence/IPersistenceConfiguration.d.ts +10 -0
- package/lib/types/persistence/KeychainPersistence.d.ts +23 -0
- package/lib/types/persistence/LibSecretPersistence.d.ts +24 -0
- package/lib/types/persistence/PersistenceCachePlugin.d.ts +38 -0
- package/lib/types/persistence/PersistenceCreator.d.ts +5 -0
- package/lib/types/utils/Constants.d.ts +54 -0
- package/lib/types/utils/Environment.d.ts +16 -0
- package/lib/types/utils/TypeGuards.d.ts +5 -0
- package/package.json +16 -9
- package/dist/Dpapi.cjs +0 -31
- package/dist/Dpapi.cjs.map +0 -1
- package/dist/broker/NativeBrokerPlugin.cjs +0 -426
- package/dist/broker/NativeBrokerPlugin.cjs.map +0 -1
- package/dist/error/NativeAuthError.cjs +0 -22
- package/dist/error/NativeAuthError.cjs.map +0 -1
- package/dist/error/PersistenceError.cjs +0 -93
- package/dist/error/PersistenceError.cjs.map +0 -1
- package/dist/index.cjs +0 -26
- package/dist/index.cjs.map +0 -1
- package/dist/lock/CrossPlatformLock.cjs +0 -97
- package/dist/lock/CrossPlatformLock.cjs.map +0 -1
- package/dist/packageMetadata.cjs +0 -11
- package/dist/packageMetadata.cjs.map +0 -1
- package/dist/persistence/BasePersistence.cjs +0 -38
- package/dist/persistence/BasePersistence.cjs.map +0 -1
- package/dist/persistence/DataProtectionScope.cjs.map +0 -1
- package/dist/persistence/FilePersistence.cjs +0 -175
- package/dist/persistence/FilePersistence.cjs.map +0 -1
- package/dist/persistence/FilePersistenceWithDataProtection.cjs +0 -92
- package/dist/persistence/FilePersistenceWithDataProtection.cjs.map +0 -1
- package/dist/persistence/KeychainPersistence.cjs +0 -92
- package/dist/persistence/KeychainPersistence.cjs.map +0 -1
- package/dist/persistence/LibSecretPersistence.cjs +0 -93
- package/dist/persistence/LibSecretPersistence.cjs.map +0 -1
- package/dist/persistence/PersistenceCachePlugin.cjs +0 -101
- package/dist/persistence/PersistenceCachePlugin.cjs.map +0 -1
- package/dist/persistence/PersistenceCreator.cjs +0 -70
- package/dist/persistence/PersistenceCreator.cjs.map +0 -1
- package/dist/utils/Constants.cjs +0 -66
- package/dist/utils/Constants.cjs.map +0 -1
- package/dist/utils/Environment.cjs +0 -96
- package/dist/utils/Environment.cjs.map +0 -1
- package/dist/utils/TypeGuards.cjs +0 -17
- package/dist/utils/TypeGuards.cjs.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IPersistence } from "./IPersistence.js";
|
|
2
|
+
import { Logger, LoggerOptions } from "@azure/msal-common/node";
|
|
3
|
+
import { BasePersistence } from "./BasePersistence.js";
|
|
4
|
+
/**
|
|
5
|
+
* Uses reads and writes passwords to Secret Service API/libsecret. Requires libsecret
|
|
6
|
+
* to be installed.
|
|
7
|
+
*
|
|
8
|
+
* serviceName: Identifier used as key for whatever value is stored
|
|
9
|
+
* accountName: Account under which password should be stored
|
|
10
|
+
*/
|
|
11
|
+
export declare class LibSecretPersistence extends BasePersistence implements IPersistence {
|
|
12
|
+
protected readonly serviceName: string;
|
|
13
|
+
protected readonly accountName: string;
|
|
14
|
+
private filePersistence;
|
|
15
|
+
private constructor();
|
|
16
|
+
static create(fileLocation: string, serviceName: string, accountName: string, loggerOptions?: LoggerOptions): Promise<LibSecretPersistence>;
|
|
17
|
+
save(contents: string): Promise<void>;
|
|
18
|
+
load(): Promise<string | null>;
|
|
19
|
+
delete(): Promise<boolean>;
|
|
20
|
+
reloadNecessary(lastSync: number): Promise<boolean>;
|
|
21
|
+
getFilePath(): string;
|
|
22
|
+
getLogger(): Logger;
|
|
23
|
+
createForPersistenceValidation(): Promise<LibSecretPersistence>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IPersistence } from "./IPersistence.js";
|
|
2
|
+
import { CrossPlatformLockOptions } from "../lock/CrossPlatformLockOptions.js";
|
|
3
|
+
import { TokenCacheContext, ICachePlugin } from "@azure/msal-common/node";
|
|
4
|
+
/**
|
|
5
|
+
* MSAL cache plugin which enables callers to write the MSAL cache to disk on Windows,
|
|
6
|
+
* macOs, and Linux.
|
|
7
|
+
*
|
|
8
|
+
* - Persistence can be one of:
|
|
9
|
+
* - FilePersistence: Writes and reads from an unencrypted file. Can be used on Windows,
|
|
10
|
+
* macOs, or Linux.
|
|
11
|
+
* - FilePersistenceWithDataProtection: Used on Windows, writes and reads from file encrypted
|
|
12
|
+
* with windows dpapi-addon.
|
|
13
|
+
* - KeychainPersistence: Used on macOs, writes and reads from keychain.
|
|
14
|
+
* - LibSecretPersistence: Used on linux, writes and reads from secret service API. Requires
|
|
15
|
+
* libsecret be installed.
|
|
16
|
+
*/
|
|
17
|
+
export declare class PersistenceCachePlugin implements ICachePlugin {
|
|
18
|
+
persistence: IPersistence;
|
|
19
|
+
lastSync: number;
|
|
20
|
+
currentCache: string | null;
|
|
21
|
+
lockFilePath: string;
|
|
22
|
+
private crossPlatformLock;
|
|
23
|
+
private logger;
|
|
24
|
+
constructor(persistence: IPersistence, lockOptions?: CrossPlatformLockOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Reads from storage and saves an in-memory copy. If persistence has not been updated
|
|
27
|
+
* since last time data was read, in memory copy is used.
|
|
28
|
+
*
|
|
29
|
+
* If cacheContext.cacheHasChanged === true, then file lock is created and not deleted until
|
|
30
|
+
* afterCacheAccess() is called, to prevent the cache file from changing in between
|
|
31
|
+
* beforeCacheAccess() and afterCacheAccess().
|
|
32
|
+
*/
|
|
33
|
+
beforeCacheAccess(cacheContext: TokenCacheContext): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Writes to storage if MSAL in memory copy of cache has been changed.
|
|
36
|
+
*/
|
|
37
|
+
afterCacheAccess(cacheContext: TokenCacheContext): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare const Constants: {
|
|
2
|
+
/**
|
|
3
|
+
* An existing file was the target of an operation that required that the target not exist
|
|
4
|
+
*/
|
|
5
|
+
EEXIST_ERROR: string;
|
|
6
|
+
/**
|
|
7
|
+
* No such file or directory: Commonly raised by fs operations to indicate that a component
|
|
8
|
+
* of the specified pathname does not exist. No entity (file or directory) could be found
|
|
9
|
+
* by the given path
|
|
10
|
+
*/
|
|
11
|
+
ENOENT_ERROR: string;
|
|
12
|
+
/**
|
|
13
|
+
* Operation not permitted. An attempt was made to perform an operation that requires
|
|
14
|
+
* elevated privileges.
|
|
15
|
+
*/
|
|
16
|
+
EPERM_ERROR: string;
|
|
17
|
+
/**
|
|
18
|
+
* Default service name for using MSAL Keytar
|
|
19
|
+
*/
|
|
20
|
+
DEFAULT_SERVICE_NAME: string;
|
|
21
|
+
/**
|
|
22
|
+
* Test data used to verify underlying persistence mechanism
|
|
23
|
+
*/
|
|
24
|
+
PERSISTENCE_TEST_DATA: string;
|
|
25
|
+
/**
|
|
26
|
+
* This is the value of a the guid if the process is being ran by the root user
|
|
27
|
+
*/
|
|
28
|
+
LINUX_ROOT_USER_GUID: number;
|
|
29
|
+
/**
|
|
30
|
+
* List of environment variables
|
|
31
|
+
*/
|
|
32
|
+
ENVIRONMENT: {
|
|
33
|
+
HOME: string;
|
|
34
|
+
LOGNAME: string;
|
|
35
|
+
USER: string;
|
|
36
|
+
LNAME: string;
|
|
37
|
+
USERNAME: string;
|
|
38
|
+
PLATFORM: string;
|
|
39
|
+
LOCAL_APPLICATION_DATA: string;
|
|
40
|
+
};
|
|
41
|
+
DEFAULT_CACHE_FILE_NAME: string;
|
|
42
|
+
};
|
|
43
|
+
export declare const Platform: {
|
|
44
|
+
readonly WINDOWS: "win32";
|
|
45
|
+
readonly LINUX: "linux";
|
|
46
|
+
readonly MACOS: "darwin";
|
|
47
|
+
};
|
|
48
|
+
export type Platform = (typeof Platform)[keyof typeof Platform];
|
|
49
|
+
export declare const ErrorCodes: {
|
|
50
|
+
readonly INTERATION_REQUIRED_ERROR_CODE: "interaction_required";
|
|
51
|
+
readonly SERVER_UNAVAILABLE: "server_unavailable";
|
|
52
|
+
readonly UNKNOWN: "unknown_error";
|
|
53
|
+
};
|
|
54
|
+
export type ErrorCodes = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class Environment {
|
|
2
|
+
static get homeEnvVar(): string;
|
|
3
|
+
static get lognameEnvVar(): string;
|
|
4
|
+
static get userEnvVar(): string;
|
|
5
|
+
static get lnameEnvVar(): string;
|
|
6
|
+
static get usernameEnvVar(): string;
|
|
7
|
+
static getEnvironmentVariable(name: string): string;
|
|
8
|
+
static getEnvironmentPlatform(): string;
|
|
9
|
+
static isWindowsPlatform(): boolean;
|
|
10
|
+
static isLinuxPlatform(): boolean;
|
|
11
|
+
static isMacPlatform(): boolean;
|
|
12
|
+
static isLinuxRootUser(): boolean;
|
|
13
|
+
static getUserRootDirectory(): string | null;
|
|
14
|
+
static getUserHomeDirOnWindows(): string;
|
|
15
|
+
static getUserHomeDirOnUnix(): string | null;
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/msal-node-extensions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/AzureAD/microsoft-authentication-library-for-js.git"
|
|
7
7
|
},
|
|
8
8
|
"license": "MIT",
|
|
9
|
+
"type": "module",
|
|
9
10
|
"module": "dist/index.mjs",
|
|
10
11
|
"types": "dist/index.d.ts",
|
|
12
|
+
"main": "lib/msal-node-extensions.cjs",
|
|
11
13
|
"exports": {
|
|
12
14
|
".": {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./lib/types/index.d.ts",
|
|
21
|
+
"default": "./lib/msal-node-extensions.cjs"
|
|
22
|
+
}
|
|
18
23
|
},
|
|
19
24
|
"./package.json": "./package.json"
|
|
20
25
|
},
|
|
@@ -28,7 +33,8 @@
|
|
|
28
33
|
],
|
|
29
34
|
"files": [
|
|
30
35
|
"dist",
|
|
31
|
-
"bin"
|
|
36
|
+
"bin",
|
|
37
|
+
"lib"
|
|
32
38
|
],
|
|
33
39
|
"engines": {
|
|
34
40
|
"node": ">=16"
|
|
@@ -36,7 +42,7 @@
|
|
|
36
42
|
"scripts": {
|
|
37
43
|
"compile": "node-gyp rebuild",
|
|
38
44
|
"install": "exit 0",
|
|
39
|
-
"clean": "shx rm -rf dist bin",
|
|
45
|
+
"clean": "shx rm -rf dist bin lib",
|
|
40
46
|
"build": "npm run clean && rollup -c --strictDeprecations --bundleConfigAsCjs && node ./scripts/buildBinaries.cjs",
|
|
41
47
|
"build:all": "cd ../.. && npm run build --workspace=@azure/msal-common --workspace=@azure/msal-node-extensions",
|
|
42
48
|
"test": "jest",
|
|
@@ -58,7 +64,7 @@
|
|
|
58
64
|
]
|
|
59
65
|
},
|
|
60
66
|
"dependencies": {
|
|
61
|
-
"@azure/msal-common": "14.
|
|
67
|
+
"@azure/msal-common": "14.15.0",
|
|
62
68
|
"@azure/msal-node-runtime": "^0.13.6-alpha.0",
|
|
63
69
|
"keytar": "^7.8.0"
|
|
64
70
|
},
|
|
@@ -71,6 +77,7 @@
|
|
|
71
77
|
"jest": "^29.5.0",
|
|
72
78
|
"node-addon-api": "^6.1.0",
|
|
73
79
|
"rollup": "^3.20.2",
|
|
80
|
+
"rollup-msal": "file:../../shared-configs/rollup-msal",
|
|
74
81
|
"shx": "^0.3.4",
|
|
75
82
|
"ts-jest": "^29.1.0",
|
|
76
83
|
"ts-jest-mock-import-meta": "^1.1.0",
|
package/dist/Dpapi.cjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*! @azure/msal-node-extensions v1.1.0 2024-07-23 */
|
|
2
|
-
'use strict';
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
var module$1 = require('module');
|
|
6
|
-
|
|
7
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
8
|
-
/*
|
|
9
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
-
* Licensed under the MIT License.
|
|
11
|
-
*/
|
|
12
|
-
class defaultDpapi {
|
|
13
|
-
protectData() {
|
|
14
|
-
throw new Error("Dpapi is not supported on this platform");
|
|
15
|
-
}
|
|
16
|
-
unprotectData() {
|
|
17
|
-
throw new Error("Dpapi is not supported on this platform");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.Dpapi = void 0;
|
|
21
|
-
if (process.platform !== "win32") {
|
|
22
|
-
exports.Dpapi = new defaultDpapi();
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
// In .mjs files, require is not defined. We need to use createRequire to get a require function
|
|
26
|
-
const safeRequire = typeof require !== "undefined"
|
|
27
|
-
? require
|
|
28
|
-
: module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('Dpapi.cjs', document.baseURI).href)));
|
|
29
|
-
exports.Dpapi = safeRequire(`../bin/${process.arch}/dpapi`);
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=Dpapi.cjs.map
|
package/dist/Dpapi.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Dpapi.cjs","sources":["../src/Dpapi.ts"],"sourcesContent":[null],"names":["Dpapi","createRequire"],"mappings":";;;;;;;AAAA;;;AAGG;AAiBH,MAAM,YAAY,CAAA;IACd,WAAW,GAAA;AACP,QAAA,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;KAC9D;IACD,aAAa,GAAA;AACT,QAAA,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;KAC9D;AACJ,CAAA;AAEGA,uBAAqB;AACzB,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;AAC9B,IAAAA,aAAK,GAAG,IAAI,YAAY,EAAE,CAAC;AAC9B,CAAA;AAAM,KAAA;;AAEH,IAAA,MAAM,WAAW,GACb,OAAO,OAAO,KAAK,WAAW;AAC1B,UAAE,OAAO;UACPC,sBAAa,CAAC,8LAAe,CAAC,CAAC;IAEzCD,aAAK,GAAG,WAAW,CAAC,CAAA,OAAA,EAAU,OAAO,CAAC,IAAI,CAAQ,MAAA,CAAA,CAAC,CAAC;AACvD;;"}
|
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
/*! @azure/msal-node-extensions v1.1.0 2024-07-23 */
|
|
2
|
-
'use strict';
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
var msalCommon = require('@azure/msal-common');
|
|
6
|
-
var msalNodeRuntime = require('@azure/msal-node-runtime');
|
|
7
|
-
var Constants = require('../utils/Constants.cjs');
|
|
8
|
-
var NativeAuthError = require('../error/NativeAuthError.cjs');
|
|
9
|
-
var packageMetadata = require('../packageMetadata.cjs');
|
|
10
|
-
|
|
11
|
-
/*
|
|
12
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
13
|
-
* Licensed under the MIT License.
|
|
14
|
-
*/
|
|
15
|
-
class NativeBrokerPlugin {
|
|
16
|
-
constructor() {
|
|
17
|
-
const defaultLoggerOptions = {
|
|
18
|
-
loggerCallback: () => {
|
|
19
|
-
// Empty logger callback
|
|
20
|
-
},
|
|
21
|
-
piiLoggingEnabled: false,
|
|
22
|
-
};
|
|
23
|
-
this.logger = new msalCommon.Logger(defaultLoggerOptions, packageMetadata.name, packageMetadata.version); // Default logger
|
|
24
|
-
this.isBrokerAvailable = msalNodeRuntime.msalNodeRuntime.StartupError ? false : true;
|
|
25
|
-
}
|
|
26
|
-
setLogger(loggerOptions) {
|
|
27
|
-
this.logger = new msalCommon.Logger(loggerOptions, packageMetadata.name, packageMetadata.version);
|
|
28
|
-
const logCallback = (message, logLevel, containsPii) => {
|
|
29
|
-
switch (logLevel) {
|
|
30
|
-
case msalNodeRuntime.LogLevel.Trace:
|
|
31
|
-
if (containsPii) {
|
|
32
|
-
this.logger.tracePii(message);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this.logger.trace(message);
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
case msalNodeRuntime.LogLevel.Debug:
|
|
39
|
-
if (containsPii) {
|
|
40
|
-
this.logger.tracePii(message);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.logger.trace(message);
|
|
44
|
-
}
|
|
45
|
-
break;
|
|
46
|
-
case msalNodeRuntime.LogLevel.Info:
|
|
47
|
-
if (containsPii) {
|
|
48
|
-
this.logger.infoPii(message);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
this.logger.info(message);
|
|
52
|
-
}
|
|
53
|
-
break;
|
|
54
|
-
case msalNodeRuntime.LogLevel.Warning:
|
|
55
|
-
if (containsPii) {
|
|
56
|
-
this.logger.warningPii(message);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
this.logger.warning(message);
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
case msalNodeRuntime.LogLevel.Error:
|
|
63
|
-
if (containsPii) {
|
|
64
|
-
this.logger.errorPii(message);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.logger.error(message);
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
case msalNodeRuntime.LogLevel.Fatal:
|
|
71
|
-
if (containsPii) {
|
|
72
|
-
this.logger.errorPii(message);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
this.logger.error(message);
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
default:
|
|
79
|
-
if (containsPii) {
|
|
80
|
-
this.logger.infoPii(message);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this.logger.info(message);
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
try {
|
|
89
|
-
msalNodeRuntime.msalNodeRuntime.RegisterLogger(logCallback, loggerOptions.piiLoggingEnabled || false);
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
|
-
const wrappedError = this.wrapError(e);
|
|
93
|
-
if (wrappedError) {
|
|
94
|
-
throw wrappedError;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async getAccountById(accountId, correlationId) {
|
|
99
|
-
this.logger.trace("NativeBrokerPlugin - getAccountById called", correlationId);
|
|
100
|
-
const readAccountResult = await this.readAccountById(accountId, correlationId);
|
|
101
|
-
return this.generateAccountInfo(readAccountResult.account);
|
|
102
|
-
}
|
|
103
|
-
async getAllAccounts(clientId, correlationId) {
|
|
104
|
-
this.logger.trace("NativeBrokerPlugin - getAllAccounts called", correlationId);
|
|
105
|
-
return new Promise((resolve, reject) => {
|
|
106
|
-
const resultCallback = (result) => {
|
|
107
|
-
try {
|
|
108
|
-
result.CheckError();
|
|
109
|
-
}
|
|
110
|
-
catch (e) {
|
|
111
|
-
const wrappedError = this.wrapError(e);
|
|
112
|
-
if (wrappedError) {
|
|
113
|
-
reject(wrappedError);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const accountInfoResult = [];
|
|
118
|
-
result.accounts.forEach((account) => {
|
|
119
|
-
accountInfoResult.push(this.generateAccountInfo(account));
|
|
120
|
-
});
|
|
121
|
-
resolve(accountInfoResult);
|
|
122
|
-
};
|
|
123
|
-
try {
|
|
124
|
-
msalNodeRuntime.msalNodeRuntime.DiscoverAccountsAsync(clientId, correlationId, resultCallback);
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
const wrappedError = this.wrapError(e);
|
|
128
|
-
if (wrappedError) {
|
|
129
|
-
reject(wrappedError);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
async acquireTokenSilent(request) {
|
|
135
|
-
this.logger.trace("NativeBrokerPlugin - acquireTokenSilent called", request.correlationId);
|
|
136
|
-
const authParams = this.generateRequestParameters(request);
|
|
137
|
-
const account = await this.getAccount(request);
|
|
138
|
-
return new Promise((resolve, reject) => {
|
|
139
|
-
const resultCallback = (result) => {
|
|
140
|
-
try {
|
|
141
|
-
result.CheckError();
|
|
142
|
-
}
|
|
143
|
-
catch (e) {
|
|
144
|
-
const wrappedError = this.wrapError(e);
|
|
145
|
-
if (wrappedError) {
|
|
146
|
-
reject(wrappedError);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const authenticationResult = this.getAuthenticationResult(request, result);
|
|
151
|
-
resolve(authenticationResult);
|
|
152
|
-
};
|
|
153
|
-
try {
|
|
154
|
-
if (account) {
|
|
155
|
-
msalNodeRuntime.msalNodeRuntime.AcquireTokenSilentlyAsync(authParams, request.correlationId, account, resultCallback);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
msalNodeRuntime.msalNodeRuntime.SignInSilentlyAsync(authParams, request.correlationId, resultCallback);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch (e) {
|
|
162
|
-
const wrappedError = this.wrapError(e);
|
|
163
|
-
if (wrappedError) {
|
|
164
|
-
reject(wrappedError);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
async acquireTokenInteractive(request, providedWindowHandle) {
|
|
170
|
-
this.logger.trace("NativeBrokerPlugin - acquireTokenInteractive called", request.correlationId);
|
|
171
|
-
const authParams = this.generateRequestParameters(request);
|
|
172
|
-
const account = await this.getAccount(request);
|
|
173
|
-
const windowHandle = providedWindowHandle || Buffer.from([0]);
|
|
174
|
-
return new Promise((resolve, reject) => {
|
|
175
|
-
const resultCallback = (result) => {
|
|
176
|
-
try {
|
|
177
|
-
result.CheckError();
|
|
178
|
-
}
|
|
179
|
-
catch (e) {
|
|
180
|
-
const wrappedError = this.wrapError(e);
|
|
181
|
-
if (wrappedError) {
|
|
182
|
-
reject(wrappedError);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const authenticationResult = this.getAuthenticationResult(request, result);
|
|
187
|
-
resolve(authenticationResult);
|
|
188
|
-
};
|
|
189
|
-
try {
|
|
190
|
-
switch (request.prompt) {
|
|
191
|
-
case msalCommon.PromptValue.LOGIN:
|
|
192
|
-
case msalCommon.PromptValue.SELECT_ACCOUNT:
|
|
193
|
-
case msalCommon.PromptValue.CREATE:
|
|
194
|
-
this.logger.info("Calling native interop SignInInteractively API", request.correlationId);
|
|
195
|
-
const loginHint = request.loginHint || msalCommon.Constants.EMPTY_STRING;
|
|
196
|
-
msalNodeRuntime.msalNodeRuntime.SignInInteractivelyAsync(windowHandle, authParams, request.correlationId, loginHint, resultCallback);
|
|
197
|
-
break;
|
|
198
|
-
case msalCommon.PromptValue.NONE:
|
|
199
|
-
if (account) {
|
|
200
|
-
this.logger.info("Calling native interop AcquireTokenSilently API", request.correlationId);
|
|
201
|
-
msalNodeRuntime.msalNodeRuntime.AcquireTokenSilentlyAsync(authParams, request.correlationId, account, resultCallback);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
this.logger.info("Calling native interop SignInSilently API", request.correlationId);
|
|
205
|
-
msalNodeRuntime.msalNodeRuntime.SignInSilentlyAsync(authParams, request.correlationId, resultCallback);
|
|
206
|
-
}
|
|
207
|
-
break;
|
|
208
|
-
default:
|
|
209
|
-
if (account) {
|
|
210
|
-
this.logger.info("Calling native interop AcquireTokenInteractively API", request.correlationId);
|
|
211
|
-
msalNodeRuntime.msalNodeRuntime.AcquireTokenInteractivelyAsync(windowHandle, authParams, request.correlationId, account, resultCallback);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
this.logger.info("Calling native interop SignIn API", request.correlationId);
|
|
215
|
-
const loginHint = request.loginHint || msalCommon.Constants.EMPTY_STRING;
|
|
216
|
-
msalNodeRuntime.msalNodeRuntime.SignInAsync(windowHandle, authParams, request.correlationId, loginHint, resultCallback);
|
|
217
|
-
}
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
catch (e) {
|
|
222
|
-
const wrappedError = this.wrapError(e);
|
|
223
|
-
if (wrappedError) {
|
|
224
|
-
reject(wrappedError);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
async signOut(request) {
|
|
230
|
-
this.logger.trace("NativeBrokerPlugin - signOut called", request.correlationId);
|
|
231
|
-
const account = await this.getAccount(request);
|
|
232
|
-
if (!account) {
|
|
233
|
-
throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.noAccountFound);
|
|
234
|
-
}
|
|
235
|
-
return new Promise((resolve, reject) => {
|
|
236
|
-
const resultCallback = (result) => {
|
|
237
|
-
try {
|
|
238
|
-
result.CheckError();
|
|
239
|
-
}
|
|
240
|
-
catch (e) {
|
|
241
|
-
const wrappedError = this.wrapError(e);
|
|
242
|
-
if (wrappedError) {
|
|
243
|
-
reject(wrappedError);
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
resolve();
|
|
248
|
-
};
|
|
249
|
-
try {
|
|
250
|
-
msalNodeRuntime.msalNodeRuntime.SignOutSilentlyAsync(request.clientId, request.correlationId, account, resultCallback);
|
|
251
|
-
}
|
|
252
|
-
catch (e) {
|
|
253
|
-
const wrappedError = this.wrapError(e);
|
|
254
|
-
if (wrappedError) {
|
|
255
|
-
reject(wrappedError);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
async getAccount(request) {
|
|
261
|
-
if (request.accountId) {
|
|
262
|
-
const readAccountResult = await this.readAccountById(request.accountId, request.correlationId);
|
|
263
|
-
return readAccountResult.account;
|
|
264
|
-
}
|
|
265
|
-
return null;
|
|
266
|
-
}
|
|
267
|
-
async readAccountById(accountId, correlationId) {
|
|
268
|
-
this.logger.trace("NativeBrokerPlugin - readAccountById called", correlationId);
|
|
269
|
-
return new Promise((resolve, reject) => {
|
|
270
|
-
const resultCallback = (result) => {
|
|
271
|
-
try {
|
|
272
|
-
result.CheckError();
|
|
273
|
-
}
|
|
274
|
-
catch (e) {
|
|
275
|
-
const wrappedError = this.wrapError(e);
|
|
276
|
-
if (wrappedError) {
|
|
277
|
-
reject(wrappedError);
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
resolve(result);
|
|
282
|
-
};
|
|
283
|
-
try {
|
|
284
|
-
msalNodeRuntime.msalNodeRuntime.ReadAccountByIdAsync(accountId, correlationId, resultCallback);
|
|
285
|
-
}
|
|
286
|
-
catch (e) {
|
|
287
|
-
const wrappedError = this.wrapError(e);
|
|
288
|
-
if (wrappedError) {
|
|
289
|
-
reject(wrappedError);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
generateRequestParameters(request) {
|
|
295
|
-
this.logger.trace("NativeBrokerPlugin - generateRequestParameters called", request.correlationId);
|
|
296
|
-
const authParams = new msalNodeRuntime.msalNodeRuntime.AuthParameters();
|
|
297
|
-
try {
|
|
298
|
-
authParams.CreateAuthParameters(request.clientId, request.authority);
|
|
299
|
-
authParams.SetRedirectUri(request.redirectUri);
|
|
300
|
-
authParams.SetRequestedScopes(request.scopes.join(" "));
|
|
301
|
-
if (request.claims) {
|
|
302
|
-
authParams.SetDecodedClaims(request.claims);
|
|
303
|
-
}
|
|
304
|
-
if (request.authenticationScheme === msalCommon.AuthenticationScheme.POP) {
|
|
305
|
-
if (!request.resourceRequestMethod ||
|
|
306
|
-
!request.resourceRequestUri ||
|
|
307
|
-
!request.shrNonce) {
|
|
308
|
-
throw new Error("Authentication Scheme set to POP but one or more of the following parameters are missing: resourceRequestMethod, resourceRequestUri, shrNonce");
|
|
309
|
-
}
|
|
310
|
-
const resourceUrl = new URL(request.resourceRequestUri);
|
|
311
|
-
authParams.SetPopParams(request.resourceRequestMethod, resourceUrl.host, resourceUrl.pathname, request.shrNonce);
|
|
312
|
-
}
|
|
313
|
-
if (request.extraParameters) {
|
|
314
|
-
Object.entries(request.extraParameters).forEach(([key, value]) => {
|
|
315
|
-
authParams.SetAdditionalParameter(key, value);
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
const skus = request.extraParameters &&
|
|
319
|
-
request.extraParameters[msalCommon.AADServerParamKeys.X_CLIENT_EXTRA_SKU]
|
|
320
|
-
?.length
|
|
321
|
-
? request.extraParameters[msalCommon.AADServerParamKeys.X_CLIENT_EXTRA_SKU]
|
|
322
|
-
: "";
|
|
323
|
-
authParams.SetAdditionalParameter(msalCommon.AADServerParamKeys.X_CLIENT_EXTRA_SKU, msalCommon.ServerTelemetryManager.makeExtraSkuString({
|
|
324
|
-
skus,
|
|
325
|
-
extensionName: "msal.node.ext",
|
|
326
|
-
extensionVersion: packageMetadata.version,
|
|
327
|
-
}));
|
|
328
|
-
}
|
|
329
|
-
catch (e) {
|
|
330
|
-
const wrappedError = this.wrapError(e);
|
|
331
|
-
if (wrappedError) {
|
|
332
|
-
throw wrappedError;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return authParams;
|
|
336
|
-
}
|
|
337
|
-
getAuthenticationResult(request, authResult) {
|
|
338
|
-
this.logger.trace("NativeBrokerPlugin - getAuthenticationResult called", request.correlationId);
|
|
339
|
-
let fromCache = false;
|
|
340
|
-
try {
|
|
341
|
-
const telemetryJSON = JSON.parse(authResult.telemetryData);
|
|
342
|
-
fromCache = !!telemetryJSON["is_cache"];
|
|
343
|
-
}
|
|
344
|
-
catch (e) {
|
|
345
|
-
this.logger.error("NativeBrokerPlugin: getAuthenticationResult - Error parsing telemetry data. Could not determine if response came from cache.", request.correlationId);
|
|
346
|
-
}
|
|
347
|
-
let idTokenClaims;
|
|
348
|
-
try {
|
|
349
|
-
idTokenClaims = JSON.parse(authResult.idToken);
|
|
350
|
-
}
|
|
351
|
-
catch (e) {
|
|
352
|
-
throw new Error("Unable to parse idToken claims");
|
|
353
|
-
}
|
|
354
|
-
const accountInfo = this.generateAccountInfo(authResult.account, idTokenClaims);
|
|
355
|
-
const result = {
|
|
356
|
-
authority: request.authority,
|
|
357
|
-
uniqueId: idTokenClaims.oid || idTokenClaims.sub || "",
|
|
358
|
-
tenantId: idTokenClaims.tid || "",
|
|
359
|
-
scopes: authResult.grantedScopes.split(" "),
|
|
360
|
-
account: accountInfo,
|
|
361
|
-
idToken: authResult.rawIdToken,
|
|
362
|
-
idTokenClaims: idTokenClaims,
|
|
363
|
-
accessToken: authResult.accessToken,
|
|
364
|
-
fromCache: fromCache,
|
|
365
|
-
expiresOn: new Date(authResult.expiresOn),
|
|
366
|
-
tokenType: authResult.isPopAuthorization
|
|
367
|
-
? msalCommon.AuthenticationScheme.POP
|
|
368
|
-
: msalCommon.AuthenticationScheme.BEARER,
|
|
369
|
-
correlationId: request.correlationId,
|
|
370
|
-
fromNativeBroker: true,
|
|
371
|
-
};
|
|
372
|
-
return result;
|
|
373
|
-
}
|
|
374
|
-
generateAccountInfo(account, idTokenClaims) {
|
|
375
|
-
this.logger.trace("NativeBrokerPlugin - generateAccountInfo called");
|
|
376
|
-
const accountInfo = {
|
|
377
|
-
homeAccountId: account.homeAccountId,
|
|
378
|
-
environment: account.environment,
|
|
379
|
-
tenantId: account.realm,
|
|
380
|
-
username: account.username,
|
|
381
|
-
localAccountId: account.localAccountId,
|
|
382
|
-
name: account.displayName,
|
|
383
|
-
idTokenClaims: idTokenClaims,
|
|
384
|
-
nativeAccountId: account.accountId,
|
|
385
|
-
};
|
|
386
|
-
return accountInfo;
|
|
387
|
-
}
|
|
388
|
-
isMsalRuntimeError(result) {
|
|
389
|
-
return (result.hasOwnProperty("errorCode") ||
|
|
390
|
-
result.hasOwnProperty("errorStatus") ||
|
|
391
|
-
result.hasOwnProperty("errorContext") ||
|
|
392
|
-
result.hasOwnProperty("errorTag"));
|
|
393
|
-
}
|
|
394
|
-
wrapError(error) {
|
|
395
|
-
if (error &&
|
|
396
|
-
typeof error === "object" &&
|
|
397
|
-
this.isMsalRuntimeError(error)) {
|
|
398
|
-
const { errorCode, errorStatus, errorContext, errorTag } = error;
|
|
399
|
-
switch (errorStatus) {
|
|
400
|
-
case msalNodeRuntime.ErrorStatus.InteractionRequired:
|
|
401
|
-
case msalNodeRuntime.ErrorStatus.AccountUnusable:
|
|
402
|
-
return new msalCommon.InteractionRequiredAuthError(Constants.ErrorCodes.INTERATION_REQUIRED_ERROR_CODE, errorContext);
|
|
403
|
-
case msalNodeRuntime.ErrorStatus.NoNetwork:
|
|
404
|
-
case msalNodeRuntime.ErrorStatus.NetworkTemporarilyUnavailable:
|
|
405
|
-
return msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.noNetworkConnectivity);
|
|
406
|
-
case msalNodeRuntime.ErrorStatus.ServerTemporarilyUnavailable:
|
|
407
|
-
return new msalCommon.ServerError(Constants.ErrorCodes.SERVER_UNAVAILABLE, errorContext);
|
|
408
|
-
case msalNodeRuntime.ErrorStatus.UserCanceled:
|
|
409
|
-
return msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.userCanceled);
|
|
410
|
-
case msalNodeRuntime.ErrorStatus.AuthorityUntrusted:
|
|
411
|
-
return msalCommon.createClientConfigurationError(msalCommon.ClientConfigurationErrorCodes.untrustedAuthority);
|
|
412
|
-
case msalNodeRuntime.ErrorStatus.UserSwitched:
|
|
413
|
-
// Not an error case, if there's customer demand we can surface this as a response property
|
|
414
|
-
return null;
|
|
415
|
-
case msalNodeRuntime.ErrorStatus.AccountNotFound:
|
|
416
|
-
return msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.noAccountFound);
|
|
417
|
-
default:
|
|
418
|
-
return new NativeAuthError.NativeAuthError(msalNodeRuntime.ErrorStatus[errorStatus], errorContext, errorCode, errorTag);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
throw error;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
exports.NativeBrokerPlugin = NativeBrokerPlugin;
|
|
426
|
-
//# sourceMappingURL=NativeBrokerPlugin.cjs.map
|