@azure/msal-node 2.0.0-alpha.1 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) 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.d.ts.map +1 -1
  81. package/dist/packageMetadata.esm.js +4 -4
  82. package/dist/packageMetadata.js +4 -4
  83. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  84. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  85. package/dist/request/ClientCredentialRequest.d.ts +14 -15
  86. package/dist/request/ClientCredentialRequest.d.ts.map +1 -1
  87. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  88. package/dist/request/InteractiveRequest.d.ts +22 -22
  89. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  90. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  91. package/dist/request/SignOutRequest.d.ts +5 -5
  92. package/dist/request/SilentFlowRequest.d.ts +16 -16
  93. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  94. package/dist/utils/Constants.d.ts +96 -92
  95. package/dist/utils/Constants.d.ts.map +1 -1
  96. package/dist/utils/Constants.esm.js +89 -93
  97. package/dist/utils/Constants.esm.js.map +1 -1
  98. package/dist/utils/Constants.js +93 -93
  99. package/dist/utils/Constants.js.map +1 -1
  100. package/dist/utils/EncodingUtils.d.ts +26 -26
  101. package/dist/utils/EncodingUtils.esm.js +44 -44
  102. package/dist/utils/EncodingUtils.js +44 -44
  103. package/dist/utils/NetworkUtils.d.ts +5 -5
  104. package/dist/utils/NetworkUtils.esm.js +38 -38
  105. package/dist/utils/NetworkUtils.js +38 -38
  106. package/package.json +77 -73
  107. package/dist/msal-node.cjs.development.js +0 -2705
  108. package/dist/msal-node.cjs.development.js.map +0 -1
  109. package/dist/msal-node.cjs.production.min.js +0 -2
  110. package/dist/msal-node.cjs.production.min.js.map +0 -1
  111. package/dist/msal-node.esm.js +0 -2594
  112. package/dist/msal-node.esm.js.map +0 -1
@@ -1,215 +1,215 @@
1
- /*! @azure/msal-node v2.0.0-alpha.1 2023-05-08 */
1
+ /*! @azure/msal-node v2.0.0-beta.0 2023-06-19 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
5
5
  var msalCommon = require('@azure/msal-common');
6
6
 
7
- /*
8
- * Copyright (c) Microsoft Corporation. All rights reserved.
9
- * Licensed under the MIT License.
10
- */
11
- /**
12
- * OAuth2.0 Device code client
13
- */
14
- class DeviceCodeClient extends msalCommon.BaseClient {
15
- constructor(configuration) {
16
- super(configuration);
17
- }
18
- /**
19
- * Gets device code from device code endpoint, calls back to with device code response, and
20
- * polls token endpoint to exchange device code for tokens
21
- * @param request
22
- */
23
- async acquireToken(request) {
24
- const deviceCodeResponse = await this.getDeviceCode(request);
25
- request.deviceCodeCallback(deviceCodeResponse);
26
- const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
27
- const response = await this.acquireTokenWithDeviceCode(request, deviceCodeResponse);
28
- const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
29
- // Validate response. This function throws a server error if an error is returned by the server.
30
- responseHandler.validateTokenResponse(response);
31
- return await responseHandler.handleServerTokenResponse(response, this.authority, reqTimestamp, request);
32
- }
33
- /**
34
- * Creates device code request and executes http GET
35
- * @param request
36
- */
37
- async getDeviceCode(request) {
38
- const queryParametersString = this.createExtraQueryParameters(request);
39
- const endpoint = msalCommon.UrlString.appendQueryString(this.authority.deviceCodeEndpoint, queryParametersString);
40
- const queryString = this.createQueryString(request);
41
- const headers = this.createTokenRequestHeaders();
42
- const thumbprint = {
43
- clientId: this.config.authOptions.clientId,
44
- authority: request.authority,
45
- scopes: request.scopes,
46
- claims: request.claims,
47
- authenticationScheme: request.authenticationScheme,
48
- resourceRequestMethod: request.resourceRequestMethod,
49
- resourceRequestUri: request.resourceRequestUri,
50
- shrClaims: request.shrClaims,
51
- sshKid: request.sshKid,
52
- };
53
- return this.executePostRequestToDeviceCodeEndpoint(endpoint, queryString, headers, thumbprint);
54
- }
55
- /**
56
- * Creates query string for the device code request
57
- * @param request
58
- */
59
- createExtraQueryParameters(request) {
60
- const parameterBuilder = new msalCommon.RequestParameterBuilder();
61
- if (request.extraQueryParameters) {
62
- parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
63
- }
64
- return parameterBuilder.createQueryString();
65
- }
66
- /**
67
- * Executes POST request to device code endpoint
68
- * @param deviceCodeEndpoint
69
- * @param queryString
70
- * @param headers
71
- */
72
- async executePostRequestToDeviceCodeEndpoint(deviceCodeEndpoint, queryString, headers, thumbprint) {
73
- const { body: { user_code: userCode, device_code: deviceCode, verification_uri: verificationUri, expires_in: expiresIn, interval, message, }, } = await this.networkManager.sendPostRequest(thumbprint, deviceCodeEndpoint, {
74
- body: queryString,
75
- headers: headers,
76
- });
77
- return {
78
- userCode,
79
- deviceCode,
80
- verificationUri,
81
- expiresIn,
82
- interval,
83
- message,
84
- };
85
- }
86
- /**
87
- * Create device code endpoint query parameters and returns string
88
- */
89
- createQueryString(request) {
90
- const parameterBuilder = new msalCommon.RequestParameterBuilder();
91
- parameterBuilder.addScopes(request.scopes);
92
- parameterBuilder.addClientId(this.config.authOptions.clientId);
93
- if (request.extraQueryParameters) {
94
- parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
95
- }
96
- if (!msalCommon.StringUtils.isEmpty(request.claims) ||
97
- (this.config.authOptions.clientCapabilities &&
98
- this.config.authOptions.clientCapabilities.length > 0)) {
99
- parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
100
- }
101
- return parameterBuilder.createQueryString();
102
- }
103
- /**
104
- * Breaks the polling with specific conditions.
105
- * @param request CommonDeviceCodeRequest
106
- * @param deviceCodeResponse DeviceCodeResponse
107
- */
108
- continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, userSpecifiedCancelFlag) {
109
- if (userSpecifiedCancelFlag) {
110
- this.logger.error("Token request cancelled by setting DeviceCodeRequest.cancel = true");
111
- throw msalCommon.ClientAuthError.createDeviceCodeCancelledError();
112
- }
113
- else if (userSpecifiedTimeout &&
114
- userSpecifiedTimeout < deviceCodeExpirationTime &&
115
- msalCommon.TimeUtils.nowSeconds() > userSpecifiedTimeout) {
116
- this.logger.error(`User defined timeout for device code polling reached. The timeout was set for ${userSpecifiedTimeout}`);
117
- throw msalCommon.ClientAuthError.createUserTimeoutReachedError();
118
- }
119
- else if (msalCommon.TimeUtils.nowSeconds() > deviceCodeExpirationTime) {
120
- if (userSpecifiedTimeout) {
121
- this.logger.verbose(`User specified timeout ignored as the device code has expired before the timeout elapsed. The user specified timeout was set for ${userSpecifiedTimeout}`);
122
- }
123
- this.logger.error(`Device code expired. Expiration time of device code was ${deviceCodeExpirationTime}`);
124
- throw msalCommon.ClientAuthError.createDeviceCodeExpiredError();
125
- }
126
- return true;
127
- }
128
- /**
129
- * Creates token request with device code response and polls token endpoint at interval set by the device code
130
- * response
131
- * @param request
132
- * @param deviceCodeResponse
133
- */
134
- async acquireTokenWithDeviceCode(request, deviceCodeResponse) {
135
- const queryParametersString = this.createTokenQueryParameters(request);
136
- const endpoint = msalCommon.UrlString.appendQueryString(this.authority.tokenEndpoint, queryParametersString);
137
- const requestBody = this.createTokenRequestBody(request, deviceCodeResponse);
138
- const headers = this.createTokenRequestHeaders();
139
- const userSpecifiedTimeout = request.timeout
140
- ? msalCommon.TimeUtils.nowSeconds() + request.timeout
141
- : undefined;
142
- const deviceCodeExpirationTime = msalCommon.TimeUtils.nowSeconds() + deviceCodeResponse.expiresIn;
143
- const pollingIntervalMilli = deviceCodeResponse.interval * 1000;
144
- /*
145
- * Poll token endpoint while (device code is not expired AND operation has not been cancelled by
146
- * setting CancellationToken.cancel = true). POST request is sent at interval set by pollingIntervalMilli
147
- */
148
- while (this.continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, request.cancel)) {
149
- const thumbprint = {
150
- clientId: this.config.authOptions.clientId,
151
- authority: request.authority,
152
- scopes: request.scopes,
153
- claims: request.claims,
154
- authenticationScheme: request.authenticationScheme,
155
- resourceRequestMethod: request.resourceRequestMethod,
156
- resourceRequestUri: request.resourceRequestUri,
157
- shrClaims: request.shrClaims,
158
- sshKid: request.sshKid,
159
- };
160
- const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint);
161
- if (response.body && response.body.error) {
162
- // user authorization is pending. Sleep for polling interval and try again
163
- if (response.body.error === msalCommon.Constants.AUTHORIZATION_PENDING) {
164
- this.logger.info("Authorization pending. Continue polling.");
165
- await msalCommon.TimeUtils.delay(pollingIntervalMilli);
166
- }
167
- else {
168
- // for any other error, throw
169
- this.logger.info("Unexpected error in polling from the server");
170
- throw msalCommon.ServerError.createPostRequestFailed(response.body.error);
171
- }
172
- }
173
- else {
174
- this.logger.verbose("Authorization completed successfully. Polling stopped.");
175
- return response.body;
176
- }
177
- }
178
- /*
179
- * The above code should've thrown by this point, but to satisfy TypeScript,
180
- * and in the rare case the conditionals in continuePolling() may not catch everything...
181
- */
182
- this.logger.error("Polling stopped for unknown reasons.");
183
- throw msalCommon.ClientAuthError.createDeviceCodeUnknownError();
184
- }
185
- /**
186
- * Creates query parameters and converts to string.
187
- * @param request
188
- * @param deviceCodeResponse
189
- */
190
- createTokenRequestBody(request, deviceCodeResponse) {
191
- const requestParameters = new msalCommon.RequestParameterBuilder();
192
- requestParameters.addScopes(request.scopes);
193
- requestParameters.addClientId(this.config.authOptions.clientId);
194
- requestParameters.addGrantType(msalCommon.GrantType.DEVICE_CODE_GRANT);
195
- requestParameters.addDeviceCode(deviceCodeResponse.deviceCode);
196
- const correlationId = request.correlationId ||
197
- this.config.cryptoInterface.createNewGuid();
198
- requestParameters.addCorrelationId(correlationId);
199
- requestParameters.addClientInfo();
200
- requestParameters.addLibraryInfo(this.config.libraryInfo);
201
- requestParameters.addApplicationTelemetry(this.config.telemetry.application);
202
- requestParameters.addThrottling();
203
- if (this.serverTelemetryManager) {
204
- requestParameters.addServerTelemetry(this.serverTelemetryManager);
205
- }
206
- if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
207
- (this.config.authOptions.clientCapabilities &&
208
- this.config.authOptions.clientCapabilities.length > 0)) {
209
- requestParameters.addClaims(request.claims, this.config.authOptions.clientCapabilities);
210
- }
211
- return requestParameters.createQueryString();
212
- }
7
+ /*
8
+ * Copyright (c) Microsoft Corporation. All rights reserved.
9
+ * Licensed under the MIT License.
10
+ */
11
+ /**
12
+ * OAuth2.0 Device code client
13
+ */
14
+ class DeviceCodeClient extends msalCommon.BaseClient {
15
+ constructor(configuration) {
16
+ super(configuration);
17
+ }
18
+ /**
19
+ * Gets device code from device code endpoint, calls back to with device code response, and
20
+ * polls token endpoint to exchange device code for tokens
21
+ * @param request
22
+ */
23
+ async acquireToken(request) {
24
+ const deviceCodeResponse = await this.getDeviceCode(request);
25
+ request.deviceCodeCallback(deviceCodeResponse);
26
+ const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
27
+ const response = await this.acquireTokenWithDeviceCode(request, deviceCodeResponse);
28
+ const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
29
+ // Validate response. This function throws a server error if an error is returned by the server.
30
+ responseHandler.validateTokenResponse(response);
31
+ return await responseHandler.handleServerTokenResponse(response, this.authority, reqTimestamp, request);
32
+ }
33
+ /**
34
+ * Creates device code request and executes http GET
35
+ * @param request
36
+ */
37
+ async getDeviceCode(request) {
38
+ const queryParametersString = this.createExtraQueryParameters(request);
39
+ const endpoint = msalCommon.UrlString.appendQueryString(this.authority.deviceCodeEndpoint, queryParametersString);
40
+ const queryString = this.createQueryString(request);
41
+ const headers = this.createTokenRequestHeaders();
42
+ const thumbprint = {
43
+ clientId: this.config.authOptions.clientId,
44
+ authority: request.authority,
45
+ scopes: request.scopes,
46
+ claims: request.claims,
47
+ authenticationScheme: request.authenticationScheme,
48
+ resourceRequestMethod: request.resourceRequestMethod,
49
+ resourceRequestUri: request.resourceRequestUri,
50
+ shrClaims: request.shrClaims,
51
+ sshKid: request.sshKid,
52
+ };
53
+ return this.executePostRequestToDeviceCodeEndpoint(endpoint, queryString, headers, thumbprint);
54
+ }
55
+ /**
56
+ * Creates query string for the device code request
57
+ * @param request
58
+ */
59
+ createExtraQueryParameters(request) {
60
+ const parameterBuilder = new msalCommon.RequestParameterBuilder();
61
+ if (request.extraQueryParameters) {
62
+ parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
63
+ }
64
+ return parameterBuilder.createQueryString();
65
+ }
66
+ /**
67
+ * Executes POST request to device code endpoint
68
+ * @param deviceCodeEndpoint
69
+ * @param queryString
70
+ * @param headers
71
+ */
72
+ async executePostRequestToDeviceCodeEndpoint(deviceCodeEndpoint, queryString, headers, thumbprint) {
73
+ const { body: { user_code: userCode, device_code: deviceCode, verification_uri: verificationUri, expires_in: expiresIn, interval, message, }, } = await this.networkManager.sendPostRequest(thumbprint, deviceCodeEndpoint, {
74
+ body: queryString,
75
+ headers: headers,
76
+ });
77
+ return {
78
+ userCode,
79
+ deviceCode,
80
+ verificationUri,
81
+ expiresIn,
82
+ interval,
83
+ message,
84
+ };
85
+ }
86
+ /**
87
+ * Create device code endpoint query parameters and returns string
88
+ */
89
+ createQueryString(request) {
90
+ const parameterBuilder = new msalCommon.RequestParameterBuilder();
91
+ parameterBuilder.addScopes(request.scopes);
92
+ parameterBuilder.addClientId(this.config.authOptions.clientId);
93
+ if (request.extraQueryParameters) {
94
+ parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
95
+ }
96
+ if (!msalCommon.StringUtils.isEmpty(request.claims) ||
97
+ (this.config.authOptions.clientCapabilities &&
98
+ this.config.authOptions.clientCapabilities.length > 0)) {
99
+ parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
100
+ }
101
+ return parameterBuilder.createQueryString();
102
+ }
103
+ /**
104
+ * Breaks the polling with specific conditions.
105
+ * @param request CommonDeviceCodeRequest
106
+ * @param deviceCodeResponse DeviceCodeResponse
107
+ */
108
+ continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, userSpecifiedCancelFlag) {
109
+ if (userSpecifiedCancelFlag) {
110
+ this.logger.error("Token request cancelled by setting DeviceCodeRequest.cancel = true");
111
+ throw msalCommon.ClientAuthError.createDeviceCodeCancelledError();
112
+ }
113
+ else if (userSpecifiedTimeout &&
114
+ userSpecifiedTimeout < deviceCodeExpirationTime &&
115
+ msalCommon.TimeUtils.nowSeconds() > userSpecifiedTimeout) {
116
+ this.logger.error(`User defined timeout for device code polling reached. The timeout was set for ${userSpecifiedTimeout}`);
117
+ throw msalCommon.ClientAuthError.createUserTimeoutReachedError();
118
+ }
119
+ else if (msalCommon.TimeUtils.nowSeconds() > deviceCodeExpirationTime) {
120
+ if (userSpecifiedTimeout) {
121
+ this.logger.verbose(`User specified timeout ignored as the device code has expired before the timeout elapsed. The user specified timeout was set for ${userSpecifiedTimeout}`);
122
+ }
123
+ this.logger.error(`Device code expired. Expiration time of device code was ${deviceCodeExpirationTime}`);
124
+ throw msalCommon.ClientAuthError.createDeviceCodeExpiredError();
125
+ }
126
+ return true;
127
+ }
128
+ /**
129
+ * Creates token request with device code response and polls token endpoint at interval set by the device code
130
+ * response
131
+ * @param request
132
+ * @param deviceCodeResponse
133
+ */
134
+ async acquireTokenWithDeviceCode(request, deviceCodeResponse) {
135
+ const queryParametersString = this.createTokenQueryParameters(request);
136
+ const endpoint = msalCommon.UrlString.appendQueryString(this.authority.tokenEndpoint, queryParametersString);
137
+ const requestBody = this.createTokenRequestBody(request, deviceCodeResponse);
138
+ const headers = this.createTokenRequestHeaders();
139
+ const userSpecifiedTimeout = request.timeout
140
+ ? msalCommon.TimeUtils.nowSeconds() + request.timeout
141
+ : undefined;
142
+ const deviceCodeExpirationTime = msalCommon.TimeUtils.nowSeconds() + deviceCodeResponse.expiresIn;
143
+ const pollingIntervalMilli = deviceCodeResponse.interval * 1000;
144
+ /*
145
+ * Poll token endpoint while (device code is not expired AND operation has not been cancelled by
146
+ * setting CancellationToken.cancel = true). POST request is sent at interval set by pollingIntervalMilli
147
+ */
148
+ while (this.continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, request.cancel)) {
149
+ const thumbprint = {
150
+ clientId: this.config.authOptions.clientId,
151
+ authority: request.authority,
152
+ scopes: request.scopes,
153
+ claims: request.claims,
154
+ authenticationScheme: request.authenticationScheme,
155
+ resourceRequestMethod: request.resourceRequestMethod,
156
+ resourceRequestUri: request.resourceRequestUri,
157
+ shrClaims: request.shrClaims,
158
+ sshKid: request.sshKid,
159
+ };
160
+ const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint);
161
+ if (response.body && response.body.error) {
162
+ // user authorization is pending. Sleep for polling interval and try again
163
+ if (response.body.error === msalCommon.Constants.AUTHORIZATION_PENDING) {
164
+ this.logger.info("Authorization pending. Continue polling.");
165
+ await msalCommon.TimeUtils.delay(pollingIntervalMilli);
166
+ }
167
+ else {
168
+ // for any other error, throw
169
+ this.logger.info("Unexpected error in polling from the server");
170
+ throw msalCommon.ServerError.createPostRequestFailed(response.body.error);
171
+ }
172
+ }
173
+ else {
174
+ this.logger.verbose("Authorization completed successfully. Polling stopped.");
175
+ return response.body;
176
+ }
177
+ }
178
+ /*
179
+ * The above code should've thrown by this point, but to satisfy TypeScript,
180
+ * and in the rare case the conditionals in continuePolling() may not catch everything...
181
+ */
182
+ this.logger.error("Polling stopped for unknown reasons.");
183
+ throw msalCommon.ClientAuthError.createDeviceCodeUnknownError();
184
+ }
185
+ /**
186
+ * Creates query parameters and converts to string.
187
+ * @param request
188
+ * @param deviceCodeResponse
189
+ */
190
+ createTokenRequestBody(request, deviceCodeResponse) {
191
+ const requestParameters = new msalCommon.RequestParameterBuilder();
192
+ requestParameters.addScopes(request.scopes);
193
+ requestParameters.addClientId(this.config.authOptions.clientId);
194
+ requestParameters.addGrantType(msalCommon.GrantType.DEVICE_CODE_GRANT);
195
+ requestParameters.addDeviceCode(deviceCodeResponse.deviceCode);
196
+ const correlationId = request.correlationId ||
197
+ this.config.cryptoInterface.createNewGuid();
198
+ requestParameters.addCorrelationId(correlationId);
199
+ requestParameters.addClientInfo();
200
+ requestParameters.addLibraryInfo(this.config.libraryInfo);
201
+ requestParameters.addApplicationTelemetry(this.config.telemetry.application);
202
+ requestParameters.addThrottling();
203
+ if (this.serverTelemetryManager) {
204
+ requestParameters.addServerTelemetry(this.serverTelemetryManager);
205
+ }
206
+ if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
207
+ (this.config.authOptions.clientCapabilities &&
208
+ this.config.authOptions.clientCapabilities.length > 0)) {
209
+ requestParameters.addClaims(request.claims, this.config.authOptions.clientCapabilities);
210
+ }
211
+ return requestParameters.createQueryString();
212
+ }
213
213
  }
214
214
 
215
215
  exports.DeviceCodeClient = DeviceCodeClient;
@@ -1,40 +1,40 @@
1
- import { AuthenticationResult, IAppTokenProvider, Logger } from "@azure/msal-common";
2
- import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
3
- import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
4
- import { ClientCredentialRequest } from "../request/ClientCredentialRequest";
5
- import { OnBehalfOfRequest } from "../request/OnBehalfOfRequest";
6
- import { RefreshTokenRequest } from "../request/RefreshTokenRequest";
7
- import { SilentFlowRequest } from "../request/SilentFlowRequest";
8
- import { UsernamePasswordRequest } from "../request/UsernamePasswordRequest";
9
- import { TokenCache } from "../cache/TokenCache";
10
- /**
11
- * Interface for the ConfidentialClientApplication class defining the public API signatures
12
- * @public
13
- */
14
- export interface IConfidentialClientApplication {
15
- /** Creates the URL of the authorization request */
16
- getAuthCodeUrl(request: AuthorizationUrlRequest): Promise<string>;
17
- /** Acquires a token by exchanging the authorization code received from the first step of OAuth 2.0 Authorization Code Flow */
18
- acquireTokenByCode(request: AuthorizationCodeRequest): Promise<AuthenticationResult>;
19
- /** Acquires a token silently when a user specifies the account the token is requested for */
20
- acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult | null>;
21
- /** Acquires a token by exchanging the refresh token provided for a new set of tokens */
22
- acquireTokenByRefreshToken(request: RefreshTokenRequest): Promise<AuthenticationResult | null>;
23
- /** Acquires tokens from the authority for the application (not for an end user) */
24
- acquireTokenByClientCredential(request: ClientCredentialRequest): Promise<AuthenticationResult | null>;
25
- /** Acquires tokens from the authority for the application */
26
- acquireTokenOnBehalfOf(request: OnBehalfOfRequest): Promise<AuthenticationResult | null>;
27
- /** Acquires tokens with password grant by exchanging client applications username and password for credentials */
28
- acquireTokenByUsernamePassword(request: UsernamePasswordRequest): Promise<AuthenticationResult | null>;
29
- /** Gets the token cache for the application */
30
- getTokenCache(): TokenCache;
31
- /** Returns the logger instance */
32
- getLogger(): Logger;
33
- /** Replaces the default logger set in configurations with new Logger with new configurations */
34
- setLogger(logger: Logger): void;
35
- /** Clear the cache */
36
- clearCache(): void;
37
- /** This extensibility point is meant for Azure SDK to enhance Managed Identity support */
38
- SetAppTokenProvider(provider: IAppTokenProvider): void;
39
- }
1
+ import { AuthenticationResult, IAppTokenProvider, Logger } from "@azure/msal-common";
2
+ import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
3
+ import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
4
+ import { ClientCredentialRequest } from "../request/ClientCredentialRequest";
5
+ import { OnBehalfOfRequest } from "../request/OnBehalfOfRequest";
6
+ import { RefreshTokenRequest } from "../request/RefreshTokenRequest";
7
+ import { SilentFlowRequest } from "../request/SilentFlowRequest";
8
+ import { UsernamePasswordRequest } from "../request/UsernamePasswordRequest";
9
+ import { TokenCache } from "../cache/TokenCache";
10
+ /**
11
+ * Interface for the ConfidentialClientApplication class defining the public API signatures
12
+ * @public
13
+ */
14
+ export interface IConfidentialClientApplication {
15
+ /** Creates the URL of the authorization request */
16
+ getAuthCodeUrl(request: AuthorizationUrlRequest): Promise<string>;
17
+ /** Acquires a token by exchanging the authorization code received from the first step of OAuth 2.0 Authorization Code Flow */
18
+ acquireTokenByCode(request: AuthorizationCodeRequest): Promise<AuthenticationResult>;
19
+ /** Acquires a token silently when a user specifies the account the token is requested for */
20
+ acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult | null>;
21
+ /** Acquires a token by exchanging the refresh token provided for a new set of tokens */
22
+ acquireTokenByRefreshToken(request: RefreshTokenRequest): Promise<AuthenticationResult | null>;
23
+ /** Acquires tokens from the authority for the application (not for an end user) */
24
+ acquireTokenByClientCredential(request: ClientCredentialRequest): Promise<AuthenticationResult | null>;
25
+ /** Acquires tokens from the authority for the application */
26
+ acquireTokenOnBehalfOf(request: OnBehalfOfRequest): Promise<AuthenticationResult | null>;
27
+ /** Acquires tokens with password grant by exchanging client applications username and password for credentials */
28
+ acquireTokenByUsernamePassword(request: UsernamePasswordRequest): Promise<AuthenticationResult | null>;
29
+ /** Gets the token cache for the application */
30
+ getTokenCache(): TokenCache;
31
+ /** Returns the logger instance */
32
+ getLogger(): Logger;
33
+ /** Replaces the default logger set in configurations with new Logger with new configurations */
34
+ setLogger(logger: Logger): void;
35
+ /** Clear the cache */
36
+ clearCache(): void;
37
+ /** This extensibility point is meant for Azure SDK to enhance Managed Identity support */
38
+ SetAppTokenProvider(provider: IAppTokenProvider): void;
39
+ }
40
40
  //# sourceMappingURL=IConfidentialClientApplication.d.ts.map
@@ -1,43 +1,43 @@
1
- import { AccountInfo, AuthenticationResult, Logger } from "@azure/msal-common";
2
- import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
3
- import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
4
- import { DeviceCodeRequest } from "../request/DeviceCodeRequest";
5
- import { RefreshTokenRequest } from "../request/RefreshTokenRequest";
6
- import { SilentFlowRequest } from "../request/SilentFlowRequest";
7
- import { UsernamePasswordRequest } from "../request/UsernamePasswordRequest";
8
- import { TokenCache } from "../cache/TokenCache";
9
- import { InteractiveRequest } from "../request/InteractiveRequest";
10
- import { SignOutRequest } from "../request/SignOutRequest";
11
- /**
12
- * Interface for the PublicClientApplication class defining the public API signatures
13
- * @public
14
- */
15
- export interface IPublicClientApplication {
16
- /** Creates the URL of the authorization request */
17
- getAuthCodeUrl(request: AuthorizationUrlRequest): Promise<string>;
18
- /** Acquires a token by exchanging the authorization code received from the first step of OAuth 2.0 Authorization Code Flow */
19
- acquireTokenByCode(request: AuthorizationCodeRequest): Promise<AuthenticationResult>;
20
- /** Acquires a token interactively */
21
- acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult>;
22
- /** Acquires a token silently when a user specifies the account the token is requested for */
23
- acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>;
24
- /** Acquires a token by exchanging the refresh token provided for a new set of tokens */
25
- acquireTokenByRefreshToken(request: RefreshTokenRequest): Promise<AuthenticationResult | null>;
26
- /** Acquires a token from the authority using OAuth2.0 device code flow */
27
- acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult | null>;
28
- /** Acquires tokens with password grant by exchanging client applications username and password for credentials */
29
- acquireTokenByUsernamePassword(request: UsernamePasswordRequest): Promise<AuthenticationResult | null>;
30
- /** Gets the token cache for the application */
31
- getTokenCache(): TokenCache;
32
- /** Returns the logger instance */
33
- getLogger(): Logger;
34
- /** Replaces the default logger set in configurations with new Logger with new configurations */
35
- setLogger(logger: Logger): void;
36
- /** Clear the cache */
37
- clearCache(): void;
38
- /** Gets all cached accounts */
39
- getAllAccounts(): Promise<AccountInfo[]>;
40
- /** Removes cache artifacts associated with the given account */
41
- signOut(request: SignOutRequest): Promise<void>;
42
- }
1
+ import { AccountInfo, AuthenticationResult, Logger } from "@azure/msal-common";
2
+ import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
3
+ import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
4
+ import { DeviceCodeRequest } from "../request/DeviceCodeRequest";
5
+ import { RefreshTokenRequest } from "../request/RefreshTokenRequest";
6
+ import { SilentFlowRequest } from "../request/SilentFlowRequest";
7
+ import { UsernamePasswordRequest } from "../request/UsernamePasswordRequest";
8
+ import { TokenCache } from "../cache/TokenCache";
9
+ import { InteractiveRequest } from "../request/InteractiveRequest";
10
+ import { SignOutRequest } from "../request/SignOutRequest";
11
+ /**
12
+ * Interface for the PublicClientApplication class defining the public API signatures
13
+ * @public
14
+ */
15
+ export interface IPublicClientApplication {
16
+ /** Creates the URL of the authorization request */
17
+ getAuthCodeUrl(request: AuthorizationUrlRequest): Promise<string>;
18
+ /** Acquires a token by exchanging the authorization code received from the first step of OAuth 2.0 Authorization Code Flow */
19
+ acquireTokenByCode(request: AuthorizationCodeRequest): Promise<AuthenticationResult>;
20
+ /** Acquires a token interactively */
21
+ acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult>;
22
+ /** Acquires a token silently when a user specifies the account the token is requested for */
23
+ acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>;
24
+ /** Acquires a token by exchanging the refresh token provided for a new set of tokens */
25
+ acquireTokenByRefreshToken(request: RefreshTokenRequest): Promise<AuthenticationResult | null>;
26
+ /** Acquires a token from the authority using OAuth2.0 device code flow */
27
+ acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult | null>;
28
+ /** Acquires tokens with password grant by exchanging client applications username and password for credentials */
29
+ acquireTokenByUsernamePassword(request: UsernamePasswordRequest): Promise<AuthenticationResult | null>;
30
+ /** Gets the token cache for the application */
31
+ getTokenCache(): TokenCache;
32
+ /** Returns the logger instance */
33
+ getLogger(): Logger;
34
+ /** Replaces the default logger set in configurations with new Logger with new configurations */
35
+ setLogger(logger: Logger): void;
36
+ /** Clear the cache */
37
+ clearCache(): void;
38
+ /** Gets all cached accounts */
39
+ getAllAccounts(): Promise<AccountInfo[]>;
40
+ /** Removes cache artifacts associated with the given account */
41
+ signOut(request: SignOutRequest): Promise<void>;
42
+ }
43
43
  //# sourceMappingURL=IPublicClientApplication.d.ts.map