@azure/identity-cache-persistence 1.1.2-alpha.20241204.3 → 1.1.2-alpha.20241206.3
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/{types/identity-cache-persistence.d.ts → dist/browser/index.d.ts} +29 -31
- package/dist/browser/index.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/index.js +1 -1
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/package.json +3 -0
- package/dist/browser/platforms.d.ts +51 -0
- package/dist/browser/platforms.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/platforms.js +1 -1
- package/dist/browser/platforms.js.map +1 -0
- package/dist/browser/provider.d.ts +12 -0
- package/dist/browser/provider.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/provider.js +1 -1
- package/dist/browser/provider.js.map +1 -0
- package/dist/commonjs/index.d.ts +29 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +38 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/platforms.d.ts +51 -0
- package/dist/commonjs/platforms.d.ts.map +1 -0
- package/dist/commonjs/platforms.js +111 -0
- package/dist/commonjs/platforms.js.map +1 -0
- package/dist/commonjs/provider.d.ts +12 -0
- package/dist/commonjs/provider.d.ts.map +1 -0
- package/dist/commonjs/provider.js +35 -0
- package/dist/commonjs/provider.js.map +1 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -0
- package/dist/esm/index.d.ts +29 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/platforms.d.ts +51 -0
- package/dist/esm/platforms.d.ts.map +1 -0
- package/dist/esm/platforms.js +108 -0
- package/dist/esm/platforms.js.map +1 -0
- package/dist/esm/provider.d.ts +12 -0
- package/dist/esm/provider.d.ts.map +1 -0
- package/dist/esm/provider.js +31 -0
- package/dist/esm/provider.js.map +1 -0
- package/dist/react-native/index.d.ts +29 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +34 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/platforms.d.ts +51 -0
- package/dist/react-native/platforms.d.ts.map +1 -0
- package/dist/react-native/platforms.js +108 -0
- package/dist/react-native/platforms.js.map +1 -0
- package/dist/react-native/provider.d.ts +12 -0
- package/dist/react-native/provider.d.ts.map +1 -0
- package/dist/react-native/provider.js +31 -0
- package/dist/react-native/provider.js.map +1 -0
- package/package.json +60 -30
- package/dist/index.js +0 -194
- package/dist/index.js.map +0 -1
- package/dist-esm/src/index.js.map +0 -1
- package/dist-esm/src/platforms.js.map +0 -1
- package/dist-esm/src/provider.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAuB7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAmB,CAAC,OAAO,EAAE,EAAE;IAChE,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAA6B,CAAC;IAE7D,kBAAkB,CAAC,cAAc,CAAC,4BAA4B,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { IdentityPlugin, TokenCachePersistenceOptions } from \"@azure/identity\";\nimport { createPersistenceCachePlugin } from \"./provider.js\";\n\n/**\n * Plugin context entries for controlling cache plugins.\n */\ninterface CachePluginControl {\n setPersistence(\n persistenceFactory: (\n options?: TokenCachePersistenceOptions,\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\n ) => Promise<import(\"@azure/msal-node\").ICachePlugin>,\n ): void;\n}\n/**\n * Context options passed to a plugin during initialization.\n *\n * Represents a subset of the context defined in `@azure/identity`\n *\n */\ninterface AzurePluginContext {\n cachePluginControl: CachePluginControl;\n}\n\n/**\n * A plugin that provides persistent token caching for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * In order to enable this functionality, you must also pass\n * `tokenCachePersistenceOptions` to your credential constructors with an\n * `enabled` property set to true.\n *\n * Example:\n *\n * ```ts snippet:device_code_credential_example\n * import { DeviceCodeCredential } from \"@azure/identity\";\n *\n * const credential = new DeviceCodeCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true,\n * },\n * });\n * // We'll use the Microsoft Graph scope as an example\n * const scope = \"https://graph.microsoft.com/.default\";\n * // Print out part of the access token\n * console.log((await credential.getToken(scope)).token.substring(0, 10), \"...\");\n * ```\n */\n\nexport const cachePersistencePlugin: IdentityPlugin = (context) => {\n const { cachePluginControl } = context as AzurePluginContext;\n\n cachePluginControl.setPersistence(createPersistenceCachePlugin);\n};\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { IPersistence as Persistence } from "@azure/msal-node-extensions";
|
|
2
|
+
import type { TokenCachePersistenceOptions } from "@azure/identity";
|
|
3
|
+
/**
|
|
4
|
+
* Dictionary of values that we use as default as we discover, pick and enable the persistence layer.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare const defaultMsalValues: {
|
|
8
|
+
tokenCache: {
|
|
9
|
+
name: string;
|
|
10
|
+
directory: string;
|
|
11
|
+
};
|
|
12
|
+
keyRing: {
|
|
13
|
+
label: string;
|
|
14
|
+
schema: string;
|
|
15
|
+
collection: string;
|
|
16
|
+
attributes: {
|
|
17
|
+
MsalClientID: string;
|
|
18
|
+
"Microsoft.Developer.IdentityService": string;
|
|
19
|
+
};
|
|
20
|
+
service: string;
|
|
21
|
+
account: string;
|
|
22
|
+
};
|
|
23
|
+
keyChain: {
|
|
24
|
+
service: string;
|
|
25
|
+
account: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Options that are used by the underlying MSAL cache provider.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export type MsalPersistenceOptions = Omit<TokenCachePersistenceOptions, "enabled">;
|
|
33
|
+
/**
|
|
34
|
+
* A function that returns a persistent token cache instance.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
type MsalPersistenceFactory = (options?: MsalPersistenceOptions) => Promise<Persistence>;
|
|
38
|
+
/**
|
|
39
|
+
* Set of the platforms we attempt to deliver persistence on.
|
|
40
|
+
*
|
|
41
|
+
* - On Windows we use DPAPI.
|
|
42
|
+
* - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
|
|
43
|
+
* - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
|
|
44
|
+
*
|
|
45
|
+
* Other platforms _are not supported_ at this time.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export declare const msalPersistencePlatforms: Partial<Record<NodeJS.Platform, MsalPersistenceFactory>>;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=platforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platforms.d.ts","sourceRoot":"","sources":["../../src/platforms.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAQ/E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAapE;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;CAwB7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;AAEnF;;;GAGG;AACH,KAAK,sBAAsB,GAAG,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAazF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CA8C7F,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
var _a, _b, _c;
|
|
4
|
+
import { __awaiter } from "tslib";
|
|
5
|
+
/* eslint-disable tsdoc/syntax */
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { DataProtectionScope, FilePersistence, FilePersistenceWithDataProtection, KeychainPersistence, LibSecretPersistence, } from "@azure/msal-node-extensions";
|
|
8
|
+
/**
|
|
9
|
+
* Local application data folder
|
|
10
|
+
* Expected values:
|
|
11
|
+
* - Darwin: '/Users/user/'
|
|
12
|
+
* - Windows 8+: 'C:\Users\user\AppData\Local'
|
|
13
|
+
* - Linux: '/home/user/.local/share'
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
const localApplicationDataFolder = (_c = (_b = (_a = process.env.APPDATA) === null || _a === void 0 ? void 0 : _a.replace) === null || _b === void 0 ? void 0 : _b.call(_a, /(.Roaming)*$/, "\\Local")) !== null && _c !== void 0 ? _c : process.env.HOME;
|
|
17
|
+
/**
|
|
18
|
+
* Dictionary of values that we use as default as we discover, pick and enable the persistence layer.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export const defaultMsalValues = {
|
|
22
|
+
tokenCache: {
|
|
23
|
+
name: "msal.cache",
|
|
24
|
+
// Expected values:
|
|
25
|
+
// - Darwin: '/Users/user/.IdentityService'
|
|
26
|
+
// - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService'
|
|
27
|
+
// - Linux: '/home/user/.IdentityService'
|
|
28
|
+
directory: path.join(localApplicationDataFolder, ".IdentityService"),
|
|
29
|
+
},
|
|
30
|
+
keyRing: {
|
|
31
|
+
label: "MSALCache",
|
|
32
|
+
schema: "msal.cache",
|
|
33
|
+
collection: "default",
|
|
34
|
+
attributes: {
|
|
35
|
+
MsalClientID: "Microsoft.Developer.IdentityService",
|
|
36
|
+
"Microsoft.Developer.IdentityService": "1.0.0.0",
|
|
37
|
+
},
|
|
38
|
+
service: "Microsoft.Developer.IdentityService",
|
|
39
|
+
account: "MSALCache",
|
|
40
|
+
},
|
|
41
|
+
keyChain: {
|
|
42
|
+
service: "Microsoft.Developer.IdentityService",
|
|
43
|
+
account: "MSALCache",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Expected responses:
|
|
48
|
+
* - Darwin: '/Users/user/.IdentityService/<name>'
|
|
49
|
+
* - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService\<name>'
|
|
50
|
+
* - Linux: '/home/user/.IdentityService/<name>'
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
function getPersistencePath(name) {
|
|
54
|
+
return path.join(defaultMsalValues.tokenCache.directory, name);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Set of the platforms we attempt to deliver persistence on.
|
|
58
|
+
*
|
|
59
|
+
* - On Windows we use DPAPI.
|
|
60
|
+
* - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
|
|
61
|
+
* - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
|
|
62
|
+
*
|
|
63
|
+
* Other platforms _are not supported_ at this time.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export const msalPersistencePlatforms = {
|
|
68
|
+
win32: ({ name = defaultMsalValues.tokenCache.name } = {}) => FilePersistenceWithDataProtection.create(getPersistencePath(name), DataProtectionScope.CurrentUser),
|
|
69
|
+
darwin: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (options = {}) {
|
|
70
|
+
const { name, unsafeAllowUnencryptedStorage } = options;
|
|
71
|
+
const { service, account } = defaultMsalValues.keyChain;
|
|
72
|
+
const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
|
|
73
|
+
try {
|
|
74
|
+
const persistence = yield KeychainPersistence.create(persistencePath, service, account);
|
|
75
|
+
// If we don't encounter an error when trying to read from the keychain, then we should be good to go.
|
|
76
|
+
yield persistence.load();
|
|
77
|
+
return persistence;
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
// If we got an error while trying to read from the keyring,
|
|
81
|
+
// we will proceed only if the user has specified that unencrypted storage is allowed.
|
|
82
|
+
if (!unsafeAllowUnencryptedStorage) {
|
|
83
|
+
throw new Error("Unable to read from the macOS Keychain.");
|
|
84
|
+
}
|
|
85
|
+
return FilePersistence.create(persistencePath);
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
linux: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (options = {}) {
|
|
89
|
+
const { name, unsafeAllowUnencryptedStorage } = options;
|
|
90
|
+
const { service, account } = defaultMsalValues.keyRing;
|
|
91
|
+
const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
|
|
92
|
+
try {
|
|
93
|
+
const persistence = yield LibSecretPersistence.create(persistencePath, service, account);
|
|
94
|
+
// If we don't encounter an error when trying to read from the keyring, then we should be good to go.
|
|
95
|
+
yield persistence.load();
|
|
96
|
+
return persistence;
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
// If we got an error while trying to read from the keyring,
|
|
100
|
+
// we will proceed only if the user has specified that unencrypted storage is allowed.
|
|
101
|
+
if (!unsafeAllowUnencryptedStorage) {
|
|
102
|
+
throw new Error("Unable to read from the system keyring (libsecret).");
|
|
103
|
+
}
|
|
104
|
+
return FilePersistence.create(persistencePath);
|
|
105
|
+
}
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=platforms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platforms.js","sourceRoot":"","sources":["../../src/platforms.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,iCAAiC;AAEjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AAGrC;;;;;;;GAOG;AACH,MAAM,0BAA0B,GAC9B,MAAA,MAAA,MAAA,OAAO,CAAC,GAAG,CAAC,OAAO,0CAAE,OAAO,mDAAG,cAAc,EAAE,SAAS,CAAC,mCAAI,OAAO,CAAC,GAAG,CAAC,IAAK,CAAC;AAEjF;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,UAAU,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,mBAAmB;QACnB,2CAA2C;QAC3C,+DAA+D;QAC/D,yCAAyC;QACzC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE,kBAAkB,CAAC;KACrE;IACD,OAAO,EAAE;QACP,KAAK,EAAE,WAAW;QAClB,MAAM,EAAE,YAAY;QACpB,UAAU,EAAE,SAAS;QACrB,UAAU,EAAE;YACV,YAAY,EAAE,qCAAqC;YACnD,qCAAqC,EAAE,SAAS;SACjD;QACD,OAAO,EAAE,qCAAqC;QAC9C,OAAO,EAAE,WAAW;KACrB;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,qCAAqC;QAC9C,OAAO,EAAE,WAAW;KACrB;CACF,CAAC;AAcF;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,SAAS,EA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,eAAe,GAAG,kBAAkB,CAAC,IAAI,IAAI,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEtF,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACzF,qGAAqG;YACrG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;YACzB,OAAO,WAAW,CAAC;QACrB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,4DAA4D;YAC5D,sFAAsF;YACtF,IAAI,CAAC,6BAA6B,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;YACzE,CAAC;YACD,OAAO,eAAe,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACjD,CAAC;IACH,CAAC,CAAA;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable tsdoc/syntax */\n\nimport path from \"node:path\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport {\n DataProtectionScope,\n FilePersistence,\n FilePersistenceWithDataProtection,\n KeychainPersistence,\n LibSecretPersistence,\n} from \"@azure/msal-node-extensions\";\nimport type { TokenCachePersistenceOptions } from \"@azure/identity\";\n\n/**\n * Local application data folder\n * Expected values:\n * - Darwin: '/Users/user/'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local'\n * - Linux: '/home/user/.local/share'\n * @internal\n */\nconst localApplicationDataFolder =\n process.env.APPDATA?.replace?.(/(.Roaming)*$/, \"\\\\Local\") ?? process.env.HOME!;\n\n/**\n * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.\n * @internal\n */\nexport const defaultMsalValues = {\n tokenCache: {\n name: \"msal.cache\",\n // Expected values:\n // - Darwin: '/Users/user/.IdentityService'\n // - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService'\n // - Linux: '/home/user/.IdentityService'\n directory: path.join(localApplicationDataFolder, \".IdentityService\"),\n },\n keyRing: {\n label: \"MSALCache\",\n schema: \"msal.cache\",\n collection: \"default\",\n attributes: {\n MsalClientID: \"Microsoft.Developer.IdentityService\",\n \"Microsoft.Developer.IdentityService\": \"1.0.0.0\",\n },\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n keyChain: {\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n};\n\n/**\n * Options that are used by the underlying MSAL cache provider.\n * @internal\n */\nexport type MsalPersistenceOptions = Omit<TokenCachePersistenceOptions, \"enabled\">;\n\n/**\n * A function that returns a persistent token cache instance.\n * @internal\n */\ntype MsalPersistenceFactory = (options?: MsalPersistenceOptions) => Promise<Persistence>;\n\n/**\n * Expected responses:\n * - Darwin: '/Users/user/.IdentityService/<name>'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService\\<name>'\n * - Linux: '/home/user/.IdentityService/<name>'\n * @internal\n */\nfunction getPersistencePath(name: string): string {\n return path.join(defaultMsalValues.tokenCache.directory, name);\n}\n\n/**\n * Set of the platforms we attempt to deliver persistence on.\n *\n * - On Windows we use DPAPI.\n * - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n *\n * Other platforms _are not supported_ at this time.\n *\n * @internal\n */\nexport const msalPersistencePlatforms: Partial<Record<NodeJS.Platform, MsalPersistenceFactory>> = {\n win32: ({ name = defaultMsalValues.tokenCache.name } = {}): Promise<Persistence> =>\n FilePersistenceWithDataProtection.create(\n getPersistencePath(name),\n DataProtectionScope.CurrentUser,\n ),\n\n darwin: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyChain;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await KeychainPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keychain, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the macOS Keychain.\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n\n linux: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyRing;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await LibSecretPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keyring, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the system keyring (libsecret).\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MsalPersistenceOptions } from "./platforms.js";
|
|
2
|
+
import type { IPersistence as Persistence } from "@azure/msal-node-extensions";
|
|
3
|
+
import type { ICachePlugin as CachePlugin } from "@azure/msal-node";
|
|
4
|
+
/**
|
|
5
|
+
* This is used to gain access to the underlying Persistence instance, which we use for testing
|
|
6
|
+
*
|
|
7
|
+
* @returns a raw persistence instance
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function createPersistence(options: MsalPersistenceOptions): Promise<Persistence>;
|
|
11
|
+
export declare function createPersistenceCachePlugin(options?: MsalPersistenceOptions): Promise<CachePlugin>;
|
|
12
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/E,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC,CAQ7F;AAED,wBAAsB,4BAA4B,CAChD,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,WAAW,CAAC,CAOtB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { __awaiter } from "tslib";
|
|
4
|
+
import { msalPersistencePlatforms } from "./platforms.js";
|
|
5
|
+
import { PersistenceCachePlugin } from "@azure/msal-node-extensions";
|
|
6
|
+
/**
|
|
7
|
+
* This is used to gain access to the underlying Persistence instance, which we use for testing
|
|
8
|
+
*
|
|
9
|
+
* @returns a raw persistence instance
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export function createPersistence(options) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
var _a;
|
|
15
|
+
const persistence = yield ((_a = msalPersistencePlatforms[process.platform]) === null || _a === void 0 ? void 0 : _a.call(msalPersistencePlatforms, options));
|
|
16
|
+
if (persistence === undefined) {
|
|
17
|
+
throw new Error("no persistence providers are available on this platform");
|
|
18
|
+
}
|
|
19
|
+
return persistence;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function createPersistenceCachePlugin(options) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const persistence = yield createPersistence(options !== null && options !== void 0 ? options : {});
|
|
25
|
+
return new PersistenceCachePlugin(persistence, {
|
|
26
|
+
retryNumber: 100,
|
|
27
|
+
retryDelay: 50,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE;;;;;GAKG;AACH,MAAM,UAAgB,iBAAiB,CAAC,OAA+B;;;QACrE,MAAM,WAAW,GAAG,MAAM,CAAA,MAAA,wBAAwB,CAAC,OAAO,CAAC,QAAQ,CAAC,yEAAG,OAAO,CAAC,CAAA,CAAC;QAEhF,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CAAA;AAED,MAAM,UAAgB,4BAA4B,CAChD,OAAgC;;QAEhC,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,CAAC;QAE3D,OAAO,IAAI,sBAAsB,CAAC,WAAW,EAAE;YAC7C,WAAW,EAAE,GAAG;YAChB,UAAU,EAAE,EAAE;SACf,CAAC,CAAC;IACL,CAAC;CAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MsalPersistenceOptions } from \"./platforms.js\";\nimport { msalPersistencePlatforms } from \"./platforms.js\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport { PersistenceCachePlugin } from \"@azure/msal-node-extensions\";\nimport type { ICachePlugin as CachePlugin } from \"@azure/msal-node\";\n\n/**\n * This is used to gain access to the underlying Persistence instance, which we use for testing\n *\n * @returns a raw persistence instance\n * @internal\n */\nexport async function createPersistence(options: MsalPersistenceOptions): Promise<Persistence> {\n const persistence = await msalPersistencePlatforms[process.platform]?.(options);\n\n if (persistence === undefined) {\n throw new Error(\"no persistence providers are available on this platform\");\n }\n\n return persistence;\n}\n\nexport async function createPersistenceCachePlugin(\n options?: MsalPersistenceOptions,\n): Promise<CachePlugin> {\n const persistence = await createPersistence(options ?? {});\n\n return new PersistenceCachePlugin(persistence, {\n retryNumber: 100,\n retryDelay: 50,\n });\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IdentityPlugin } from "@azure/identity";
|
|
2
|
+
/**
|
|
3
|
+
* A plugin that provides persistent token caching for `@azure/identity`
|
|
4
|
+
* credentials. The plugin API is compatible with `@azure/identity` versions
|
|
5
|
+
* 2.0.0 and later. Load this plugin using the `useIdentityPlugin`
|
|
6
|
+
* function, imported from `@azure/identity`.
|
|
7
|
+
*
|
|
8
|
+
* In order to enable this functionality, you must also pass
|
|
9
|
+
* `tokenCachePersistenceOptions` to your credential constructors with an
|
|
10
|
+
* `enabled` property set to true.
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
*
|
|
14
|
+
* ```ts snippet:device_code_credential_example
|
|
15
|
+
* import { DeviceCodeCredential } from "@azure/identity";
|
|
16
|
+
*
|
|
17
|
+
* const credential = new DeviceCodeCredential({
|
|
18
|
+
* tokenCachePersistenceOptions: {
|
|
19
|
+
* enabled: true,
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
* // We'll use the Microsoft Graph scope as an example
|
|
23
|
+
* const scope = "https://graph.microsoft.com/.default";
|
|
24
|
+
* // Print out part of the access token
|
|
25
|
+
* console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const cachePersistencePlugin: IdentityPlugin;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAgC,MAAM,iBAAiB,CAAC;AAwBpF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,eAAO,MAAM,sBAAsB,EAAE,cAIpC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { createPersistenceCachePlugin } from "./provider.js";
|
|
4
|
+
/**
|
|
5
|
+
* A plugin that provides persistent token caching for `@azure/identity`
|
|
6
|
+
* credentials. The plugin API is compatible with `@azure/identity` versions
|
|
7
|
+
* 2.0.0 and later. Load this plugin using the `useIdentityPlugin`
|
|
8
|
+
* function, imported from `@azure/identity`.
|
|
9
|
+
*
|
|
10
|
+
* In order to enable this functionality, you must also pass
|
|
11
|
+
* `tokenCachePersistenceOptions` to your credential constructors with an
|
|
12
|
+
* `enabled` property set to true.
|
|
13
|
+
*
|
|
14
|
+
* Example:
|
|
15
|
+
*
|
|
16
|
+
* ```ts snippet:device_code_credential_example
|
|
17
|
+
* import { DeviceCodeCredential } from "@azure/identity";
|
|
18
|
+
*
|
|
19
|
+
* const credential = new DeviceCodeCredential({
|
|
20
|
+
* tokenCachePersistenceOptions: {
|
|
21
|
+
* enabled: true,
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* // We'll use the Microsoft Graph scope as an example
|
|
25
|
+
* const scope = "https://graph.microsoft.com/.default";
|
|
26
|
+
* // Print out part of the access token
|
|
27
|
+
* console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export const cachePersistencePlugin = (context) => {
|
|
31
|
+
const { cachePluginControl } = context;
|
|
32
|
+
cachePluginControl.setPersistence(createPersistenceCachePlugin);
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAuB7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAmB,CAAC,OAAO,EAAE,EAAE;IAChE,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAA6B,CAAC;IAE7D,kBAAkB,CAAC,cAAc,CAAC,4BAA4B,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { IdentityPlugin, TokenCachePersistenceOptions } from \"@azure/identity\";\nimport { createPersistenceCachePlugin } from \"./provider.js\";\n\n/**\n * Plugin context entries for controlling cache plugins.\n */\ninterface CachePluginControl {\n setPersistence(\n persistenceFactory: (\n options?: TokenCachePersistenceOptions,\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\n ) => Promise<import(\"@azure/msal-node\").ICachePlugin>,\n ): void;\n}\n/**\n * Context options passed to a plugin during initialization.\n *\n * Represents a subset of the context defined in `@azure/identity`\n *\n */\ninterface AzurePluginContext {\n cachePluginControl: CachePluginControl;\n}\n\n/**\n * A plugin that provides persistent token caching for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * In order to enable this functionality, you must also pass\n * `tokenCachePersistenceOptions` to your credential constructors with an\n * `enabled` property set to true.\n *\n * Example:\n *\n * ```ts snippet:device_code_credential_example\n * import { DeviceCodeCredential } from \"@azure/identity\";\n *\n * const credential = new DeviceCodeCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true,\n * },\n * });\n * // We'll use the Microsoft Graph scope as an example\n * const scope = \"https://graph.microsoft.com/.default\";\n * // Print out part of the access token\n * console.log((await credential.getToken(scope)).token.substring(0, 10), \"...\");\n * ```\n */\n\nexport const cachePersistencePlugin: IdentityPlugin = (context) => {\n const { cachePluginControl } = context as AzurePluginContext;\n\n cachePluginControl.setPersistence(createPersistenceCachePlugin);\n};\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { IPersistence as Persistence } from "@azure/msal-node-extensions";
|
|
2
|
+
import type { TokenCachePersistenceOptions } from "@azure/identity";
|
|
3
|
+
/**
|
|
4
|
+
* Dictionary of values that we use as default as we discover, pick and enable the persistence layer.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare const defaultMsalValues: {
|
|
8
|
+
tokenCache: {
|
|
9
|
+
name: string;
|
|
10
|
+
directory: string;
|
|
11
|
+
};
|
|
12
|
+
keyRing: {
|
|
13
|
+
label: string;
|
|
14
|
+
schema: string;
|
|
15
|
+
collection: string;
|
|
16
|
+
attributes: {
|
|
17
|
+
MsalClientID: string;
|
|
18
|
+
"Microsoft.Developer.IdentityService": string;
|
|
19
|
+
};
|
|
20
|
+
service: string;
|
|
21
|
+
account: string;
|
|
22
|
+
};
|
|
23
|
+
keyChain: {
|
|
24
|
+
service: string;
|
|
25
|
+
account: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Options that are used by the underlying MSAL cache provider.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export type MsalPersistenceOptions = Omit<TokenCachePersistenceOptions, "enabled">;
|
|
33
|
+
/**
|
|
34
|
+
* A function that returns a persistent token cache instance.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
type MsalPersistenceFactory = (options?: MsalPersistenceOptions) => Promise<Persistence>;
|
|
38
|
+
/**
|
|
39
|
+
* Set of the platforms we attempt to deliver persistence on.
|
|
40
|
+
*
|
|
41
|
+
* - On Windows we use DPAPI.
|
|
42
|
+
* - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
|
|
43
|
+
* - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
|
|
44
|
+
*
|
|
45
|
+
* Other platforms _are not supported_ at this time.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export declare const msalPersistencePlatforms: Partial<Record<NodeJS.Platform, MsalPersistenceFactory>>;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=platforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platforms.d.ts","sourceRoot":"","sources":["../../src/platforms.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAQ/E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAapE;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;CAwB7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;AAEnF;;;GAGG;AACH,KAAK,sBAAsB,GAAG,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAazF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CA8C7F,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
var _a, _b, _c;
|
|
4
|
+
import { __awaiter } from "tslib";
|
|
5
|
+
/* eslint-disable tsdoc/syntax */
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { DataProtectionScope, FilePersistence, FilePersistenceWithDataProtection, KeychainPersistence, LibSecretPersistence, } from "@azure/msal-node-extensions";
|
|
8
|
+
/**
|
|
9
|
+
* Local application data folder
|
|
10
|
+
* Expected values:
|
|
11
|
+
* - Darwin: '/Users/user/'
|
|
12
|
+
* - Windows 8+: 'C:\Users\user\AppData\Local'
|
|
13
|
+
* - Linux: '/home/user/.local/share'
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
const localApplicationDataFolder = (_c = (_b = (_a = process.env.APPDATA) === null || _a === void 0 ? void 0 : _a.replace) === null || _b === void 0 ? void 0 : _b.call(_a, /(.Roaming)*$/, "\\Local")) !== null && _c !== void 0 ? _c : process.env.HOME;
|
|
17
|
+
/**
|
|
18
|
+
* Dictionary of values that we use as default as we discover, pick and enable the persistence layer.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export const defaultMsalValues = {
|
|
22
|
+
tokenCache: {
|
|
23
|
+
name: "msal.cache",
|
|
24
|
+
// Expected values:
|
|
25
|
+
// - Darwin: '/Users/user/.IdentityService'
|
|
26
|
+
// - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService'
|
|
27
|
+
// - Linux: '/home/user/.IdentityService'
|
|
28
|
+
directory: path.join(localApplicationDataFolder, ".IdentityService"),
|
|
29
|
+
},
|
|
30
|
+
keyRing: {
|
|
31
|
+
label: "MSALCache",
|
|
32
|
+
schema: "msal.cache",
|
|
33
|
+
collection: "default",
|
|
34
|
+
attributes: {
|
|
35
|
+
MsalClientID: "Microsoft.Developer.IdentityService",
|
|
36
|
+
"Microsoft.Developer.IdentityService": "1.0.0.0",
|
|
37
|
+
},
|
|
38
|
+
service: "Microsoft.Developer.IdentityService",
|
|
39
|
+
account: "MSALCache",
|
|
40
|
+
},
|
|
41
|
+
keyChain: {
|
|
42
|
+
service: "Microsoft.Developer.IdentityService",
|
|
43
|
+
account: "MSALCache",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Expected responses:
|
|
48
|
+
* - Darwin: '/Users/user/.IdentityService/<name>'
|
|
49
|
+
* - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService\<name>'
|
|
50
|
+
* - Linux: '/home/user/.IdentityService/<name>'
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
function getPersistencePath(name) {
|
|
54
|
+
return path.join(defaultMsalValues.tokenCache.directory, name);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Set of the platforms we attempt to deliver persistence on.
|
|
58
|
+
*
|
|
59
|
+
* - On Windows we use DPAPI.
|
|
60
|
+
* - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
|
|
61
|
+
* - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
|
|
62
|
+
*
|
|
63
|
+
* Other platforms _are not supported_ at this time.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export const msalPersistencePlatforms = {
|
|
68
|
+
win32: ({ name = defaultMsalValues.tokenCache.name } = {}) => FilePersistenceWithDataProtection.create(getPersistencePath(name), DataProtectionScope.CurrentUser),
|
|
69
|
+
darwin: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (options = {}) {
|
|
70
|
+
const { name, unsafeAllowUnencryptedStorage } = options;
|
|
71
|
+
const { service, account } = defaultMsalValues.keyChain;
|
|
72
|
+
const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
|
|
73
|
+
try {
|
|
74
|
+
const persistence = yield KeychainPersistence.create(persistencePath, service, account);
|
|
75
|
+
// If we don't encounter an error when trying to read from the keychain, then we should be good to go.
|
|
76
|
+
yield persistence.load();
|
|
77
|
+
return persistence;
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
// If we got an error while trying to read from the keyring,
|
|
81
|
+
// we will proceed only if the user has specified that unencrypted storage is allowed.
|
|
82
|
+
if (!unsafeAllowUnencryptedStorage) {
|
|
83
|
+
throw new Error("Unable to read from the macOS Keychain.");
|
|
84
|
+
}
|
|
85
|
+
return FilePersistence.create(persistencePath);
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
linux: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (options = {}) {
|
|
89
|
+
const { name, unsafeAllowUnencryptedStorage } = options;
|
|
90
|
+
const { service, account } = defaultMsalValues.keyRing;
|
|
91
|
+
const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
|
|
92
|
+
try {
|
|
93
|
+
const persistence = yield LibSecretPersistence.create(persistencePath, service, account);
|
|
94
|
+
// If we don't encounter an error when trying to read from the keyring, then we should be good to go.
|
|
95
|
+
yield persistence.load();
|
|
96
|
+
return persistence;
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
// If we got an error while trying to read from the keyring,
|
|
100
|
+
// we will proceed only if the user has specified that unencrypted storage is allowed.
|
|
101
|
+
if (!unsafeAllowUnencryptedStorage) {
|
|
102
|
+
throw new Error("Unable to read from the system keyring (libsecret).");
|
|
103
|
+
}
|
|
104
|
+
return FilePersistence.create(persistencePath);
|
|
105
|
+
}
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=platforms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platforms.js","sourceRoot":"","sources":["../../src/platforms.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,iCAAiC;AAEjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AAGrC;;;;;;;GAOG;AACH,MAAM,0BAA0B,GAC9B,MAAA,MAAA,MAAA,OAAO,CAAC,GAAG,CAAC,OAAO,0CAA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eAAe,CAAC,CAAC;QACjD,CAAC;IACH,CAAC,CAAA;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable tsdoc/syntax */\n\nimport path from \"node:path\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport {\n DataProtectionScope,\n FilePersistence,\n FilePersistenceWithDataProtection,\n KeychainPersistence,\n LibSecretPersistence,\n} from \"@azure/msal-node-extensions\";\nimport type { TokenCachePersistenceOptions } from \"@azure/identity\";\n\n/**\n * Local application data folder\n * Expected values:\n * - Darwin: '/Users/user/'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local'\n * - Linux: '/home/user/.local/share'\n * @internal\n */\nconst localApplicationDataFolder =\n process.env.APPDATA?.replace?.(/(.Roaming)*$/, \"\\\\Local\") ?? process.env.HOME!;\n\n/**\n * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.\n * @internal\n */\nexport const defaultMsalValues = {\n tokenCache: {\n name: \"msal.cache\",\n // Expected values:\n // - Darwin: '/Users/user/.IdentityService'\n // - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService'\n // - Linux: '/home/user/.IdentityService'\n directory: path.join(localApplicationDataFolder, \".IdentityService\"),\n },\n keyRing: {\n label: \"MSALCache\",\n schema: \"msal.cache\",\n collection: \"default\",\n attributes: {\n MsalClientID: \"Microsoft.Developer.IdentityService\",\n \"Microsoft.Developer.IdentityService\": \"1.0.0.0\",\n },\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n keyChain: {\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n};\n\n/**\n * Options that are used by the underlying MSAL cache provider.\n * @internal\n */\nexport type MsalPersistenceOptions = Omit<TokenCachePersistenceOptions, \"enabled\">;\n\n/**\n * A function that returns a persistent token cache instance.\n * @internal\n */\ntype MsalPersistenceFactory = (options?: MsalPersistenceOptions) => Promise<Persistence>;\n\n/**\n * Expected responses:\n * - Darwin: '/Users/user/.IdentityService/<name>'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService\\<name>'\n * - Linux: '/home/user/.IdentityService/<name>'\n * @internal\n */\nfunction getPersistencePath(name: string): string {\n return path.join(defaultMsalValues.tokenCache.directory, name);\n}\n\n/**\n * Set of the platforms we attempt to deliver persistence on.\n *\n * - On Windows we use DPAPI.\n * - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n *\n * Other platforms _are not supported_ at this time.\n *\n * @internal\n */\nexport const msalPersistencePlatforms: Partial<Record<NodeJS.Platform, MsalPersistenceFactory>> = {\n win32: ({ name = defaultMsalValues.tokenCache.name } = {}): Promise<Persistence> =>\n FilePersistenceWithDataProtection.create(\n getPersistencePath(name),\n DataProtectionScope.CurrentUser,\n ),\n\n darwin: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyChain;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await KeychainPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keychain, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the macOS Keychain.\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n\n linux: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyRing;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await LibSecretPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keyring, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the system keyring (libsecret).\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MsalPersistenceOptions } from "./platforms.js";
|
|
2
|
+
import type { IPersistence as Persistence } from "@azure/msal-node-extensions";
|
|
3
|
+
import type { ICachePlugin as CachePlugin } from "@azure/msal-node";
|
|
4
|
+
/**
|
|
5
|
+
* This is used to gain access to the underlying Persistence instance, which we use for testing
|
|
6
|
+
*
|
|
7
|
+
* @returns a raw persistence instance
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function createPersistence(options: MsalPersistenceOptions): Promise<Persistence>;
|
|
11
|
+
export declare function createPersistenceCachePlugin(options?: MsalPersistenceOptions): Promise<CachePlugin>;
|
|
12
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/E,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC,CAQ7F;AAED,wBAAsB,4BAA4B,CAChD,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,WAAW,CAAC,CAOtB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { __awaiter } from "tslib";
|
|
4
|
+
import { msalPersistencePlatforms } from "./platforms.js";
|
|
5
|
+
import { PersistenceCachePlugin } from "@azure/msal-node-extensions";
|
|
6
|
+
/**
|
|
7
|
+
* This is used to gain access to the underlying Persistence instance, which we use for testing
|
|
8
|
+
*
|
|
9
|
+
* @returns a raw persistence instance
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export function createPersistence(options) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
var _a;
|
|
15
|
+
const persistence = yield ((_a = msalPersistencePlatforms[process.platform]) === null || _a === void 0 ? void 0 : _a.call(msalPersistencePlatforms, options));
|
|
16
|
+
if (persistence === undefined) {
|
|
17
|
+
throw new Error("no persistence providers are available on this platform");
|
|
18
|
+
}
|
|
19
|
+
return persistence;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function createPersistenceCachePlugin(options) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const persistence = yield createPersistence(options !== null && options !== void 0 ? options : {});
|
|
25
|
+
return new PersistenceCachePlugin(persistence, {
|
|
26
|
+
retryNumber: 100,
|
|
27
|
+
retryDelay: 50,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE;;;;;GAKG;AACH,MAAM,UAAgB,iBAAiB,CAAC,OAA+B;;;QACrE,MAAM,WAAW,GAAG,MAAM,CAAA,MAAA,wBAAwB,CAAC,OAAO,CAAC,QAAQ,CAAC,yEAAG,OAAO,CAAC,CAAA,CAAC;QAEhF,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CAAA;AAED,MAAM,UAAgB,4BAA4B,CAChD,OAAgC;;QAEhC,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,CAAC;QAE3D,OAAO,IAAI,sBAAsB,CAAC,WAAW,EAAE;YAC7C,WAAW,EAAE,GAAG;YAChB,UAAU,EAAE,EAAE;SACf,CAAC,CAAC;IACL,CAAC;CAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MsalPersistenceOptions } from \"./platforms.js\";\nimport { msalPersistencePlatforms } from \"./platforms.js\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport { PersistenceCachePlugin } from \"@azure/msal-node-extensions\";\nimport type { ICachePlugin as CachePlugin } from \"@azure/msal-node\";\n\n/**\n * This is used to gain access to the underlying Persistence instance, which we use for testing\n *\n * @returns a raw persistence instance\n * @internal\n */\nexport async function createPersistence(options: MsalPersistenceOptions): Promise<Persistence> {\n const persistence = await msalPersistencePlatforms[process.platform]?.(options);\n\n if (persistence === undefined) {\n throw new Error(\"no persistence providers are available on this platform\");\n }\n\n return persistence;\n}\n\nexport async function createPersistenceCachePlugin(\n options?: MsalPersistenceOptions,\n): Promise<CachePlugin> {\n const persistence = await createPersistence(options ?? {});\n\n return new PersistenceCachePlugin(persistence, {\n retryNumber: 100,\n retryDelay: 50,\n });\n}\n"]}
|