Skip to content

Commit 538c8e5

Browse files
authored
[identity] Refactor plugin definitions (#28781)
### Packages impacted by this PR @azure/identity ### Issues associated with this PR Resolves #28679 ### Describe the problem that is addressed by this PR When migrating plugin support to MSALClient I noticed that msalNodeCommon defines all the plugin declarations. To avoid duplication, provide an easy path to migrate (by avoiding imports on msalNodeCommon) and provide a single source of truth for plugin settings it made sense to migrate all the definitions to a single file. This is purely mechanical, just moving things around and updating imports ### Provide a list of related PRs _(if any)_ #28493
1 parent 3ff3a8f commit 538c8e5

5 files changed

Lines changed: 52 additions & 55 deletions

File tree

sdk/identity/identity/src/msal/nodeFlows/msalNodeCommon.ts

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
publicToMsal,
2020
randomUUID,
2121
} from "../utils";
22+
import { hasNativeBroker, nativeBrokerInfo, persistenceProvider } from "./msalPlugins";
2223
import {
2324
processMultiTenantRequest,
2425
resolveAdditionallyAllowedTenantIds,
@@ -32,7 +33,6 @@ import { CredentialFlowGetTokenOptions } from "../credentials";
3233
import { IdentityClient } from "../../client/identityClient";
3334
import { LogPolicyOptions } from "@azure/core-rest-pipeline";
3435
import { MultiTenantTokenCredentialOptions } from "../../credentials/multiTenantTokenCredentialOptions";
35-
import { NativeBrokerPluginControl } from "../../plugins/provider";
3636
import { RegionalAuthority } from "../../regionalAuthority";
3737
import { TokenCachePersistenceOptions } from "./tokenCachePersistenceOptions";
3838
import { getLogLevel } from "@azure/logger";
@@ -66,50 +66,6 @@ export interface MsalNodeOptions extends MsalFlowOptions {
6666
};
6767
}
6868

69-
/**
70-
* The current persistence provider, undefined by default.
71-
* @internal
72-
*/
73-
export let persistenceProvider:
74-
| ((options?: TokenCachePersistenceOptions) => Promise<msalNode.ICachePlugin>)
75-
| undefined = undefined;
76-
77-
/**
78-
* An object that allows setting the persistence provider.
79-
* @internal
80-
*/
81-
export const msalNodeFlowCacheControl = {
82-
setPersistence(pluginProvider: Exclude<typeof persistenceProvider, undefined>): void {
83-
persistenceProvider = pluginProvider;
84-
},
85-
};
86-
87-
/**
88-
* The current native broker provider, undefined by default.
89-
* @internal
90-
*/
91-
export let nativeBrokerInfo:
92-
| {
93-
broker: msalNode.INativeBrokerPlugin;
94-
}
95-
| undefined = undefined;
96-
97-
export function hasNativeBroker(): boolean {
98-
return nativeBrokerInfo !== undefined;
99-
}
100-
101-
/**
102-
* An object that allows setting the native broker provider.
103-
* @internal
104-
*/
105-
export const msalNodeFlowNativeBrokerControl: NativeBrokerPluginControl = {
106-
setNativeBroker(broker): void {
107-
nativeBrokerInfo = {
108-
broker,
109-
};
110-
},
111-
};
112-
11369
/**
11470
* MSAL partial base client for Node.js.
11571
*

sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
import * as msalNode from "@azure/msal-node";
55

6-
import { MsalNode, MsalNodeOptions, hasNativeBroker } from "./msalNodeCommon";
6+
import { MsalNode, MsalNodeOptions } from "./msalNodeCommon";
77

88
import { AccessToken } from "@azure/core-auth";
99
import { CredentialFlowGetTokenOptions } from "../credentials";
1010
import { credentialLogger } from "../../util/logging";
1111
import { handleMsalError } from "../utils";
12+
import { hasNativeBroker } from "./msalPlugins";
1213
import open from "open";
1314

1415
/**

sdk/identity/identity/src/msal/nodeFlows/msalPlugins.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44
import * as msalNode from "@azure/msal-node";
55

6-
import { nativeBrokerInfo, persistenceProvider } from "./msalNodeCommon";
7-
86
import { MsalClientOptions } from "./msalClient";
9-
10-
// TODO: invert this relationship, instead of importing from msalNodeCommon and calling into it, we should _export_ the right things from here and import them in msalNodeCommon
11-
// Then, there's a single source for plugins across both msalClient and msalNodeCommon
7+
import { NativeBrokerPluginControl } from "../../plugins/provider";
8+
import { TokenCachePersistenceOptions } from "./tokenCachePersistenceOptions";
129

1310
/**
1411
* Configuration for the plugins used by the MSAL node client.
@@ -30,6 +27,50 @@ export interface PluginConfiguration {
3027
};
3128
}
3229

30+
/**
31+
* The current persistence provider, undefined by default.
32+
* @internal
33+
*/
34+
export let persistenceProvider:
35+
| ((options?: TokenCachePersistenceOptions) => Promise<msalNode.ICachePlugin>)
36+
| undefined = undefined;
37+
38+
/**
39+
* An object that allows setting the persistence provider.
40+
* @internal
41+
*/
42+
export const msalNodeFlowCacheControl = {
43+
setPersistence(pluginProvider: Exclude<typeof persistenceProvider, undefined>): void {
44+
persistenceProvider = pluginProvider;
45+
},
46+
};
47+
48+
/**
49+
* The current native broker provider, undefined by default.
50+
* @internal
51+
*/
52+
export let nativeBrokerInfo:
53+
| {
54+
broker: msalNode.INativeBrokerPlugin;
55+
}
56+
| undefined = undefined;
57+
58+
export function hasNativeBroker(): boolean {
59+
return nativeBrokerInfo !== undefined;
60+
}
61+
62+
/**
63+
* An object that allows setting the native broker provider.
64+
* @internal
65+
*/
66+
export const msalNodeFlowNativeBrokerControl: NativeBrokerPluginControl = {
67+
setNativeBroker(broker): void {
68+
nativeBrokerInfo = {
69+
broker,
70+
};
71+
},
72+
};
73+
3374
/**
3475
* Configures plugins, validating that required plugins are available and enabled.
3576
*

sdk/identity/identity/src/plugins/consumer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { AzurePluginContext, IdentityPlugin } from "./provider";
55
import {
66
msalNodeFlowCacheControl,
77
msalNodeFlowNativeBrokerControl,
8-
} from "../msal/nodeFlows/msalNodeCommon";
8+
} from "../msal/nodeFlows/msalPlugins";
9+
910
import { vsCodeCredentialControl } from "../credentials/visualStudioCodeCredential";
1011

1112
/**

sdk/identity/identity/test/internal/node/msalPlugins.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import { ICachePlugin, INativeBrokerPlugin } from "@azure/msal-node";
55
import {
66
PluginConfiguration,
77
generatePluginConfiguration,
8-
} from "../../../src/msal/nodeFlows/msalPlugins";
9-
import {
108
msalNodeFlowCacheControl,
119
msalNodeFlowNativeBrokerControl,
12-
} from "../../../src/msal/nodeFlows/msalNodeCommon";
10+
} from "../../../src/msal/nodeFlows/msalPlugins";
1311

1412
import { MsalClientOptions } from "../../../src/msal/nodeFlows/msalClient";
1513
import { assert } from "@azure/test-utils";

0 commit comments

Comments
 (0)