@azure/msal-node 2.0.0-alpha.1 → 2.0.0-alpha.2

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 (107) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +182 -182
  3. package/dist/cache/ITokenCache.d.ts +15 -15
  4. package/dist/cache/NodeStorage.d.ts +182 -182
  5. package/dist/cache/NodeStorage.esm.js +401 -401
  6. package/dist/cache/NodeStorage.js +401 -401
  7. package/dist/cache/TokenCache.d.ts +90 -90
  8. package/dist/cache/TokenCache.esm.js +269 -269
  9. package/dist/cache/TokenCache.js +269 -269
  10. package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
  11. package/dist/cache/distributed/DistributedCachePlugin.esm.js +26 -26
  12. package/dist/cache/distributed/DistributedCachePlugin.js +26 -26
  13. package/dist/cache/distributed/ICacheClient.d.ts +17 -17
  14. package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
  15. package/dist/cache/serializer/Deserializer.d.ts +42 -42
  16. package/dist/cache/serializer/Deserializer.esm.js +175 -175
  17. package/dist/cache/serializer/Deserializer.js +175 -175
  18. package/dist/cache/serializer/Serializer.d.ts +39 -39
  19. package/dist/cache/serializer/Serializer.esm.js +134 -134
  20. package/dist/cache/serializer/Serializer.js +134 -134
  21. package/dist/cache/serializer/SerializerTypes.d.ts +101 -101
  22. package/dist/client/ClientApplication.d.ts +142 -142
  23. package/dist/client/ClientApplication.esm.js +327 -327
  24. package/dist/client/ClientApplication.js +327 -327
  25. package/dist/client/ClientAssertion.d.ts +46 -46
  26. package/dist/client/ClientAssertion.esm.js +116 -116
  27. package/dist/client/ClientAssertion.js +116 -116
  28. package/dist/client/ClientCredentialClient.d.ts +33 -33
  29. package/dist/client/ClientCredentialClient.esm.js +157 -157
  30. package/dist/client/ClientCredentialClient.js +157 -157
  31. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  32. package/dist/client/ConfidentialClientApplication.esm.js +163 -163
  33. package/dist/client/ConfidentialClientApplication.js +163 -163
  34. package/dist/client/DeviceCodeClient.d.ts +53 -53
  35. package/dist/client/DeviceCodeClient.esm.js +207 -207
  36. package/dist/client/DeviceCodeClient.js +207 -207
  37. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  38. package/dist/client/IPublicClientApplication.d.ts +42 -42
  39. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  40. package/dist/client/OnBehalfOfClient.esm.js +204 -204
  41. package/dist/client/OnBehalfOfClient.js +204 -204
  42. package/dist/client/PublicClientApplication.d.ts +65 -65
  43. package/dist/client/PublicClientApplication.esm.js +175 -175
  44. package/dist/client/PublicClientApplication.js +175 -175
  45. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  46. package/dist/client/UsernamePasswordClient.esm.js +102 -102
  47. package/dist/client/UsernamePasswordClient.js +102 -102
  48. package/dist/config/Configuration.d.ts +105 -105
  49. package/dist/config/Configuration.esm.js +70 -70
  50. package/dist/config/Configuration.js +70 -70
  51. package/dist/crypto/CryptoProvider.d.ts +52 -52
  52. package/dist/crypto/CryptoProvider.esm.js +75 -75
  53. package/dist/crypto/CryptoProvider.js +75 -75
  54. package/dist/crypto/GuidGenerator.d.ts +14 -14
  55. package/dist/crypto/GuidGenerator.esm.js +22 -22
  56. package/dist/crypto/GuidGenerator.js +22 -22
  57. package/dist/crypto/HashUtils.d.ts +8 -8
  58. package/dist/crypto/HashUtils.esm.js +13 -13
  59. package/dist/crypto/HashUtils.js +13 -13
  60. package/dist/crypto/PkceGenerator.d.ts +22 -22
  61. package/dist/crypto/PkceGenerator.esm.js +49 -49
  62. package/dist/crypto/PkceGenerator.js +49 -49
  63. package/dist/error/NodeAuthError.d.ts +65 -65
  64. package/dist/error/NodeAuthError.esm.js +85 -85
  65. package/dist/error/NodeAuthError.js +85 -85
  66. package/dist/index.d.ts +41 -41
  67. package/dist/index.esm.js +1 -1
  68. package/dist/index.js +1 -1
  69. package/dist/internals.d.ts +6 -6
  70. package/dist/internals.esm.js +4 -4
  71. package/dist/internals.js +4 -4
  72. package/dist/network/HttpClient.d.ts +25 -25
  73. package/dist/network/HttpClient.esm.js +276 -276
  74. package/dist/network/HttpClient.js +276 -276
  75. package/dist/network/ILoopbackClient.d.ts +10 -10
  76. package/dist/network/LoopbackClient.d.ts +21 -21
  77. package/dist/network/LoopbackClient.esm.js +84 -84
  78. package/dist/network/LoopbackClient.js +84 -84
  79. package/dist/packageMetadata.d.ts +2 -2
  80. package/dist/packageMetadata.esm.js +4 -4
  81. package/dist/packageMetadata.js +4 -4
  82. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  83. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  84. package/dist/request/ClientCredentialRequest.d.ts +15 -15
  85. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  86. package/dist/request/InteractiveRequest.d.ts +22 -22
  87. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  88. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  89. package/dist/request/SignOutRequest.d.ts +5 -5
  90. package/dist/request/SilentFlowRequest.d.ts +16 -16
  91. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  92. package/dist/utils/Constants.d.ts +92 -92
  93. package/dist/utils/Constants.esm.js +93 -93
  94. package/dist/utils/Constants.js +93 -93
  95. package/dist/utils/EncodingUtils.d.ts +26 -26
  96. package/dist/utils/EncodingUtils.esm.js +44 -44
  97. package/dist/utils/EncodingUtils.js +44 -44
  98. package/dist/utils/NetworkUtils.d.ts +5 -5
  99. package/dist/utils/NetworkUtils.esm.js +38 -38
  100. package/dist/utils/NetworkUtils.js +38 -38
  101. package/package.json +73 -73
  102. package/dist/msal-node.cjs.development.js +0 -2705
  103. package/dist/msal-node.cjs.development.js.map +0 -1
  104. package/dist/msal-node.cjs.production.min.js +0 -2
  105. package/dist/msal-node.cjs.production.min.js.map +0 -1
  106. package/dist/msal-node.esm.js +0 -2594
  107. package/dist/msal-node.esm.js.map +0 -1
@@ -1,59 +1,59 @@
1
- import { ClientApplication } from "./ClientApplication";
2
- import { Configuration } from "../config/Configuration";
3
- import { AuthenticationResult, IAppTokenProvider } from "@azure/msal-common";
4
- import { IConfidentialClientApplication } from "./IConfidentialClientApplication";
5
- import { OnBehalfOfRequest } from "../request/OnBehalfOfRequest";
6
- import { ClientCredentialRequest } from "../request/ClientCredentialRequest";
7
- /**
8
- * This class is to be used to acquire tokens for confidential client applications (webApp, webAPI). Confidential client applications
9
- * will configure application secrets, client certificates/assertions as applicable
10
- * @public
11
- */
12
- export declare class ConfidentialClientApplication extends ClientApplication implements IConfidentialClientApplication {
13
- private appTokenProvider?;
14
- /**
15
- * Constructor for the ConfidentialClientApplication
16
- *
17
- * Required attributes in the Configuration object are:
18
- * - clientID: the application ID of your application. You can obtain one by registering your application with our application registration portal
19
- * - authority: the authority URL for your application.
20
- * - client credential: Must set either client secret, certificate, or assertion for confidential clients. You can obtain a client secret from the application registration portal.
21
- *
22
- * In Azure AD, authority is a URL indicating of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
23
- * If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
24
- * If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
25
- * If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
26
- * To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
27
- *
28
- * In Azure B2C, authority is of the form https://\{instance\}/tfp/\{tenant\}/\{policyName\}/
29
- * Full B2C functionality will be available in this library in future versions.
30
- *
31
- * @param Configuration - configuration object for the MSAL ConfidentialClientApplication instance
32
- */
33
- constructor(configuration: Configuration);
34
- /**
35
- * This extensibility point only works for the client_credential flow, i.e. acquireTokenByClientCredential and
36
- * is meant for Azure SDK to enhance Managed Identity support.
37
- *
38
- * @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
39
- */
40
- SetAppTokenProvider(provider: IAppTokenProvider): void;
41
- /**
42
- * Acquires tokens from the authority for the application (not for an end user).
43
- */
44
- acquireTokenByClientCredential(request: ClientCredentialRequest): Promise<AuthenticationResult | null>;
45
- /**
46
- * Acquires tokens from the authority for the application.
47
- *
48
- * Used in scenarios where the current app is a middle-tier service which was called with a token
49
- * representing an end user. The current app can use the token (oboAssertion) to request another
50
- * token to access downstream web API, on behalf of that user.
51
- *
52
- * The current middle-tier app has no user interaction to obtain consent.
53
- * See how to gain consent upfront for your middle-tier app from this article.
54
- * https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
55
- */
56
- acquireTokenOnBehalfOf(request: OnBehalfOfRequest): Promise<AuthenticationResult | null>;
57
- private setClientCredential;
58
- }
1
+ import { ClientApplication } from "./ClientApplication";
2
+ import { Configuration } from "../config/Configuration";
3
+ import { AuthenticationResult, IAppTokenProvider } from "@azure/msal-common";
4
+ import { IConfidentialClientApplication } from "./IConfidentialClientApplication";
5
+ import { OnBehalfOfRequest } from "../request/OnBehalfOfRequest";
6
+ import { ClientCredentialRequest } from "../request/ClientCredentialRequest";
7
+ /**
8
+ * This class is to be used to acquire tokens for confidential client applications (webApp, webAPI). Confidential client applications
9
+ * will configure application secrets, client certificates/assertions as applicable
10
+ * @public
11
+ */
12
+ export declare class ConfidentialClientApplication extends ClientApplication implements IConfidentialClientApplication {
13
+ private appTokenProvider?;
14
+ /**
15
+ * Constructor for the ConfidentialClientApplication
16
+ *
17
+ * Required attributes in the Configuration object are:
18
+ * - clientID: the application ID of your application. You can obtain one by registering your application with our application registration portal
19
+ * - authority: the authority URL for your application.
20
+ * - client credential: Must set either client secret, certificate, or assertion for confidential clients. You can obtain a client secret from the application registration portal.
21
+ *
22
+ * In Azure AD, authority is a URL indicating of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
23
+ * If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
24
+ * If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
25
+ * If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
26
+ * To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
27
+ *
28
+ * In Azure B2C, authority is of the form https://\{instance\}/tfp/\{tenant\}/\{policyName\}/
29
+ * Full B2C functionality will be available in this library in future versions.
30
+ *
31
+ * @param Configuration - configuration object for the MSAL ConfidentialClientApplication instance
32
+ */
33
+ constructor(configuration: Configuration);
34
+ /**
35
+ * This extensibility point only works for the client_credential flow, i.e. acquireTokenByClientCredential and
36
+ * is meant for Azure SDK to enhance Managed Identity support.
37
+ *
38
+ * @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
39
+ */
40
+ SetAppTokenProvider(provider: IAppTokenProvider): void;
41
+ /**
42
+ * Acquires tokens from the authority for the application (not for an end user).
43
+ */
44
+ acquireTokenByClientCredential(request: ClientCredentialRequest): Promise<AuthenticationResult | null>;
45
+ /**
46
+ * Acquires tokens from the authority for the application.
47
+ *
48
+ * Used in scenarios where the current app is a middle-tier service which was called with a token
49
+ * representing an end user. The current app can use the token (oboAssertion) to request another
50
+ * token to access downstream web API, on behalf of that user.
51
+ *
52
+ * The current middle-tier app has no user interaction to obtain consent.
53
+ * See how to gain consent upfront for your middle-tier app from this article.
54
+ * https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
55
+ */
56
+ acquireTokenOnBehalfOf(request: OnBehalfOfRequest): Promise<AuthenticationResult | null>;
57
+ private setClientCredential;
58
+ }
59
59
  //# sourceMappingURL=ConfidentialClientApplication.d.ts.map
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.0.0-alpha.1 2023-05-08 */
1
+ /*! @azure/msal-node v2.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
3
  import { ClientApplication } from './ClientApplication.esm.js';
4
4
  import { ClientAssertion } from './ClientAssertion.esm.js';
@@ -7,168 +7,168 @@ import { OIDC_DEFAULT_SCOPES, UrlString, AADAuthorityConstants, ClientAuthError,
7
7
  import { ClientCredentialClient } from './ClientCredentialClient.esm.js';
8
8
  import { OnBehalfOfClient } from './OnBehalfOfClient.esm.js';
9
9
 
10
- /*
11
- * Copyright (c) Microsoft Corporation. All rights reserved.
12
- * Licensed under the MIT License.
13
- */
14
- /**
15
- * This class is to be used to acquire tokens for confidential client applications (webApp, webAPI). Confidential client applications
16
- * will configure application secrets, client certificates/assertions as applicable
17
- * @public
18
- */
19
- class ConfidentialClientApplication extends ClientApplication {
20
- /**
21
- * Constructor for the ConfidentialClientApplication
22
- *
23
- * Required attributes in the Configuration object are:
24
- * - clientID: the application ID of your application. You can obtain one by registering your application with our application registration portal
25
- * - authority: the authority URL for your application.
26
- * - client credential: Must set either client secret, certificate, or assertion for confidential clients. You can obtain a client secret from the application registration portal.
27
- *
28
- * In Azure AD, authority is a URL indicating of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
29
- * If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
30
- * If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
31
- * If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
32
- * To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
33
- *
34
- * In Azure B2C, authority is of the form https://\{instance\}/tfp/\{tenant\}/\{policyName\}/
35
- * Full B2C functionality will be available in this library in future versions.
36
- *
37
- * @param Configuration - configuration object for the MSAL ConfidentialClientApplication instance
38
- */
39
- constructor(configuration) {
40
- super(configuration);
41
- this.setClientCredential(this.config);
42
- this.appTokenProvider = undefined;
43
- }
44
- /**
45
- * This extensibility point only works for the client_credential flow, i.e. acquireTokenByClientCredential and
46
- * is meant for Azure SDK to enhance Managed Identity support.
47
- *
48
- * @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
49
- */
50
- SetAppTokenProvider(provider) {
51
- this.appTokenProvider = provider;
52
- }
53
- /**
54
- * Acquires tokens from the authority for the application (not for an end user).
55
- */
56
- async acquireTokenByClientCredential(request) {
57
- this.logger.info("acquireTokenByClientCredential called", request.correlationId);
58
- // If there is a client assertion present in the request, it overrides the one present in the client configuration
59
- let clientAssertion;
60
- if (request.clientAssertion) {
61
- clientAssertion = {
62
- assertion: request.clientAssertion,
63
- assertionType: Constants$1.JWT_BEARER_ASSERTION_TYPE,
64
- };
65
- }
66
- const baseRequest = await this.initializeBaseRequest(request);
67
- // valid base request should not contain oidc scopes in this grant type
68
- const validBaseRequest = {
69
- ...baseRequest,
70
- scopes: baseRequest.scopes.filter((scope) => !OIDC_DEFAULT_SCOPES.includes(scope)),
71
- };
72
- const validRequest = {
73
- ...request,
74
- ...validBaseRequest,
75
- clientAssertion,
76
- };
77
- /*
78
- * valid request should not have "common" or "organizations" in lieu of the tenant_id in the authority in the auth configuration
79
- * example authority: "https://login.microsoftonline.com/TenantId",
80
- */
81
- const authority = new UrlString(validRequest.authority);
82
- const tenantId = authority.getUrlComponents().PathSegments[0];
83
- if (Object.values(AADAuthorityConstants).includes(tenantId)) {
84
- throw ClientAuthError.createMissingTenantIdError();
85
- }
86
- const azureRegionConfiguration = {
87
- azureRegion: validRequest.azureRegion,
88
- environmentRegion: process.env[REGION_ENVIRONMENT_VARIABLE],
89
- };
90
- const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
91
- try {
92
- const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
93
- const clientCredentialClient = new ClientCredentialClient(clientCredentialConfig, this.appTokenProvider);
94
- this.logger.verbose("Client credential client created", validRequest.correlationId);
95
- return clientCredentialClient.acquireToken(validRequest);
96
- }
97
- catch (e) {
98
- if (e instanceof AuthError) {
99
- e.setCorrelationId(validRequest.correlationId);
100
- }
101
- serverTelemetryManager.cacheFailedRequest(e);
102
- throw e;
103
- }
104
- }
105
- /**
106
- * Acquires tokens from the authority for the application.
107
- *
108
- * Used in scenarios where the current app is a middle-tier service which was called with a token
109
- * representing an end user. The current app can use the token (oboAssertion) to request another
110
- * token to access downstream web API, on behalf of that user.
111
- *
112
- * The current middle-tier app has no user interaction to obtain consent.
113
- * See how to gain consent upfront for your middle-tier app from this article.
114
- * https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
115
- */
116
- async acquireTokenOnBehalfOf(request) {
117
- this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
118
- const validRequest = {
119
- ...request,
120
- ...(await this.initializeBaseRequest(request)),
121
- };
122
- try {
123
- const onBehalfOfConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
124
- const oboClient = new OnBehalfOfClient(onBehalfOfConfig);
125
- this.logger.verbose("On behalf of client created", validRequest.correlationId);
126
- return oboClient.acquireToken(validRequest);
127
- }
128
- catch (e) {
129
- if (e instanceof AuthError) {
130
- e.setCorrelationId(validRequest.correlationId);
131
- }
132
- throw e;
133
- }
134
- }
135
- setClientCredential(configuration) {
136
- const clientSecretNotEmpty = !StringUtils.isEmpty(configuration.auth.clientSecret);
137
- const clientAssertionNotEmpty = !StringUtils.isEmpty(configuration.auth.clientAssertion);
138
- const certificate = configuration.auth.clientCertificate || {
139
- thumbprint: Constants.EMPTY_STRING,
140
- privateKey: Constants.EMPTY_STRING,
141
- };
142
- const certificateNotEmpty = !StringUtils.isEmpty(certificate.thumbprint) ||
143
- !StringUtils.isEmpty(certificate.privateKey);
144
- /*
145
- * If app developer configures this callback, they don't need a credential
146
- * i.e. AzureSDK can get token from Managed Identity without a cert / secret
147
- */
148
- if (this.appTokenProvider) {
149
- return;
150
- }
151
- // Check that at most one credential is set on the application
152
- if ((clientSecretNotEmpty && clientAssertionNotEmpty) ||
153
- (clientAssertionNotEmpty && certificateNotEmpty) ||
154
- (clientSecretNotEmpty && certificateNotEmpty)) {
155
- throw ClientAuthError.createInvalidCredentialError();
156
- }
157
- if (configuration.auth.clientSecret) {
158
- this.clientSecret = configuration.auth.clientSecret;
159
- return;
160
- }
161
- if (configuration.auth.clientAssertion) {
162
- this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
163
- return;
164
- }
165
- if (!certificateNotEmpty) {
166
- throw ClientAuthError.createInvalidCredentialError();
167
- }
168
- else {
169
- this.clientAssertion = ClientAssertion.fromCertificate(certificate.thumbprint, certificate.privateKey, configuration.auth.clientCertificate?.x5c);
170
- }
171
- }
10
+ /*
11
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12
+ * Licensed under the MIT License.
13
+ */
14
+ /**
15
+ * This class is to be used to acquire tokens for confidential client applications (webApp, webAPI). Confidential client applications
16
+ * will configure application secrets, client certificates/assertions as applicable
17
+ * @public
18
+ */
19
+ class ConfidentialClientApplication extends ClientApplication {
20
+ /**
21
+ * Constructor for the ConfidentialClientApplication
22
+ *
23
+ * Required attributes in the Configuration object are:
24
+ * - clientID: the application ID of your application. You can obtain one by registering your application with our application registration portal
25
+ * - authority: the authority URL for your application.
26
+ * - client credential: Must set either client secret, certificate, or assertion for confidential clients. You can obtain a client secret from the application registration portal.
27
+ *
28
+ * In Azure AD, authority is a URL indicating of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
29
+ * If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
30
+ * If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
31
+ * If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
32
+ * To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
33
+ *
34
+ * In Azure B2C, authority is of the form https://\{instance\}/tfp/\{tenant\}/\{policyName\}/
35
+ * Full B2C functionality will be available in this library in future versions.
36
+ *
37
+ * @param Configuration - configuration object for the MSAL ConfidentialClientApplication instance
38
+ */
39
+ constructor(configuration) {
40
+ super(configuration);
41
+ this.setClientCredential(this.config);
42
+ this.appTokenProvider = undefined;
43
+ }
44
+ /**
45
+ * This extensibility point only works for the client_credential flow, i.e. acquireTokenByClientCredential and
46
+ * is meant for Azure SDK to enhance Managed Identity support.
47
+ *
48
+ * @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
49
+ */
50
+ SetAppTokenProvider(provider) {
51
+ this.appTokenProvider = provider;
52
+ }
53
+ /**
54
+ * Acquires tokens from the authority for the application (not for an end user).
55
+ */
56
+ async acquireTokenByClientCredential(request) {
57
+ this.logger.info("acquireTokenByClientCredential called", request.correlationId);
58
+ // If there is a client assertion present in the request, it overrides the one present in the client configuration
59
+ let clientAssertion;
60
+ if (request.clientAssertion) {
61
+ clientAssertion = {
62
+ assertion: request.clientAssertion,
63
+ assertionType: Constants$1.JWT_BEARER_ASSERTION_TYPE,
64
+ };
65
+ }
66
+ const baseRequest = await this.initializeBaseRequest(request);
67
+ // valid base request should not contain oidc scopes in this grant type
68
+ const validBaseRequest = {
69
+ ...baseRequest,
70
+ scopes: baseRequest.scopes.filter((scope) => !OIDC_DEFAULT_SCOPES.includes(scope)),
71
+ };
72
+ const validRequest = {
73
+ ...request,
74
+ ...validBaseRequest,
75
+ clientAssertion,
76
+ };
77
+ /*
78
+ * valid request should not have "common" or "organizations" in lieu of the tenant_id in the authority in the auth configuration
79
+ * example authority: "https://login.microsoftonline.com/TenantId",
80
+ */
81
+ const authority = new UrlString(validRequest.authority);
82
+ const tenantId = authority.getUrlComponents().PathSegments[0];
83
+ if (Object.values(AADAuthorityConstants).includes(tenantId)) {
84
+ throw ClientAuthError.createMissingTenantIdError();
85
+ }
86
+ const azureRegionConfiguration = {
87
+ azureRegion: validRequest.azureRegion,
88
+ environmentRegion: process.env[REGION_ENVIRONMENT_VARIABLE],
89
+ };
90
+ const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
91
+ try {
92
+ const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
93
+ const clientCredentialClient = new ClientCredentialClient(clientCredentialConfig, this.appTokenProvider);
94
+ this.logger.verbose("Client credential client created", validRequest.correlationId);
95
+ return clientCredentialClient.acquireToken(validRequest);
96
+ }
97
+ catch (e) {
98
+ if (e instanceof AuthError) {
99
+ e.setCorrelationId(validRequest.correlationId);
100
+ }
101
+ serverTelemetryManager.cacheFailedRequest(e);
102
+ throw e;
103
+ }
104
+ }
105
+ /**
106
+ * Acquires tokens from the authority for the application.
107
+ *
108
+ * Used in scenarios where the current app is a middle-tier service which was called with a token
109
+ * representing an end user. The current app can use the token (oboAssertion) to request another
110
+ * token to access downstream web API, on behalf of that user.
111
+ *
112
+ * The current middle-tier app has no user interaction to obtain consent.
113
+ * See how to gain consent upfront for your middle-tier app from this article.
114
+ * https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
115
+ */
116
+ async acquireTokenOnBehalfOf(request) {
117
+ this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
118
+ const validRequest = {
119
+ ...request,
120
+ ...(await this.initializeBaseRequest(request)),
121
+ };
122
+ try {
123
+ const onBehalfOfConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
124
+ const oboClient = new OnBehalfOfClient(onBehalfOfConfig);
125
+ this.logger.verbose("On behalf of client created", validRequest.correlationId);
126
+ return oboClient.acquireToken(validRequest);
127
+ }
128
+ catch (e) {
129
+ if (e instanceof AuthError) {
130
+ e.setCorrelationId(validRequest.correlationId);
131
+ }
132
+ throw e;
133
+ }
134
+ }
135
+ setClientCredential(configuration) {
136
+ const clientSecretNotEmpty = !StringUtils.isEmpty(configuration.auth.clientSecret);
137
+ const clientAssertionNotEmpty = !StringUtils.isEmpty(configuration.auth.clientAssertion);
138
+ const certificate = configuration.auth.clientCertificate || {
139
+ thumbprint: Constants.EMPTY_STRING,
140
+ privateKey: Constants.EMPTY_STRING,
141
+ };
142
+ const certificateNotEmpty = !StringUtils.isEmpty(certificate.thumbprint) ||
143
+ !StringUtils.isEmpty(certificate.privateKey);
144
+ /*
145
+ * If app developer configures this callback, they don't need a credential
146
+ * i.e. AzureSDK can get token from Managed Identity without a cert / secret
147
+ */
148
+ if (this.appTokenProvider) {
149
+ return;
150
+ }
151
+ // Check that at most one credential is set on the application
152
+ if ((clientSecretNotEmpty && clientAssertionNotEmpty) ||
153
+ (clientAssertionNotEmpty && certificateNotEmpty) ||
154
+ (clientSecretNotEmpty && certificateNotEmpty)) {
155
+ throw ClientAuthError.createInvalidCredentialError();
156
+ }
157
+ if (configuration.auth.clientSecret) {
158
+ this.clientSecret = configuration.auth.clientSecret;
159
+ return;
160
+ }
161
+ if (configuration.auth.clientAssertion) {
162
+ this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
163
+ return;
164
+ }
165
+ if (!certificateNotEmpty) {
166
+ throw ClientAuthError.createInvalidCredentialError();
167
+ }
168
+ else {
169
+ this.clientAssertion = ClientAssertion.fromCertificate(certificate.thumbprint, certificate.privateKey, configuration.auth.clientCertificate?.x5c);
170
+ }
171
+ }
172
172
  }
173
173
 
174
174
  export { ConfidentialClientApplication };