@azure/identity-cache-persistence 1.1.2-alpha.20241203.2 → 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.
Files changed (59) hide show
  1. package/{types/identity-cache-persistence.d.ts → dist/browser/index.d.ts} +29 -31
  2. package/dist/browser/index.d.ts.map +1 -0
  3. package/{dist-esm/src → dist/browser}/index.js +1 -1
  4. package/dist/browser/index.js.map +1 -0
  5. package/dist/browser/package.json +3 -0
  6. package/dist/browser/platforms.d.ts +51 -0
  7. package/dist/browser/platforms.d.ts.map +1 -0
  8. package/{dist-esm/src → dist/browser}/platforms.js +1 -1
  9. package/dist/browser/platforms.js.map +1 -0
  10. package/dist/browser/provider.d.ts +12 -0
  11. package/dist/browser/provider.d.ts.map +1 -0
  12. package/{dist-esm/src → dist/browser}/provider.js +1 -1
  13. package/dist/browser/provider.js.map +1 -0
  14. package/dist/commonjs/index.d.ts +29 -0
  15. package/dist/commonjs/index.d.ts.map +1 -0
  16. package/dist/commonjs/index.js +38 -0
  17. package/dist/commonjs/index.js.map +1 -0
  18. package/dist/commonjs/package.json +3 -0
  19. package/dist/commonjs/platforms.d.ts +51 -0
  20. package/dist/commonjs/platforms.d.ts.map +1 -0
  21. package/dist/commonjs/platforms.js +111 -0
  22. package/dist/commonjs/platforms.js.map +1 -0
  23. package/dist/commonjs/provider.d.ts +12 -0
  24. package/dist/commonjs/provider.d.ts.map +1 -0
  25. package/dist/commonjs/provider.js +35 -0
  26. package/dist/commonjs/provider.js.map +1 -0
  27. package/dist/commonjs/tsdoc-metadata.json +11 -0
  28. package/dist/esm/index.d.ts +29 -0
  29. package/dist/esm/index.d.ts.map +1 -0
  30. package/dist/esm/index.js +34 -0
  31. package/dist/esm/index.js.map +1 -0
  32. package/dist/esm/package.json +3 -0
  33. package/dist/esm/platforms.d.ts +51 -0
  34. package/dist/esm/platforms.d.ts.map +1 -0
  35. package/dist/esm/platforms.js +108 -0
  36. package/dist/esm/platforms.js.map +1 -0
  37. package/dist/esm/provider.d.ts +12 -0
  38. package/dist/esm/provider.d.ts.map +1 -0
  39. package/dist/esm/provider.js +31 -0
  40. package/dist/esm/provider.js.map +1 -0
  41. package/dist/react-native/index.d.ts +29 -0
  42. package/dist/react-native/index.d.ts.map +1 -0
  43. package/dist/react-native/index.js +34 -0
  44. package/dist/react-native/index.js.map +1 -0
  45. package/dist/react-native/package.json +3 -0
  46. package/dist/react-native/platforms.d.ts +51 -0
  47. package/dist/react-native/platforms.d.ts.map +1 -0
  48. package/dist/react-native/platforms.js +108 -0
  49. package/dist/react-native/platforms.js.map +1 -0
  50. package/dist/react-native/provider.d.ts +12 -0
  51. package/dist/react-native/provider.d.ts.map +1 -0
  52. package/dist/react-native/provider.js +31 -0
  53. package/dist/react-native/provider.js.map +1 -0
  54. package/package.json +60 -30
  55. package/dist/index.js +0 -194
  56. package/dist/index.js.map +0 -1
  57. package/dist-esm/src/index.js.map +0 -1
  58. package/dist-esm/src/platforms.js.map +0 -1
  59. package/dist-esm/src/provider.js.map +0 -1
@@ -1,31 +1,29 @@
1
- import type { IdentityPlugin } from '@azure/identity';
2
-
3
- /**
4
- * A plugin that provides persistent token caching for `@azure/identity`
5
- * credentials. The plugin API is compatible with `@azure/identity` versions
6
- * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`
7
- * function, imported from `@azure/identity`.
8
- *
9
- * In order to enable this functionality, you must also pass
10
- * `tokenCachePersistenceOptions` to your credential constructors with an
11
- * `enabled` property set to true.
12
- *
13
- * Example:
14
- *
15
- * ```ts snippet:device_code_credential_example
16
- * import { DeviceCodeCredential } from "@azure/identity";
17
- *
18
- * const credential = new DeviceCodeCredential({
19
- * tokenCachePersistenceOptions: {
20
- * enabled: true,
21
- * },
22
- * });
23
- * // We'll use the Microsoft Graph scope as an example
24
- * const scope = "https://graph.microsoft.com/.default";
25
- * // Print out part of the access token
26
- * console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
27
- * ```
28
- */
29
- export declare const cachePersistencePlugin: IdentityPlugin;
30
-
31
- export { }
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"}
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- import { createPersistenceCachePlugin } from "./provider";
3
+ import { createPersistenceCachePlugin } from "./provider.js";
4
4
  /**
5
5
  * A plugin that provides persistent token caching for `@azure/identity`
6
6
  * credentials. The plugin API is compatible with `@azure/identity` versions
@@ -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,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -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"}
@@ -3,7 +3,7 @@
3
3
  var _a, _b, _c;
4
4
  import { __awaiter } from "tslib";
5
5
  /* eslint-disable tsdoc/syntax */
6
- import * as path from "path";
6
+ import path from "node:path";
7
7
  import { DataProtectionScope, FilePersistence, FilePersistenceWithDataProtection, KeychainPersistence, LibSecretPersistence, } from "@azure/msal-node-extensions";
8
8
  /**
9
9
  * Local application data folder
@@ -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,C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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"}
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
  import { __awaiter } from "tslib";
4
- import { msalPersistencePlatforms } from "./platforms";
4
+ import { msalPersistencePlatforms } from "./platforms.js";
5
5
  import { PersistenceCachePlugin } from "@azure/msal-node-extensions";
6
6
  /**
7
7
  * This is used to gain access to the underlying Persistence instance, which we use for testing
@@ -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,38 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.cachePersistencePlugin = void 0;
6
+ const provider_js_1 = require("./provider.js");
7
+ /**
8
+ * A plugin that provides persistent token caching for `@azure/identity`
9
+ * credentials. The plugin API is compatible with `@azure/identity` versions
10
+ * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`
11
+ * function, imported from `@azure/identity`.
12
+ *
13
+ * In order to enable this functionality, you must also pass
14
+ * `tokenCachePersistenceOptions` to your credential constructors with an
15
+ * `enabled` property set to true.
16
+ *
17
+ * Example:
18
+ *
19
+ * ```ts snippet:device_code_credential_example
20
+ * import { DeviceCodeCredential } from "@azure/identity";
21
+ *
22
+ * const credential = new DeviceCodeCredential({
23
+ * tokenCachePersistenceOptions: {
24
+ * enabled: true,
25
+ * },
26
+ * });
27
+ * // We'll use the Microsoft Graph scope as an example
28
+ * const scope = "https://graph.microsoft.com/.default";
29
+ * // Print out part of the access token
30
+ * console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
31
+ * ```
32
+ */
33
+ const cachePersistencePlugin = (context) => {
34
+ const { cachePluginControl } = context;
35
+ cachePluginControl.setPersistence(provider_js_1.createPersistenceCachePlugin);
36
+ };
37
+ exports.cachePersistencePlugin = cachePersistencePlugin;
38
+ //# 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,+CAA6D;AAuB7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEI,MAAM,sBAAsB,GAAmB,CAAC,OAAO,EAAE,EAAE;IAChE,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAA6B,CAAC;IAE7D,kBAAkB,CAAC,cAAc,CAAC,0CAA4B,CAAC,CAAC;AAClE,CAAC,CAAC;AAJW,QAAA,sBAAsB,0BAIjC","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,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -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,111 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ var _a, _b, _c;
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.msalPersistencePlatforms = exports.defaultMsalValues = void 0;
7
+ const tslib_1 = require("tslib");
8
+ /* eslint-disable tsdoc/syntax */
9
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
10
+ const msal_node_extensions_1 = require("@azure/msal-node-extensions");
11
+ /**
12
+ * Local application data folder
13
+ * Expected values:
14
+ * - Darwin: '/Users/user/'
15
+ * - Windows 8+: 'C:\Users\user\AppData\Local'
16
+ * - Linux: '/home/user/.local/share'
17
+ * @internal
18
+ */
19
+ 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;
20
+ /**
21
+ * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.
22
+ * @internal
23
+ */
24
+ exports.defaultMsalValues = {
25
+ tokenCache: {
26
+ name: "msal.cache",
27
+ // Expected values:
28
+ // - Darwin: '/Users/user/.IdentityService'
29
+ // - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService'
30
+ // - Linux: '/home/user/.IdentityService'
31
+ directory: node_path_1.default.join(localApplicationDataFolder, ".IdentityService"),
32
+ },
33
+ keyRing: {
34
+ label: "MSALCache",
35
+ schema: "msal.cache",
36
+ collection: "default",
37
+ attributes: {
38
+ MsalClientID: "Microsoft.Developer.IdentityService",
39
+ "Microsoft.Developer.IdentityService": "1.0.0.0",
40
+ },
41
+ service: "Microsoft.Developer.IdentityService",
42
+ account: "MSALCache",
43
+ },
44
+ keyChain: {
45
+ service: "Microsoft.Developer.IdentityService",
46
+ account: "MSALCache",
47
+ },
48
+ };
49
+ /**
50
+ * Expected responses:
51
+ * - Darwin: '/Users/user/.IdentityService/<name>'
52
+ * - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService\<name>'
53
+ * - Linux: '/home/user/.IdentityService/<name>'
54
+ * @internal
55
+ */
56
+ function getPersistencePath(name) {
57
+ return node_path_1.default.join(exports.defaultMsalValues.tokenCache.directory, name);
58
+ }
59
+ /**
60
+ * Set of the platforms we attempt to deliver persistence on.
61
+ *
62
+ * - On Windows we use DPAPI.
63
+ * - 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.
64
+ * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
65
+ *
66
+ * Other platforms _are not supported_ at this time.
67
+ *
68
+ * @internal
69
+ */
70
+ exports.msalPersistencePlatforms = {
71
+ win32: ({ name = exports.defaultMsalValues.tokenCache.name } = {}) => msal_node_extensions_1.FilePersistenceWithDataProtection.create(getPersistencePath(name), msal_node_extensions_1.DataProtectionScope.CurrentUser),
72
+ darwin: (...args_1) => tslib_1.__awaiter(void 0, [...args_1], void 0, function* (options = {}) {
73
+ const { name, unsafeAllowUnencryptedStorage } = options;
74
+ const { service, account } = exports.defaultMsalValues.keyChain;
75
+ const persistencePath = getPersistencePath(name || exports.defaultMsalValues.tokenCache.name);
76
+ try {
77
+ const persistence = yield msal_node_extensions_1.KeychainPersistence.create(persistencePath, service, account);
78
+ // If we don't encounter an error when trying to read from the keychain, then we should be good to go.
79
+ yield persistence.load();
80
+ return persistence;
81
+ }
82
+ catch (e) {
83
+ // If we got an error while trying to read from the keyring,
84
+ // we will proceed only if the user has specified that unencrypted storage is allowed.
85
+ if (!unsafeAllowUnencryptedStorage) {
86
+ throw new Error("Unable to read from the macOS Keychain.");
87
+ }
88
+ return msal_node_extensions_1.FilePersistence.create(persistencePath);
89
+ }
90
+ }),
91
+ linux: (...args_1) => tslib_1.__awaiter(void 0, [...args_1], void 0, function* (options = {}) {
92
+ const { name, unsafeAllowUnencryptedStorage } = options;
93
+ const { service, account } = exports.defaultMsalValues.keyRing;
94
+ const persistencePath = getPersistencePath(name || exports.defaultMsalValues.tokenCache.name);
95
+ try {
96
+ const persistence = yield msal_node_extensions_1.LibSecretPersistence.create(persistencePath, service, account);
97
+ // If we don't encounter an error when trying to read from the keyring, then we should be good to go.
98
+ yield persistence.load();
99
+ return persistence;
100
+ }
101
+ catch (e) {
102
+ // If we got an error while trying to read from the keyring,
103
+ // we will proceed only if the user has specified that unencrypted storage is allowed.
104
+ if (!unsafeAllowUnencryptedStorage) {
105
+ throw new Error("Unable to read from the system keyring (libsecret).");
106
+ }
107
+ return msal_node_extensions_1.FilePersistence.create(persistencePath);
108
+ }
109
+ }),
110
+ };
111
+ //# 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,kEAA6B;AAE7B,sEAMqC;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;AACU,QAAA,iBAAiB,GAAG;IAC/B,UAAU,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,mBAAmB;QACnB,2CAA2C;QAC3C,+DAA+D;QAC/D,yCAAyC;QACzC,SAAS,EAAE,mBAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE,kBAAkB,CAAC;KACrE;IACD,OAAO,EAAE;QACP,KAAK,EAAE,WAAW;QAClB,MAAM,EAAE,YAAY;QACpB,UAAU,EAA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M,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;YAC7D,CAAC;YACD,OAAO,sCAAe,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACjD,CAAC;IACH,CAAC,CAAA;IAED,KAAK,EAAE,YAAmE,EAAE,2DAA9D,UAAkC,EAAE;QAChD,MAAM,EAAE,IAAI,EAAE,6BAA6B,EAAE,GAAG,OAAO,CAAC;QACxD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,yBAAiB,CAAC,OAAO,CAAC;QACvD,MAAM,eAAe,GAAG,kBAAkB,CAAC,IAAI,IAAI,yBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEtF,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,2CAAoB,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,sCAAe,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,35 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.createPersistence = createPersistence;
6
+ exports.createPersistenceCachePlugin = createPersistenceCachePlugin;
7
+ const tslib_1 = require("tslib");
8
+ const platforms_js_1 = require("./platforms.js");
9
+ const msal_node_extensions_1 = require("@azure/msal-node-extensions");
10
+ /**
11
+ * This is used to gain access to the underlying Persistence instance, which we use for testing
12
+ *
13
+ * @returns a raw persistence instance
14
+ * @internal
15
+ */
16
+ function createPersistence(options) {
17
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
18
+ var _a;
19
+ const persistence = yield ((_a = platforms_js_1.msalPersistencePlatforms[process.platform]) === null || _a === void 0 ? void 0 : _a.call(platforms_js_1.msalPersistencePlatforms, options));
20
+ if (persistence === undefined) {
21
+ throw new Error("no persistence providers are available on this platform");
22
+ }
23
+ return persistence;
24
+ });
25
+ }
26
+ function createPersistenceCachePlugin(options) {
27
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
28
+ const persistence = yield createPersistence(options !== null && options !== void 0 ? options : {});
29
+ return new msal_node_extensions_1.PersistenceCachePlugin(persistence, {
30
+ retryNumber: 100,
31
+ retryDelay: 50,
32
+ });
33
+ });
34
+ }
35
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAclC,8CAQC;AAED,oEASC;;AA9BD,iDAA0D;AAE1D,sEAAqE;AAGrE;;;;;GAKG;AACH,SAAsB,iBAAiB,CAAC,OAA+B;;;QACrE,MAAM,WAAW,GAAG,MAAM,CAAA,MAAA,uCAAwB,CAAC,OAAO,CAAC,QAAQ,CAAC,wFAAG,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,SAAsB,4BAA4B,CAChD,OAAgC;;QAEhC,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,CAAC;QAE3D,OAAO,IAAI,6CAAsB,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,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.48.0"
9
+ }
10
+ ]
11
+ }
@@ -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