@typespec/ts-http-runtime 0.1.0-alpha.20250325.2 → 0.2.0-alpha.20250326.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 (261) hide show
  1. package/dist/browser/auth/credentials.d.ts +77 -0
  2. package/dist/browser/auth/credentials.js +27 -0
  3. package/dist/browser/auth/credentials.js.map +1 -0
  4. package/dist/browser/auth/oauth2Flows.d.ts +57 -0
  5. package/dist/browser/{abort-controller/AbortSignalLike.js → auth/oauth2Flows.js} +1 -1
  6. package/dist/browser/auth/oauth2Flows.js.map +1 -0
  7. package/dist/browser/auth/schemes.d.ts +53 -0
  8. package/dist/{esm/abort-controller/AbortSignalLike.js → browser/auth/schemes.js} +1 -1
  9. package/dist/browser/auth/schemes.js.map +1 -0
  10. package/dist/browser/client/clientHelpers.d.ts +1 -20
  11. package/dist/browser/client/clientHelpers.js +21 -30
  12. package/dist/browser/client/clientHelpers.js.map +1 -1
  13. package/dist/browser/client/common.d.ts +13 -15
  14. package/dist/browser/client/common.js.map +1 -1
  15. package/dist/browser/client/getClient.d.ts +1 -9
  16. package/dist/browser/client/getClient.js +8 -16
  17. package/dist/browser/client/getClient.js.map +1 -1
  18. package/dist/browser/constants.js +1 -1
  19. package/dist/browser/constants.js.map +1 -1
  20. package/dist/browser/index.d.ts +3 -3
  21. package/dist/browser/index.js +2 -2
  22. package/dist/browser/index.js.map +1 -1
  23. package/dist/browser/interfaces.d.ts +10 -2
  24. package/dist/browser/interfaces.js.map +1 -1
  25. package/dist/browser/pipelineRequest.d.ts +1 -2
  26. package/dist/browser/pipelineRequest.js.map +1 -1
  27. package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
  28. package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js +31 -0
  29. package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
  30. package/dist/browser/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
  31. package/dist/browser/policies/auth/basicAuthenticationPolicy.js +31 -0
  32. package/dist/browser/policies/auth/basicAuthenticationPolicy.js.map +1 -0
  33. package/dist/browser/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
  34. package/dist/browser/policies/auth/bearerAuthenticationPolicy.js +31 -0
  35. package/dist/browser/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
  36. package/dist/browser/policies/auth/checkInsecureConnection.d.ts +9 -0
  37. package/dist/browser/policies/auth/checkInsecureConnection.js +50 -0
  38. package/dist/browser/policies/auth/checkInsecureConnection.js.map +1 -0
  39. package/dist/browser/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
  40. package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js +31 -0
  41. package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
  42. package/dist/browser/util/aborterUtils.d.ts +3 -4
  43. package/dist/browser/util/aborterUtils.js.map +1 -1
  44. package/dist/browser/util/helpers.d.ts +1 -2
  45. package/dist/browser/util/helpers.js.map +1 -1
  46. package/dist/commonjs/auth/credentials.d.ts +77 -0
  47. package/dist/commonjs/auth/credentials.js +33 -0
  48. package/dist/commonjs/auth/credentials.js.map +1 -0
  49. package/dist/commonjs/auth/oauth2Flows.d.ts +57 -0
  50. package/dist/commonjs/{abort-controller/AbortSignalLike.js → auth/oauth2Flows.js} +1 -1
  51. package/dist/commonjs/auth/oauth2Flows.js.map +1 -0
  52. package/dist/commonjs/auth/schemes.d.ts +53 -0
  53. package/dist/commonjs/auth/schemes.js +5 -0
  54. package/dist/commonjs/auth/schemes.js.map +1 -0
  55. package/dist/commonjs/client/clientHelpers.d.ts +1 -20
  56. package/dist/commonjs/client/clientHelpers.js +21 -31
  57. package/dist/commonjs/client/clientHelpers.js.map +1 -1
  58. package/dist/commonjs/client/common.d.ts +13 -15
  59. package/dist/commonjs/client/common.js.map +1 -1
  60. package/dist/commonjs/client/getClient.d.ts +1 -9
  61. package/dist/commonjs/client/getClient.js +8 -16
  62. package/dist/commonjs/client/getClient.js.map +1 -1
  63. package/dist/commonjs/constants.js +1 -1
  64. package/dist/commonjs/constants.js.map +1 -1
  65. package/dist/commonjs/index.d.ts +3 -3
  66. package/dist/commonjs/index.js +4 -5
  67. package/dist/commonjs/index.js.map +1 -1
  68. package/dist/commonjs/interfaces.d.ts +10 -2
  69. package/dist/commonjs/interfaces.js.map +1 -1
  70. package/dist/commonjs/pipelineRequest.d.ts +1 -2
  71. package/dist/commonjs/pipelineRequest.js.map +1 -1
  72. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
  73. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js +35 -0
  74. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
  75. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
  76. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js +35 -0
  77. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js.map +1 -0
  78. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
  79. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js +35 -0
  80. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
  81. package/dist/commonjs/policies/auth/checkInsecureConnection.d.ts +9 -0
  82. package/dist/commonjs/policies/auth/checkInsecureConnection.js +53 -0
  83. package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +1 -0
  84. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
  85. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js +35 -0
  86. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
  87. package/dist/commonjs/util/aborterUtils.d.ts +3 -4
  88. package/dist/commonjs/util/aborterUtils.js.map +1 -1
  89. package/dist/commonjs/util/helpers.d.ts +1 -2
  90. package/dist/commonjs/util/helpers.js.map +1 -1
  91. package/dist/esm/auth/credentials.d.ts +77 -0
  92. package/dist/esm/auth/credentials.js +27 -0
  93. package/dist/esm/auth/credentials.js.map +1 -0
  94. package/dist/esm/auth/oauth2Flows.d.ts +57 -0
  95. package/dist/{react-native/abort-controller/AbortSignalLike.js → esm/auth/oauth2Flows.js} +1 -1
  96. package/dist/esm/auth/oauth2Flows.js.map +1 -0
  97. package/dist/esm/auth/schemes.d.ts +53 -0
  98. package/dist/esm/auth/schemes.js +4 -0
  99. package/dist/esm/auth/schemes.js.map +1 -0
  100. package/dist/esm/client/clientHelpers.d.ts +1 -20
  101. package/dist/esm/client/clientHelpers.js +21 -30
  102. package/dist/esm/client/clientHelpers.js.map +1 -1
  103. package/dist/esm/client/common.d.ts +13 -15
  104. package/dist/esm/client/common.js.map +1 -1
  105. package/dist/esm/client/getClient.d.ts +1 -9
  106. package/dist/esm/client/getClient.js +8 -16
  107. package/dist/esm/client/getClient.js.map +1 -1
  108. package/dist/esm/constants.js +1 -1
  109. package/dist/esm/constants.js.map +1 -1
  110. package/dist/esm/index.d.ts +3 -3
  111. package/dist/esm/index.js +2 -2
  112. package/dist/esm/index.js.map +1 -1
  113. package/dist/esm/interfaces.d.ts +10 -2
  114. package/dist/esm/interfaces.js.map +1 -1
  115. package/dist/esm/pipelineRequest.d.ts +1 -2
  116. package/dist/esm/pipelineRequest.js.map +1 -1
  117. package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
  118. package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js +31 -0
  119. package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
  120. package/dist/esm/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
  121. package/dist/esm/policies/auth/basicAuthenticationPolicy.js +31 -0
  122. package/dist/esm/policies/auth/basicAuthenticationPolicy.js.map +1 -0
  123. package/dist/esm/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
  124. package/dist/esm/policies/auth/bearerAuthenticationPolicy.js +31 -0
  125. package/dist/esm/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
  126. package/dist/esm/policies/auth/checkInsecureConnection.d.ts +9 -0
  127. package/dist/esm/policies/auth/checkInsecureConnection.js +50 -0
  128. package/dist/esm/policies/auth/checkInsecureConnection.js.map +1 -0
  129. package/dist/esm/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
  130. package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js +31 -0
  131. package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
  132. package/dist/esm/util/aborterUtils.d.ts +3 -4
  133. package/dist/esm/util/aborterUtils.js.map +1 -1
  134. package/dist/esm/util/helpers.d.ts +1 -2
  135. package/dist/esm/util/helpers.js.map +1 -1
  136. package/dist/react-native/auth/credentials.d.ts +77 -0
  137. package/dist/react-native/auth/credentials.js +27 -0
  138. package/dist/react-native/auth/credentials.js.map +1 -0
  139. package/dist/react-native/auth/oauth2Flows.d.ts +57 -0
  140. package/dist/react-native/auth/oauth2Flows.js +4 -0
  141. package/dist/react-native/auth/oauth2Flows.js.map +1 -0
  142. package/dist/react-native/auth/schemes.d.ts +53 -0
  143. package/dist/react-native/auth/schemes.js +4 -0
  144. package/dist/react-native/auth/schemes.js.map +1 -0
  145. package/dist/react-native/client/clientHelpers.d.ts +1 -20
  146. package/dist/react-native/client/clientHelpers.js +21 -30
  147. package/dist/react-native/client/clientHelpers.js.map +1 -1
  148. package/dist/react-native/client/common.d.ts +13 -15
  149. package/dist/react-native/client/common.js.map +1 -1
  150. package/dist/react-native/client/getClient.d.ts +1 -9
  151. package/dist/react-native/client/getClient.js +8 -16
  152. package/dist/react-native/client/getClient.js.map +1 -1
  153. package/dist/react-native/constants.js +1 -1
  154. package/dist/react-native/constants.js.map +1 -1
  155. package/dist/react-native/index.d.ts +3 -3
  156. package/dist/react-native/index.js +2 -2
  157. package/dist/react-native/index.js.map +1 -1
  158. package/dist/react-native/interfaces.d.ts +10 -2
  159. package/dist/react-native/interfaces.js.map +1 -1
  160. package/dist/react-native/pipelineRequest.d.ts +1 -2
  161. package/dist/react-native/pipelineRequest.js.map +1 -1
  162. package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
  163. package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js +31 -0
  164. package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
  165. package/dist/react-native/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
  166. package/dist/react-native/policies/auth/basicAuthenticationPolicy.js +31 -0
  167. package/dist/react-native/policies/auth/basicAuthenticationPolicy.js.map +1 -0
  168. package/dist/react-native/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
  169. package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js +31 -0
  170. package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
  171. package/dist/react-native/policies/auth/checkInsecureConnection.d.ts +9 -0
  172. package/dist/react-native/policies/auth/checkInsecureConnection.js +50 -0
  173. package/dist/react-native/policies/auth/checkInsecureConnection.js.map +1 -0
  174. package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
  175. package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js +31 -0
  176. package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
  177. package/dist/react-native/util/aborterUtils.d.ts +3 -4
  178. package/dist/react-native/util/aborterUtils.js.map +1 -1
  179. package/dist/react-native/util/helpers.d.ts +1 -2
  180. package/dist/react-native/util/helpers.js.map +1 -1
  181. package/package.json +1 -1
  182. package/dist/browser/abort-controller/AbortSignalLike.d.ts +0 -19
  183. package/dist/browser/abort-controller/AbortSignalLike.js.map +0 -1
  184. package/dist/browser/accessTokenCache.d.ts +0 -40
  185. package/dist/browser/accessTokenCache.js +0 -32
  186. package/dist/browser/accessTokenCache.js.map +0 -1
  187. package/dist/browser/auth/keyCredential.d.ts +0 -16
  188. package/dist/browser/auth/keyCredential.js +0 -12
  189. package/dist/browser/auth/keyCredential.js.map +0 -1
  190. package/dist/browser/auth/tokenCredential.d.ts +0 -71
  191. package/dist/browser/auth/tokenCredential.js +0 -19
  192. package/dist/browser/auth/tokenCredential.js.map +0 -1
  193. package/dist/browser/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
  194. package/dist/browser/client/keyCredentialAuthenticationPolicy.js +0 -16
  195. package/dist/browser/client/keyCredentialAuthenticationPolicy.js.map +0 -1
  196. package/dist/browser/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
  197. package/dist/browser/policies/bearerTokenAuthenticationPolicy.js +0 -107
  198. package/dist/browser/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
  199. package/dist/browser/util/tokenCycler.d.ts +0 -45
  200. package/dist/browser/util/tokenCycler.js +0 -162
  201. package/dist/browser/util/tokenCycler.js.map +0 -1
  202. package/dist/commonjs/abort-controller/AbortSignalLike.d.ts +0 -19
  203. package/dist/commonjs/abort-controller/AbortSignalLike.js.map +0 -1
  204. package/dist/commonjs/accessTokenCache.d.ts +0 -40
  205. package/dist/commonjs/accessTokenCache.js +0 -36
  206. package/dist/commonjs/accessTokenCache.js.map +0 -1
  207. package/dist/commonjs/auth/keyCredential.d.ts +0 -16
  208. package/dist/commonjs/auth/keyCredential.js +0 -15
  209. package/dist/commonjs/auth/keyCredential.js.map +0 -1
  210. package/dist/commonjs/auth/tokenCredential.d.ts +0 -71
  211. package/dist/commonjs/auth/tokenCredential.js +0 -22
  212. package/dist/commonjs/auth/tokenCredential.js.map +0 -1
  213. package/dist/commonjs/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
  214. package/dist/commonjs/client/keyCredentialAuthenticationPolicy.js +0 -20
  215. package/dist/commonjs/client/keyCredentialAuthenticationPolicy.js.map +0 -1
  216. package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
  217. package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js +0 -111
  218. package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
  219. package/dist/commonjs/util/tokenCycler.d.ts +0 -45
  220. package/dist/commonjs/util/tokenCycler.js +0 -166
  221. package/dist/commonjs/util/tokenCycler.js.map +0 -1
  222. package/dist/esm/abort-controller/AbortSignalLike.d.ts +0 -19
  223. package/dist/esm/abort-controller/AbortSignalLike.js.map +0 -1
  224. package/dist/esm/accessTokenCache.d.ts +0 -40
  225. package/dist/esm/accessTokenCache.js +0 -32
  226. package/dist/esm/accessTokenCache.js.map +0 -1
  227. package/dist/esm/auth/keyCredential.d.ts +0 -16
  228. package/dist/esm/auth/keyCredential.js +0 -12
  229. package/dist/esm/auth/keyCredential.js.map +0 -1
  230. package/dist/esm/auth/tokenCredential.d.ts +0 -71
  231. package/dist/esm/auth/tokenCredential.js +0 -19
  232. package/dist/esm/auth/tokenCredential.js.map +0 -1
  233. package/dist/esm/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
  234. package/dist/esm/client/keyCredentialAuthenticationPolicy.js +0 -16
  235. package/dist/esm/client/keyCredentialAuthenticationPolicy.js.map +0 -1
  236. package/dist/esm/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
  237. package/dist/esm/policies/bearerTokenAuthenticationPolicy.js +0 -107
  238. package/dist/esm/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
  239. package/dist/esm/util/tokenCycler.d.ts +0 -45
  240. package/dist/esm/util/tokenCycler.js +0 -162
  241. package/dist/esm/util/tokenCycler.js.map +0 -1
  242. package/dist/react-native/abort-controller/AbortSignalLike.d.ts +0 -19
  243. package/dist/react-native/abort-controller/AbortSignalLike.js.map +0 -1
  244. package/dist/react-native/accessTokenCache.d.ts +0 -40
  245. package/dist/react-native/accessTokenCache.js +0 -32
  246. package/dist/react-native/accessTokenCache.js.map +0 -1
  247. package/dist/react-native/auth/keyCredential.d.ts +0 -16
  248. package/dist/react-native/auth/keyCredential.js +0 -12
  249. package/dist/react-native/auth/keyCredential.js.map +0 -1
  250. package/dist/react-native/auth/tokenCredential.d.ts +0 -71
  251. package/dist/react-native/auth/tokenCredential.js +0 -19
  252. package/dist/react-native/auth/tokenCredential.js.map +0 -1
  253. package/dist/react-native/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
  254. package/dist/react-native/client/keyCredentialAuthenticationPolicy.js +0 -16
  255. package/dist/react-native/client/keyCredentialAuthenticationPolicy.js.map +0 -1
  256. package/dist/react-native/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
  257. package/dist/react-native/policies/bearerTokenAuthenticationPolicy.js +0 -107
  258. package/dist/react-native/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
  259. package/dist/react-native/util/tokenCycler.d.ts +0 -45
  260. package/dist/react-native/util/tokenCycler.js +0 -162
  261. package/dist/react-native/util/tokenCycler.js.map +0 -1
@@ -1,40 +0,0 @@
1
- import type { AccessToken } from "./auth/tokenCredential.js";
2
- /**
3
- * Defines the default token refresh buffer duration.
4
- */
5
- export declare const DefaultTokenRefreshBufferMs: number;
6
- /**
7
- * Provides a cache for an AccessToken that was that
8
- * was returned from a TokenCredential.
9
- */
10
- export interface AccessTokenCache {
11
- /**
12
- * Sets the cached token.
13
- *
14
- * @param accessToken - The AccessToken to be cached or null to
15
- * clear the cached token.
16
- */
17
- setCachedToken(accessToken: AccessToken | undefined): void;
18
- /**
19
- * Returns the cached AccessToken or undefined if nothing is cached.
20
- */
21
- getCachedToken(): AccessToken | undefined;
22
- }
23
- /**
24
- * Provides an AccessTokenCache implementation which clears
25
- * the cached AccessToken's after the expiresOnTimestamp has
26
- * passed.
27
- * @internal
28
- */
29
- export declare class ExpiringAccessTokenCache implements AccessTokenCache {
30
- private tokenRefreshBufferMs;
31
- private cachedToken?;
32
- /**
33
- * Constructs an instance of ExpiringAccessTokenCache with
34
- * an optional expiration buffer time.
35
- */
36
- constructor(tokenRefreshBufferMs?: number);
37
- setCachedToken(accessToken: AccessToken | undefined): void;
38
- getCachedToken(): AccessToken | undefined;
39
- }
40
- //# sourceMappingURL=accessTokenCache.d.ts.map
@@ -1,32 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /**
4
- * Defines the default token refresh buffer duration.
5
- */
6
- export const DefaultTokenRefreshBufferMs = 2 * 60 * 1000; // 2 Minutes
7
- /**
8
- * Provides an AccessTokenCache implementation which clears
9
- * the cached AccessToken's after the expiresOnTimestamp has
10
- * passed.
11
- * @internal
12
- */
13
- export class ExpiringAccessTokenCache {
14
- /**
15
- * Constructs an instance of ExpiringAccessTokenCache with
16
- * an optional expiration buffer time.
17
- */
18
- constructor(tokenRefreshBufferMs = DefaultTokenRefreshBufferMs) {
19
- this.tokenRefreshBufferMs = tokenRefreshBufferMs;
20
- }
21
- setCachedToken(accessToken) {
22
- this.cachedToken = accessToken;
23
- }
24
- getCachedToken() {
25
- if (this.cachedToken &&
26
- Date.now() + this.tokenRefreshBufferMs >= this.cachedToken.expiresOnTimestamp) {
27
- this.cachedToken = undefined;
28
- }
29
- return this.cachedToken;
30
- }
31
- }
32
- //# sourceMappingURL=accessTokenCache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accessTokenCache.js","sourceRoot":"","sources":["../../src/accessTokenCache.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAqBtE;;;;;GAKG;AACH,MAAM,OAAO,wBAAwB;IAInC;;;OAGG;IACH,YAAY,uBAA+B,2BAA2B;QACpE,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IACnD,CAAC;IAED,cAAc,CAAC,WAAoC;QACjD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,cAAc;QACZ,IACE,IAAI,CAAC,WAAW;YAChB,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAC7E,CAAC;YACD,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC/B,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken } from \"./auth/tokenCredential.js\";\n\n/**\n * Defines the default token refresh buffer duration.\n */\nexport const DefaultTokenRefreshBufferMs = 2 * 60 * 1000; // 2 Minutes\n\n/**\n * Provides a cache for an AccessToken that was that\n * was returned from a TokenCredential.\n */\nexport interface AccessTokenCache {\n /**\n * Sets the cached token.\n *\n * @param accessToken - The AccessToken to be cached or null to\n * clear the cached token.\n */\n setCachedToken(accessToken: AccessToken | undefined): void;\n\n /**\n * Returns the cached AccessToken or undefined if nothing is cached.\n */\n getCachedToken(): AccessToken | undefined;\n}\n\n/**\n * Provides an AccessTokenCache implementation which clears\n * the cached AccessToken's after the expiresOnTimestamp has\n * passed.\n * @internal\n */\nexport class ExpiringAccessTokenCache implements AccessTokenCache {\n private tokenRefreshBufferMs: number;\n private cachedToken?: AccessToken;\n\n /**\n * Constructs an instance of ExpiringAccessTokenCache with\n * an optional expiration buffer time.\n */\n constructor(tokenRefreshBufferMs: number = DefaultTokenRefreshBufferMs) {\n this.tokenRefreshBufferMs = tokenRefreshBufferMs;\n }\n\n setCachedToken(accessToken: AccessToken | undefined): void {\n this.cachedToken = accessToken;\n }\n\n getCachedToken(): AccessToken | undefined {\n if (\n this.cachedToken &&\n Date.now() + this.tokenRefreshBufferMs >= this.cachedToken.expiresOnTimestamp\n ) {\n this.cachedToken = undefined;\n }\n\n return this.cachedToken;\n }\n}\n"]}
@@ -1,16 +0,0 @@
1
- /**
2
- * Represents a credential defined by a static API key.
3
- */
4
- export interface KeyCredential {
5
- /**
6
- * The value of the API key represented as a string
7
- */
8
- readonly key: string;
9
- }
10
- /**
11
- * Tests an object to determine whether it implements KeyCredential.
12
- *
13
- * @param credential - The assumed KeyCredential to be tested.
14
- */
15
- export declare function isKeyCredential(credential: unknown): credential is KeyCredential;
16
- //# sourceMappingURL=keyCredential.d.ts.map
@@ -1,12 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { isObjectWithProperties } from "../util/typeGuards.js";
4
- /**
5
- * Tests an object to determine whether it implements KeyCredential.
6
- *
7
- * @param credential - The assumed KeyCredential to be tested.
8
- */
9
- export function isKeyCredential(credential) {
10
- return isObjectWithProperties(credential, ["key"]) && typeof credential.key === "string";
11
- }
12
- //# sourceMappingURL=keyCredential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keyCredential.js","sourceRoot":"","sources":["../../../src/auth/keyCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,UAAmB;IACjD,OAAO,sBAAsB,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,CAAC;AAC3F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { isObjectWithProperties } from \"../util/typeGuards.js\";\n\n/**\n * Represents a credential defined by a static API key.\n */\nexport interface KeyCredential {\n /**\n * The value of the API key represented as a string\n */\n readonly key: string;\n}\n\n/**\n * Tests an object to determine whether it implements KeyCredential.\n *\n * @param credential - The assumed KeyCredential to be tested.\n */\nexport function isKeyCredential(credential: unknown): credential is KeyCredential {\n return isObjectWithProperties(credential, [\"key\"]) && typeof credential.key === \"string\";\n}\n"]}
@@ -1,71 +0,0 @@
1
- import type { AbortSignalLike } from "../abort-controller/AbortSignalLike.js";
2
- /**
3
- * Represents a credential capable of providing an authentication token.
4
- */
5
- export interface TokenCredential {
6
- /**
7
- * Gets the token provided by this credential.
8
- *
9
- * This method is called automatically by Azure SDK client libraries. You may call this method
10
- * directly, but you must also handle token caching and token refreshing.
11
- *
12
- * @param scopes - The list of scopes for which the token will have access.
13
- * @param options - The options used to configure any requests this
14
- * TokenCredential implementation might make.
15
- */
16
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
17
- }
18
- /**
19
- * Defines options for TokenCredential.getToken.
20
- */
21
- export interface GetTokenOptions {
22
- /**
23
- * The signal which can be used to abort requests.
24
- */
25
- abortSignal?: AbortSignalLike;
26
- /**
27
- * Options used when creating and sending HTTP requests for this operation.
28
- */
29
- requestOptions?: {
30
- /**
31
- * The number of milliseconds a request can take before automatically being terminated.
32
- */
33
- timeout?: number;
34
- };
35
- /**
36
- * Claim details to perform the Continuous Access Evaluation authentication flow
37
- */
38
- claims?: string;
39
- /**
40
- * Indicates whether to enable the Continuous Access Evaluation authentication flow
41
- */
42
- enableCae?: boolean;
43
- /**
44
- * Allows specifying a tenantId. Useful to handle challenges that provide tenant Id hints.
45
- */
46
- tenantId?: string;
47
- }
48
- /**
49
- * Represents an access token with an expiration time.
50
- */
51
- export interface AccessToken {
52
- /**
53
- * The access token returned by the authentication service.
54
- */
55
- token: string;
56
- /**
57
- * The access token's expiration timestamp in milliseconds, UNIX epoch time.
58
- */
59
- expiresOnTimestamp: number;
60
- /**
61
- * The timestamp when the access token should be refreshed, in milliseconds, UNIX epoch time.
62
- */
63
- refreshAfterTimestamp?: number;
64
- }
65
- /**
66
- * Tests an object to determine whether it implements TokenCredential.
67
- *
68
- * @param credential - The assumed TokenCredential to be tested.
69
- */
70
- export declare function isTokenCredential(credential: unknown): credential is TokenCredential;
71
- //# sourceMappingURL=tokenCredential.d.ts.map
@@ -1,19 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /**
4
- * Tests an object to determine whether it implements TokenCredential.
5
- *
6
- * @param credential - The assumed TokenCredential to be tested.
7
- */
8
- export function isTokenCredential(credential) {
9
- // Check for an object with a 'getToken' function and possibly with
10
- // a 'signRequest' function. We do this check to make sure that
11
- // a ServiceClientCredentials implementor (like TokenClientCredentials
12
- // in ms-rest-nodeauth) doesn't get mistaken for a TokenCredential if
13
- // it doesn't actually implement TokenCredential also.
14
- const castCredential = credential;
15
- return (castCredential &&
16
- typeof castCredential.getToken === "function" &&
17
- (castCredential.signRequest === undefined || castCredential.getToken.length > 0));
18
- }
19
- //# sourceMappingURL=tokenCredential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tokenCredential.js","sourceRoot":"","sources":["../../../src/auth/tokenCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AA0ElC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAmB;IACnD,mEAAmE;IACnE,gEAAgE;IAChE,sEAAsE;IACtE,qEAAqE;IACrE,sDAAsD;IACtD,MAAM,cAAc,GAAG,UAGtB,CAAC;IACF,OAAO,CACL,cAAc;QACd,OAAO,cAAc,CAAC,QAAQ,KAAK,UAAU;QAC7C,CAAC,cAAc,CAAC,WAAW,KAAK,SAAS,IAAI,cAAc,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CACjF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\n\n/**\n * Represents a credential capable of providing an authentication token.\n */\nexport interface TokenCredential {\n /**\n * Gets the token provided by this credential.\n *\n * This method is called automatically by Azure SDK client libraries. You may call this method\n * directly, but you must also handle token caching and token refreshing.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;\n}\n\n/**\n * Defines options for TokenCredential.getToken.\n */\nexport interface GetTokenOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: {\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n };\n /**\n * Claim details to perform the Continuous Access Evaluation authentication flow\n */\n claims?: string;\n /**\n * Indicates whether to enable the Continuous Access Evaluation authentication flow\n */\n enableCae?: boolean;\n /**\n * Allows specifying a tenantId. Useful to handle challenges that provide tenant Id hints.\n */\n tenantId?: string;\n}\n\n/**\n * Represents an access token with an expiration time.\n */\nexport interface AccessToken {\n /**\n * The access token returned by the authentication service.\n */\n token: string;\n\n /**\n * The access token's expiration timestamp in milliseconds, UNIX epoch time.\n */\n expiresOnTimestamp: number;\n\n /**\n * The timestamp when the access token should be refreshed, in milliseconds, UNIX epoch time.\n */\n refreshAfterTimestamp?: number;\n\n // UNBRANDED DIFFERENCE: Unbranded Core does not support PoP (\"Proof-of-Presence\") tokens.\n}\n\n/**\n * Tests an object to determine whether it implements TokenCredential.\n *\n * @param credential - The assumed TokenCredential to be tested.\n */\nexport function isTokenCredential(credential: unknown): credential is TokenCredential {\n // Check for an object with a 'getToken' function and possibly with\n // a 'signRequest' function. We do this check to make sure that\n // a ServiceClientCredentials implementor (like TokenClientCredentials\n // in ms-rest-nodeauth) doesn't get mistaken for a TokenCredential if\n // it doesn't actually implement TokenCredential also.\n const castCredential = credential as {\n getToken: unknown;\n signRequest: unknown;\n };\n return (\n castCredential &&\n typeof castCredential.getToken === \"function\" &&\n (castCredential.signRequest === undefined || castCredential.getToken.length > 0)\n );\n}\n"]}
@@ -1,8 +0,0 @@
1
- import type { KeyCredential } from "../auth/keyCredential.js";
2
- import type { PipelinePolicy } from "../pipeline.js";
3
- /**
4
- * The programmatic identifier of the bearerTokenAuthenticationPolicy.
5
- */
6
- export declare const keyCredentialAuthenticationPolicyName = "keyCredentialAuthenticationPolicy";
7
- export declare function keyCredentialAuthenticationPolicy(credential: KeyCredential, apiKeyHeaderName: string): PipelinePolicy;
8
- //# sourceMappingURL=keyCredentialAuthenticationPolicy.d.ts.map
@@ -1,16 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /**
4
- * The programmatic identifier of the bearerTokenAuthenticationPolicy.
5
- */
6
- export const keyCredentialAuthenticationPolicyName = "keyCredentialAuthenticationPolicy";
7
- export function keyCredentialAuthenticationPolicy(credential, apiKeyHeaderName) {
8
- return {
9
- name: keyCredentialAuthenticationPolicyName,
10
- async sendRequest(request, next) {
11
- request.headers.set(apiKeyHeaderName, credential.key);
12
- return next(request);
13
- },
14
- };
15
- }
16
- //# sourceMappingURL=keyCredentialAuthenticationPolicy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keyCredentialAuthenticationPolicy.js","sourceRoot":"","sources":["../../../src/client/keyCredentialAuthenticationPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC;;GAEG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,mCAAmC,CAAC;AAEzF,MAAM,UAAU,iCAAiC,CAC/C,UAAyB,EACzB,gBAAwB;IAExB,OAAO;QACL,IAAI,EAAE,qCAAqC;QAC3C,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;YACtD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeyCredential } from \"../auth/keyCredential.js\";\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\n\n/**\n * The programmatic identifier of the bearerTokenAuthenticationPolicy.\n */\nexport const keyCredentialAuthenticationPolicyName = \"keyCredentialAuthenticationPolicy\";\n\nexport function keyCredentialAuthenticationPolicy(\n credential: KeyCredential,\n apiKeyHeaderName: string,\n): PipelinePolicy {\n return {\n name: keyCredentialAuthenticationPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.headers.set(apiKeyHeaderName, credential.key);\n return next(request);\n },\n };\n}\n"]}
@@ -1,99 +0,0 @@
1
- import type { AccessToken, GetTokenOptions, TokenCredential } from "../auth/tokenCredential.js";
2
- import type { TypeSpecRuntimeLogger } from "../logger/logger.js";
3
- import type { PipelineRequest, PipelineResponse } from "../interfaces.js";
4
- import type { PipelinePolicy } from "../pipeline.js";
5
- /**
6
- * The programmatic identifier of the bearerTokenAuthenticationPolicy.
7
- */
8
- export declare const bearerTokenAuthenticationPolicyName = "bearerTokenAuthenticationPolicy";
9
- /**
10
- * Options sent to the authorizeRequest callback
11
- */
12
- export interface AuthorizeRequestOptions {
13
- /**
14
- * The scopes for which the bearer token applies.
15
- */
16
- scopes: string[];
17
- /**
18
- * Function that retrieves either a cached access token or a new access token.
19
- */
20
- getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
21
- /**
22
- * Request that the policy is trying to fulfill.
23
- */
24
- request: PipelineRequest;
25
- /**
26
- * A logger, if one was sent through the HTTP pipeline.
27
- */
28
- logger?: TypeSpecRuntimeLogger;
29
- }
30
- /**
31
- * Options sent to the authorizeRequestOnChallenge callback
32
- */
33
- export interface AuthorizeRequestOnChallengeOptions {
34
- /**
35
- * The scopes for which the bearer token applies.
36
- */
37
- scopes: string[];
38
- /**
39
- * Function that retrieves either a cached access token or a new access token.
40
- */
41
- getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
42
- /**
43
- * Request that the policy is trying to fulfill.
44
- */
45
- request: PipelineRequest;
46
- /**
47
- * Response containing the challenge.
48
- */
49
- response: PipelineResponse;
50
- /**
51
- * A logger, if one was sent through the HTTP pipeline.
52
- */
53
- logger?: TypeSpecRuntimeLogger;
54
- }
55
- /**
56
- * Options to override the processing of [Continuous Access Evaluation](https://learn.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.
57
- */
58
- export interface ChallengeCallbacks {
59
- /**
60
- * Allows for the authorization of the main request of this policy before it's sent.
61
- */
62
- authorizeRequest?(options: AuthorizeRequestOptions): Promise<void>;
63
- /**
64
- * Allows to handle authentication challenges and to re-authorize the request.
65
- * The response containing the challenge is `options.response`.
66
- * If this method returns true, the underlying request will be sent once again.
67
- * The request may be modified before being sent.
68
- */
69
- authorizeRequestOnChallenge?(options: AuthorizeRequestOnChallengeOptions): Promise<boolean>;
70
- }
71
- /**
72
- * Options to configure the bearerTokenAuthenticationPolicy
73
- */
74
- export interface BearerTokenAuthenticationPolicyOptions {
75
- /**
76
- * The TokenCredential implementation that can supply the bearer token.
77
- */
78
- credential?: TokenCredential;
79
- /**
80
- * The scopes for which the bearer token applies.
81
- */
82
- scopes: string | string[];
83
- /**
84
- * Allows for the processing of [Continuous Access Evaluation](https://learn.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.
85
- * If provided, it must contain at least the `authorizeRequestOnChallenge` method.
86
- * If provided, after a request is sent, if it has a challenge, it can be processed to re-send the original request with the relevant challenge information.
87
- */
88
- challengeCallbacks?: ChallengeCallbacks;
89
- /**
90
- * A logger can be sent for debugging purposes.
91
- */
92
- logger?: TypeSpecRuntimeLogger;
93
- }
94
- /**
95
- * A policy that can request a token from a TokenCredential implementation and
96
- * then apply it to the Authorization header of a request as a Bearer token.
97
- */
98
- export declare function bearerTokenAuthenticationPolicy(options: BearerTokenAuthenticationPolicyOptions): PipelinePolicy;
99
- //# sourceMappingURL=bearerTokenAuthenticationPolicy.d.ts.map
@@ -1,107 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { createTokenCycler } from "../util/tokenCycler.js";
4
- import { logger as coreLogger } from "../log.js";
5
- /**
6
- * The programmatic identifier of the bearerTokenAuthenticationPolicy.
7
- */
8
- export const bearerTokenAuthenticationPolicyName = "bearerTokenAuthenticationPolicy";
9
- /**
10
- * Default authorize request handler
11
- */
12
- async function defaultAuthorizeRequest(options) {
13
- const { scopes, getAccessToken, request } = options;
14
- const getTokenOptions = {
15
- abortSignal: request.abortSignal,
16
- };
17
- const accessToken = await getAccessToken(scopes, getTokenOptions);
18
- if (accessToken) {
19
- options.request.headers.set("Authorization", `Bearer ${accessToken.token}`);
20
- }
21
- }
22
- /**
23
- * We will retrieve the challenge only if the response status code was 401,
24
- * and if the response contained the header "WWW-Authenticate" with a non-empty value.
25
- */
26
- function getChallenge(response) {
27
- const challenge = response.headers.get("WWW-Authenticate");
28
- if (response.status === 401 && challenge) {
29
- return challenge;
30
- }
31
- return;
32
- }
33
- /**
34
- * A policy that can request a token from a TokenCredential implementation and
35
- * then apply it to the Authorization header of a request as a Bearer token.
36
- */
37
- export function bearerTokenAuthenticationPolicy(options) {
38
- var _a;
39
- const { credential, scopes, challengeCallbacks } = options;
40
- const logger = options.logger || coreLogger;
41
- const callbacks = Object.assign({ authorizeRequest: (_a = challengeCallbacks === null || challengeCallbacks === void 0 ? void 0 : challengeCallbacks.authorizeRequest) !== null && _a !== void 0 ? _a : defaultAuthorizeRequest, authorizeRequestOnChallenge: challengeCallbacks === null || challengeCallbacks === void 0 ? void 0 : challengeCallbacks.authorizeRequestOnChallenge }, challengeCallbacks);
42
- // This function encapsulates the entire process of reliably retrieving the token
43
- // The options are left out of the public API until there's demand to configure this.
44
- // Remember to extend `BearerTokenAuthenticationPolicyOptions` with `TokenCyclerOptions`
45
- // in order to pass through the `options` object.
46
- const getAccessToken = credential
47
- ? createTokenCycler(credential /* , options */)
48
- : () => Promise.resolve(null);
49
- return {
50
- name: bearerTokenAuthenticationPolicyName,
51
- /**
52
- * If there's no challenge parameter:
53
- * - It will try to retrieve the token using the cache, or the credential's getToken.
54
- * - Then it will try the next policy with or without the retrieved token.
55
- *
56
- * It uses the challenge parameters to:
57
- * - Skip a first attempt to get the token from the credential if there's no cached token,
58
- * since it expects the token to be retrievable only after the challenge.
59
- * - Prepare the outgoing request if the `prepareRequest` method has been provided.
60
- * - Send an initial request to receive the challenge if it fails.
61
- * - Process a challenge if the response contains it.
62
- * - Retrieve a token with the challenge information, then re-send the request.
63
- */
64
- async sendRequest(request, next) {
65
- if (!request.url.toLowerCase().startsWith("https://")) {
66
- throw new Error("Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.");
67
- }
68
- await callbacks.authorizeRequest({
69
- scopes: Array.isArray(scopes) ? scopes : [scopes],
70
- request,
71
- getAccessToken,
72
- logger,
73
- });
74
- let response;
75
- let error;
76
- try {
77
- response = await next(request);
78
- }
79
- catch (err) {
80
- error = err;
81
- response = err.response;
82
- }
83
- if (callbacks.authorizeRequestOnChallenge &&
84
- (response === null || response === void 0 ? void 0 : response.status) === 401 &&
85
- getChallenge(response)) {
86
- // processes challenge
87
- const shouldSendRequest = await callbacks.authorizeRequestOnChallenge({
88
- scopes: Array.isArray(scopes) ? scopes : [scopes],
89
- request,
90
- response,
91
- getAccessToken,
92
- logger,
93
- });
94
- if (shouldSendRequest) {
95
- return next(request);
96
- }
97
- }
98
- if (error) {
99
- throw error;
100
- }
101
- else {
102
- return response;
103
- }
104
- },
105
- };
106
- }
107
- //# sourceMappingURL=bearerTokenAuthenticationPolicy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bearerTokenAuthenticationPolicy.js","sourceRoot":"","sources":["../../../src/policies/bearerTokenAuthenticationPolicy.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"../auth/tokenCredential.js\";\nimport type { TypeSpecRuntimeLogger } from \"../logger/logger.js\";\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { createTokenCycler } from \"../util/tokenCycler.js\";\nimport { logger as coreLogger } from \"../log.js\";\n\n/**\n * The programmatic identifier of the bearerTokenAuthenticationPolicy.\n */\nexport const bearerTokenAuthenticationPolicyName = \"bearerTokenAuthenticationPolicy\";\n\n/**\n * Options sent to the authorizeRequest callback\n */\nexport interface AuthorizeRequestOptions {\n /**\n * The scopes for which the bearer token applies.\n */\n scopes: string[];\n /**\n * Function that retrieves either a cached access token or a new access token.\n */\n getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;\n /**\n * Request that the policy is trying to fulfill.\n */\n request: PipelineRequest;\n /**\n * A logger, if one was sent through the HTTP pipeline.\n */\n logger?: TypeSpecRuntimeLogger;\n}\n\n/**\n * Options sent to the authorizeRequestOnChallenge callback\n */\nexport interface AuthorizeRequestOnChallengeOptions {\n /**\n * The scopes for which the bearer token applies.\n */\n scopes: string[];\n /**\n * Function that retrieves either a cached access token or a new access token.\n */\n getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;\n /**\n * Request that the policy is trying to fulfill.\n */\n request: PipelineRequest;\n /**\n * Response containing the challenge.\n */\n response: PipelineResponse;\n /**\n * A logger, if one was sent through the HTTP pipeline.\n */\n logger?: TypeSpecRuntimeLogger;\n}\n\n/**\n * Options to override the processing of [Continuous Access Evaluation](https://learn.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.\n */\nexport interface ChallengeCallbacks {\n /**\n * Allows for the authorization of the main request of this policy before it's sent.\n */\n authorizeRequest?(options: AuthorizeRequestOptions): Promise<void>;\n /**\n * Allows to handle authentication challenges and to re-authorize the request.\n * The response containing the challenge is `options.response`.\n * If this method returns true, the underlying request will be sent once again.\n * The request may be modified before being sent.\n */\n authorizeRequestOnChallenge?(options: AuthorizeRequestOnChallengeOptions): Promise<boolean>;\n}\n\n/**\n * Options to configure the bearerTokenAuthenticationPolicy\n */\nexport interface BearerTokenAuthenticationPolicyOptions {\n /**\n * The TokenCredential implementation that can supply the bearer token.\n */\n credential?: TokenCredential;\n /**\n * The scopes for which the bearer token applies.\n */\n scopes: string | string[];\n /**\n * Allows for the processing of [Continuous Access Evaluation](https://learn.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.\n * If provided, it must contain at least the `authorizeRequestOnChallenge` method.\n * If provided, after a request is sent, if it has a challenge, it can be processed to re-send the original request with the relevant challenge information.\n */\n challengeCallbacks?: ChallengeCallbacks;\n /**\n * A logger can be sent for debugging purposes.\n */\n logger?: TypeSpecRuntimeLogger;\n}\n\n/**\n * Default authorize request handler\n */\nasync function defaultAuthorizeRequest(options: AuthorizeRequestOptions): Promise<void> {\n const { scopes, getAccessToken, request } = options;\n const getTokenOptions: GetTokenOptions = {\n abortSignal: request.abortSignal,\n };\n const accessToken = await getAccessToken(scopes, getTokenOptions);\n\n if (accessToken) {\n options.request.headers.set(\"Authorization\", `Bearer ${accessToken.token}`);\n }\n}\n\n/**\n * We will retrieve the challenge only if the response status code was 401,\n * and if the response contained the header \"WWW-Authenticate\" with a non-empty value.\n */\nfunction getChallenge(response: PipelineResponse): string | undefined {\n const challenge = response.headers.get(\"WWW-Authenticate\");\n if (response.status === 401 && challenge) {\n return challenge;\n }\n return;\n}\n\n/**\n * A policy that can request a token from a TokenCredential implementation and\n * then apply it to the Authorization header of a request as a Bearer token.\n */\nexport function bearerTokenAuthenticationPolicy(\n options: BearerTokenAuthenticationPolicyOptions,\n): PipelinePolicy {\n const { credential, scopes, challengeCallbacks } = options;\n const logger = options.logger || coreLogger;\n const callbacks = {\n authorizeRequest: challengeCallbacks?.authorizeRequest ?? defaultAuthorizeRequest,\n authorizeRequestOnChallenge: challengeCallbacks?.authorizeRequestOnChallenge,\n // keep all other properties\n ...challengeCallbacks,\n };\n\n // This function encapsulates the entire process of reliably retrieving the token\n // The options are left out of the public API until there's demand to configure this.\n // Remember to extend `BearerTokenAuthenticationPolicyOptions` with `TokenCyclerOptions`\n // in order to pass through the `options` object.\n const getAccessToken = credential\n ? createTokenCycler(credential /* , options */)\n : () => Promise.resolve(null);\n\n return {\n name: bearerTokenAuthenticationPolicyName,\n /**\n * If there's no challenge parameter:\n * - It will try to retrieve the token using the cache, or the credential's getToken.\n * - Then it will try the next policy with or without the retrieved token.\n *\n * It uses the challenge parameters to:\n * - Skip a first attempt to get the token from the credential if there's no cached token,\n * since it expects the token to be retrievable only after the challenge.\n * - Prepare the outgoing request if the `prepareRequest` method has been provided.\n * - Send an initial request to receive the challenge if it fails.\n * - Process a challenge if the response contains it.\n * - Retrieve a token with the challenge information, then re-send the request.\n */\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (!request.url.toLowerCase().startsWith(\"https://\")) {\n throw new Error(\n \"Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.\",\n );\n }\n\n await callbacks.authorizeRequest({\n scopes: Array.isArray(scopes) ? scopes : [scopes],\n request,\n getAccessToken,\n logger,\n });\n\n let response: PipelineResponse;\n let error: Error | undefined;\n try {\n response = await next(request);\n } catch (err: any) {\n error = err;\n response = err.response;\n }\n\n if (\n callbacks.authorizeRequestOnChallenge &&\n response?.status === 401 &&\n getChallenge(response)\n ) {\n // processes challenge\n const shouldSendRequest = await callbacks.authorizeRequestOnChallenge({\n scopes: Array.isArray(scopes) ? scopes : [scopes],\n request,\n response,\n getAccessToken,\n logger,\n });\n\n if (shouldSendRequest) {\n return next(request);\n }\n }\n\n if (error) {\n throw error;\n } else {\n return response;\n }\n },\n };\n}\n"]}
@@ -1,45 +0,0 @@
1
- import type { AccessToken, GetTokenOptions, TokenCredential } from "../auth/tokenCredential.js";
2
- /**
3
- * A function that gets a promise of an access token and allows providing
4
- * options.
5
- *
6
- * @param options - the options to pass to the underlying token provider
7
- */
8
- export type AccessTokenGetter = (scopes: string | string[], options: GetTokenOptions) => Promise<AccessToken>;
9
- export interface TokenCyclerOptions {
10
- /**
11
- * The window of time before token expiration during which the token will be
12
- * considered unusable due to risk of the token expiring before sending the
13
- * request.
14
- *
15
- * This will only become meaningful if the refresh fails for over
16
- * (refreshWindow - forcedRefreshWindow) milliseconds.
17
- */
18
- forcedRefreshWindowInMs: number;
19
- /**
20
- * Interval in milliseconds to retry failed token refreshes.
21
- */
22
- retryIntervalInMs: number;
23
- /**
24
- * The window of time before token expiration during which
25
- * we will attempt to refresh the token.
26
- */
27
- refreshWindowInMs: number;
28
- }
29
- export declare const DEFAULT_CYCLER_OPTIONS: TokenCyclerOptions;
30
- /**
31
- * Creates a token cycler from a credential, scopes, and optional settings.
32
- *
33
- * A token cycler represents a way to reliably retrieve a valid access token
34
- * from a TokenCredential. It will handle initializing the token, refreshing it
35
- * when it nears expiration, and synchronizes refresh attempts to avoid
36
- * concurrency hazards.
37
- *
38
- * @param credential - the underlying TokenCredential that provides the access
39
- * token
40
- * @param tokenCyclerOptions - optionally override default settings for the cycler
41
- *
42
- * @returns - a function that reliably produces a valid access token
43
- */
44
- export declare function createTokenCycler(credential: TokenCredential, tokenCyclerOptions?: Partial<TokenCyclerOptions>): AccessTokenGetter;
45
- //# sourceMappingURL=tokenCycler.d.ts.map