@smithy/experimental-identity-and-auth 0.0.8 → 0.0.9

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 (29) hide show
  1. package/dist-cjs/IdentityProviderConfig.js +3 -1
  2. package/dist-cjs/createEndpointRuleSetHttpAuthSchemeProvider.js +41 -0
  3. package/dist-cjs/index.js +3 -0
  4. package/dist-cjs/memoizeIdentityProvider.js +58 -0
  5. package/dist-cjs/middleware-http-auth-scheme/getHttpAuthSchemePlugin.js +19 -0
  6. package/dist-cjs/middleware-http-auth-scheme/httpAuthSchemeMiddleware.js +42 -0
  7. package/dist-cjs/middleware-http-auth-scheme/index.js +5 -0
  8. package/dist-es/IdentityProviderConfig.js +3 -1
  9. package/dist-es/createEndpointRuleSetHttpAuthSchemeProvider.js +36 -0
  10. package/dist-es/index.js +3 -0
  11. package/dist-es/memoizeIdentityProvider.js +52 -0
  12. package/dist-es/middleware-http-auth-scheme/getHttpAuthSchemePlugin.js +15 -0
  13. package/dist-es/middleware-http-auth-scheme/httpAuthSchemeMiddleware.js +38 -0
  14. package/dist-es/middleware-http-auth-scheme/index.js +2 -0
  15. package/dist-types/IdentityProviderConfig.d.ts +2 -2
  16. package/dist-types/createEndpointRuleSetHttpAuthSchemeProvider.d.ts +25 -0
  17. package/dist-types/index.d.ts +3 -0
  18. package/dist-types/memoizeIdentityProvider.d.ts +26 -0
  19. package/dist-types/middleware-http-auth-scheme/getHttpAuthSchemePlugin.d.ts +10 -0
  20. package/dist-types/middleware-http-auth-scheme/httpAuthSchemeMiddleware.d.ts +17 -0
  21. package/dist-types/middleware-http-auth-scheme/index.d.ts +2 -0
  22. package/dist-types/ts3.4/IdentityProviderConfig.d.ts +2 -2
  23. package/dist-types/ts3.4/createEndpointRuleSetHttpAuthSchemeProvider.d.ts +25 -0
  24. package/dist-types/ts3.4/index.d.ts +3 -0
  25. package/dist-types/ts3.4/memoizeIdentityProvider.d.ts +26 -0
  26. package/dist-types/ts3.4/middleware-http-auth-scheme/getHttpAuthSchemePlugin.d.ts +10 -0
  27. package/dist-types/ts3.4/middleware-http-auth-scheme/httpAuthSchemeMiddleware.d.ts +17 -0
  28. package/dist-types/ts3.4/middleware-http-auth-scheme/index.d.ts +2 -0
  29. package/package.json +2 -1
@@ -5,7 +5,9 @@ class DefaultIdentityProviderConfig {
5
5
  constructor(config) {
6
6
  this.authSchemes = new Map();
7
7
  for (const [key, value] of Object.entries(config)) {
8
- this.authSchemes.set(key, value);
8
+ if (value !== undefined) {
9
+ this.authSchemes.set(key, value);
10
+ }
9
11
  }
10
12
  }
11
13
  getIdentityProvider(schemeId) {
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createEndpointRuleSetHttpAuthSchemeProvider = void 0;
4
+ const createEndpointRuleSetHttpAuthSchemeProvider = (defaultEndpointResolver, defaultHttpAuthSchemeResolver) => {
5
+ const endpointRuleSetHttpAuthSchemeProvider = (authParameters) => {
6
+ var _a;
7
+ const endpoint = defaultEndpointResolver(authParameters);
8
+ const authSchemes = (_a = endpoint.properties) === null || _a === void 0 ? void 0 : _a.authSchemes;
9
+ if (!authSchemes) {
10
+ return defaultHttpAuthSchemeResolver(authParameters);
11
+ }
12
+ const options = [];
13
+ for (const scheme of authSchemes) {
14
+ const { name: resolvedName, properties = {}, ...rest } = scheme;
15
+ const name = resolvedName.toLowerCase();
16
+ if (resolvedName !== name) {
17
+ console.warn(`HttpAuthScheme has been normalized with lowercasing: \`${resolvedName}\` to \`${name}\``);
18
+ }
19
+ let schemeId;
20
+ if (name === "sigv4") {
21
+ schemeId = "aws.auth#sigv4";
22
+ }
23
+ else if (name === "sigv4a") {
24
+ schemeId = "aws.auth#sigv4a";
25
+ }
26
+ else {
27
+ throw new Error(`Unknown HttpAuthScheme found in \`@smithy.rules#endpointRuleSet\`: \`${name}\``);
28
+ }
29
+ options.push({
30
+ schemeId,
31
+ signingProperties: {
32
+ ...rest,
33
+ ...properties,
34
+ },
35
+ });
36
+ }
37
+ return options;
38
+ };
39
+ return endpointRuleSetHttpAuthSchemeProvider;
40
+ };
41
+ exports.createEndpointRuleSetHttpAuthSchemeProvider = createEndpointRuleSetHttpAuthSchemeProvider;
package/dist-cjs/index.js CHANGED
@@ -7,8 +7,11 @@ tslib_1.__exportStar(require("./HttpSigner"), exports);
7
7
  tslib_1.__exportStar(require("./IdentityProviderConfig"), exports);
8
8
  tslib_1.__exportStar(require("./SigV4Signer"), exports);
9
9
  tslib_1.__exportStar(require("./apiKeyIdentity"), exports);
10
+ tslib_1.__exportStar(require("./createEndpointRuleSetHttpAuthSchemeProvider"), exports);
10
11
  tslib_1.__exportStar(require("./httpApiKeyAuth"), exports);
11
12
  tslib_1.__exportStar(require("./httpBearerAuth"), exports);
13
+ tslib_1.__exportStar(require("./memoizeIdentityProvider"), exports);
14
+ tslib_1.__exportStar(require("./middleware-http-auth-scheme"), exports);
12
15
  tslib_1.__exportStar(require("./middleware-http-signing"), exports);
13
16
  tslib_1.__exportStar(require("./noAuth"), exports);
14
17
  tslib_1.__exportStar(require("./tokenIdentity"), exports);
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.memoizeIdentityProvider = exports.doesIdentityRequireRefresh = exports.isIdentityExpired = exports.EXPIRATION_MS = void 0;
4
+ exports.EXPIRATION_MS = 300000;
5
+ const isIdentityExpired = (identity) => (0, exports.doesIdentityRequireRefresh)(identity) && identity.expiration.getTime() - Date.now() < exports.EXPIRATION_MS;
6
+ exports.isIdentityExpired = isIdentityExpired;
7
+ const doesIdentityRequireRefresh = (identity) => identity.expiration !== undefined;
8
+ exports.doesIdentityRequireRefresh = doesIdentityRequireRefresh;
9
+ const memoizeIdentityProvider = (provider, isExpired, requiresRefresh) => {
10
+ if (provider === undefined) {
11
+ return undefined;
12
+ }
13
+ const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
14
+ let resolved;
15
+ let pending;
16
+ let hasResult;
17
+ let isConstant = false;
18
+ const coalesceProvider = async (options) => {
19
+ if (!pending) {
20
+ pending = normalizedProvider(options);
21
+ }
22
+ try {
23
+ resolved = await pending;
24
+ hasResult = true;
25
+ isConstant = false;
26
+ }
27
+ finally {
28
+ pending = undefined;
29
+ }
30
+ return resolved;
31
+ };
32
+ if (isExpired === undefined) {
33
+ return async (options) => {
34
+ if (!hasResult || (options === null || options === void 0 ? void 0 : options.forceRefresh)) {
35
+ resolved = await coalesceProvider(options);
36
+ }
37
+ return resolved;
38
+ };
39
+ }
40
+ return async (options) => {
41
+ if (!hasResult || (options === null || options === void 0 ? void 0 : options.forceRefresh)) {
42
+ resolved = await coalesceProvider(options);
43
+ }
44
+ if (isConstant) {
45
+ return resolved;
46
+ }
47
+ if (!requiresRefresh(resolved)) {
48
+ isConstant = true;
49
+ return resolved;
50
+ }
51
+ if (isExpired(resolved)) {
52
+ await coalesceProvider(options);
53
+ return resolved;
54
+ }
55
+ return resolved;
56
+ };
57
+ };
58
+ exports.memoizeIdentityProvider = memoizeIdentityProvider;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHttpAuthSchemePlugin = exports.httpAuthSchemeMiddlewareOptions = void 0;
4
+ const middleware_endpoint_1 = require("@smithy/middleware-endpoint");
5
+ const httpAuthSchemeMiddleware_1 = require("./httpAuthSchemeMiddleware");
6
+ exports.httpAuthSchemeMiddlewareOptions = {
7
+ step: "serialize",
8
+ tags: ["HTTP_AUTH_SCHEME"],
9
+ name: "httpAuthSchemeMiddleware",
10
+ override: true,
11
+ relation: "before",
12
+ toMiddleware: middleware_endpoint_1.endpointMiddlewareOptions.name,
13
+ };
14
+ const getHttpAuthSchemePlugin = (config) => ({
15
+ applyToStack: (clientStack) => {
16
+ clientStack.addRelativeTo((0, httpAuthSchemeMiddleware_1.httpAuthSchemeMiddleware)(config), exports.httpAuthSchemeMiddlewareOptions);
17
+ },
18
+ });
19
+ exports.getHttpAuthSchemePlugin = getHttpAuthSchemePlugin;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.httpAuthSchemeMiddleware = void 0;
4
+ const types_1 = require("@smithy/types");
5
+ const util_middleware_1 = require("@smithy/util-middleware");
6
+ function convertHttpAuthSchemesToMap(httpAuthSchemes) {
7
+ const map = new Map();
8
+ for (const scheme of httpAuthSchemes) {
9
+ map.set(scheme.schemeId, scheme);
10
+ }
11
+ return map;
12
+ }
13
+ const httpAuthSchemeMiddleware = (config) => (next, context) => async (args) => {
14
+ const options = config.httpAuthSchemeProvider(await config.httpAuthSchemeParametersProvider(config, context, args.input));
15
+ const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes);
16
+ const smithyContext = (0, util_middleware_1.getSmithyContext)(context);
17
+ const failureReasons = [];
18
+ for (const option of options) {
19
+ const scheme = authSchemes.get(option.schemeId);
20
+ if (!scheme) {
21
+ failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enable for this service.`);
22
+ continue;
23
+ }
24
+ const identityProvider = scheme.identityProvider(config.identityProviderConfig);
25
+ if (!identityProvider) {
26
+ failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`);
27
+ continue;
28
+ }
29
+ const identity = await identityProvider(option.identityProperties || {});
30
+ smithyContext.selectedHttpAuthScheme = {
31
+ httpAuthOption: option,
32
+ identity,
33
+ signer: scheme.signer,
34
+ };
35
+ break;
36
+ }
37
+ if (!smithyContext.selectedHttpAuthScheme) {
38
+ throw new Error(failureReasons.join("\n"));
39
+ }
40
+ return next(args);
41
+ };
42
+ exports.httpAuthSchemeMiddleware = httpAuthSchemeMiddleware;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./httpAuthSchemeMiddleware"), exports);
5
+ tslib_1.__exportStar(require("./getHttpAuthSchemePlugin"), exports);
@@ -2,7 +2,9 @@ export class DefaultIdentityProviderConfig {
2
2
  constructor(config) {
3
3
  this.authSchemes = new Map();
4
4
  for (const [key, value] of Object.entries(config)) {
5
- this.authSchemes.set(key, value);
5
+ if (value !== undefined) {
6
+ this.authSchemes.set(key, value);
7
+ }
6
8
  }
7
9
  }
8
10
  getIdentityProvider(schemeId) {
@@ -0,0 +1,36 @@
1
+ export const createEndpointRuleSetHttpAuthSchemeProvider = (defaultEndpointResolver, defaultHttpAuthSchemeResolver) => {
2
+ const endpointRuleSetHttpAuthSchemeProvider = (authParameters) => {
3
+ const endpoint = defaultEndpointResolver(authParameters);
4
+ const authSchemes = endpoint.properties?.authSchemes;
5
+ if (!authSchemes) {
6
+ return defaultHttpAuthSchemeResolver(authParameters);
7
+ }
8
+ const options = [];
9
+ for (const scheme of authSchemes) {
10
+ const { name: resolvedName, properties = {}, ...rest } = scheme;
11
+ const name = resolvedName.toLowerCase();
12
+ if (resolvedName !== name) {
13
+ console.warn(`HttpAuthScheme has been normalized with lowercasing: \`${resolvedName}\` to \`${name}\``);
14
+ }
15
+ let schemeId;
16
+ if (name === "sigv4") {
17
+ schemeId = "aws.auth#sigv4";
18
+ }
19
+ else if (name === "sigv4a") {
20
+ schemeId = "aws.auth#sigv4a";
21
+ }
22
+ else {
23
+ throw new Error(`Unknown HttpAuthScheme found in \`@smithy.rules#endpointRuleSet\`: \`${name}\``);
24
+ }
25
+ options.push({
26
+ schemeId,
27
+ signingProperties: {
28
+ ...rest,
29
+ ...properties,
30
+ },
31
+ });
32
+ }
33
+ return options;
34
+ };
35
+ return endpointRuleSetHttpAuthSchemeProvider;
36
+ };
package/dist-es/index.js CHANGED
@@ -4,8 +4,11 @@ export * from "./HttpSigner";
4
4
  export * from "./IdentityProviderConfig";
5
5
  export * from "./SigV4Signer";
6
6
  export * from "./apiKeyIdentity";
7
+ export * from "./createEndpointRuleSetHttpAuthSchemeProvider";
7
8
  export * from "./httpApiKeyAuth";
8
9
  export * from "./httpBearerAuth";
10
+ export * from "./memoizeIdentityProvider";
11
+ export * from "./middleware-http-auth-scheme";
9
12
  export * from "./middleware-http-signing";
10
13
  export * from "./noAuth";
11
14
  export * from "./tokenIdentity";
@@ -0,0 +1,52 @@
1
+ export const EXPIRATION_MS = 300000;
2
+ export const isIdentityExpired = (identity) => doesIdentityRequireRefresh(identity) && identity.expiration.getTime() - Date.now() < EXPIRATION_MS;
3
+ export const doesIdentityRequireRefresh = (identity) => identity.expiration !== undefined;
4
+ export const memoizeIdentityProvider = (provider, isExpired, requiresRefresh) => {
5
+ if (provider === undefined) {
6
+ return undefined;
7
+ }
8
+ const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
9
+ let resolved;
10
+ let pending;
11
+ let hasResult;
12
+ let isConstant = false;
13
+ const coalesceProvider = async (options) => {
14
+ if (!pending) {
15
+ pending = normalizedProvider(options);
16
+ }
17
+ try {
18
+ resolved = await pending;
19
+ hasResult = true;
20
+ isConstant = false;
21
+ }
22
+ finally {
23
+ pending = undefined;
24
+ }
25
+ return resolved;
26
+ };
27
+ if (isExpired === undefined) {
28
+ return async (options) => {
29
+ if (!hasResult || options?.forceRefresh) {
30
+ resolved = await coalesceProvider(options);
31
+ }
32
+ return resolved;
33
+ };
34
+ }
35
+ return async (options) => {
36
+ if (!hasResult || options?.forceRefresh) {
37
+ resolved = await coalesceProvider(options);
38
+ }
39
+ if (isConstant) {
40
+ return resolved;
41
+ }
42
+ if (!requiresRefresh(resolved)) {
43
+ isConstant = true;
44
+ return resolved;
45
+ }
46
+ if (isExpired(resolved)) {
47
+ await coalesceProvider(options);
48
+ return resolved;
49
+ }
50
+ return resolved;
51
+ };
52
+ };
@@ -0,0 +1,15 @@
1
+ import { endpointMiddlewareOptions } from "@smithy/middleware-endpoint";
2
+ import { httpAuthSchemeMiddleware } from "./httpAuthSchemeMiddleware";
3
+ export const httpAuthSchemeMiddlewareOptions = {
4
+ step: "serialize",
5
+ tags: ["HTTP_AUTH_SCHEME"],
6
+ name: "httpAuthSchemeMiddleware",
7
+ override: true,
8
+ relation: "before",
9
+ toMiddleware: endpointMiddlewareOptions.name,
10
+ };
11
+ export const getHttpAuthSchemePlugin = (config) => ({
12
+ applyToStack: (clientStack) => {
13
+ clientStack.addRelativeTo(httpAuthSchemeMiddleware(config), httpAuthSchemeMiddlewareOptions);
14
+ },
15
+ });
@@ -0,0 +1,38 @@
1
+ import { SMITHY_CONTEXT_KEY, } from "@smithy/types";
2
+ import { getSmithyContext } from "@smithy/util-middleware";
3
+ function convertHttpAuthSchemesToMap(httpAuthSchemes) {
4
+ const map = new Map();
5
+ for (const scheme of httpAuthSchemes) {
6
+ map.set(scheme.schemeId, scheme);
7
+ }
8
+ return map;
9
+ }
10
+ export const httpAuthSchemeMiddleware = (config) => (next, context) => async (args) => {
11
+ const options = config.httpAuthSchemeProvider(await config.httpAuthSchemeParametersProvider(config, context, args.input));
12
+ const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes);
13
+ const smithyContext = getSmithyContext(context);
14
+ const failureReasons = [];
15
+ for (const option of options) {
16
+ const scheme = authSchemes.get(option.schemeId);
17
+ if (!scheme) {
18
+ failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enable for this service.`);
19
+ continue;
20
+ }
21
+ const identityProvider = scheme.identityProvider(config.identityProviderConfig);
22
+ if (!identityProvider) {
23
+ failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`);
24
+ continue;
25
+ }
26
+ const identity = await identityProvider(option.identityProperties || {});
27
+ smithyContext.selectedHttpAuthScheme = {
28
+ httpAuthOption: option,
29
+ identity,
30
+ signer: scheme.signer,
31
+ };
32
+ break;
33
+ }
34
+ if (!smithyContext.selectedHttpAuthScheme) {
35
+ throw new Error(failureReasons.join("\n"));
36
+ }
37
+ return next(args);
38
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./httpAuthSchemeMiddleware";
2
+ export * from "./getHttpAuthSchemePlugin";
@@ -13,7 +13,7 @@ export interface IdentityProviderConfig {
13
13
  getIdentityProvider(schemeId: HttpAuthSchemeId): IdentityProvider<Identity> | undefined;
14
14
  }
15
15
  /**
16
- * Default implementation of IddentityProviderConfig
16
+ * Default implementation of IdentityProviderConfig
17
17
  * @internal
18
18
  */
19
19
  export declare class DefaultIdentityProviderConfig implements IdentityProviderConfig {
@@ -23,6 +23,6 @@ export declare class DefaultIdentityProviderConfig implements IdentityProviderCo
23
23
  *
24
24
  * @param config scheme IDs and identity providers to configure
25
25
  */
26
- constructor(config: Record<HttpAuthSchemeId, IdentityProvider<Identity>>);
26
+ constructor(config: Record<HttpAuthSchemeId, IdentityProvider<Identity> | undefined>);
27
27
  getIdentityProvider(schemeId: HttpAuthSchemeId): IdentityProvider<Identity> | undefined;
28
28
  }
@@ -0,0 +1,25 @@
1
+ import { EndpointParameters, EndpointV2, Logger } from "@smithy/types";
2
+ import { HttpAuthSchemeParameters, HttpAuthSchemeProvider } from "./HttpAuthSchemeProvider";
3
+ /**
4
+ * @internal
5
+ */
6
+ export interface EndpointRuleSetHttpAuthSchemeProvider<EndpointParametersT extends EndpointParameters = EndpointParameters, HttpAuthSchemeParametersT extends HttpAuthSchemeParameters = HttpAuthSchemeParameters> extends HttpAuthSchemeProvider<EndpointParametersT & HttpAuthSchemeParametersT> {
7
+ }
8
+ /**
9
+ * @internal
10
+ */
11
+ export interface DefaultEndpointResolver<EndpointParametersT extends EndpointParameters = EndpointParameters> {
12
+ (params: EndpointParametersT, context?: {
13
+ logger?: Logger;
14
+ }): EndpointV2;
15
+ }
16
+ /**
17
+ * @internal
18
+ */
19
+ export interface CreateEndpointRuleSetHttpAuthSchemeProvider<EndpointParametersT extends EndpointParameters = EndpointParameters, HttpAuthSchemeParametersT extends HttpAuthSchemeParameters = HttpAuthSchemeParameters> {
20
+ (defaultEndpointResolver: DefaultEndpointResolver<EndpointParametersT>, defaultHttpAuthSchemeResolver: HttpAuthSchemeProvider<HttpAuthSchemeParametersT>): EndpointRuleSetHttpAuthSchemeProvider;
21
+ }
22
+ /**
23
+ * @internal
24
+ */
25
+ export declare const createEndpointRuleSetHttpAuthSchemeProvider: CreateEndpointRuleSetHttpAuthSchemeProvider;
@@ -4,8 +4,11 @@ export * from "./HttpSigner";
4
4
  export * from "./IdentityProviderConfig";
5
5
  export * from "./SigV4Signer";
6
6
  export * from "./apiKeyIdentity";
7
+ export * from "./createEndpointRuleSetHttpAuthSchemeProvider";
7
8
  export * from "./httpApiKeyAuth";
8
9
  export * from "./httpBearerAuth";
10
+ export * from "./memoizeIdentityProvider";
11
+ export * from "./middleware-http-auth-scheme";
9
12
  export * from "./middleware-http-signing";
10
13
  export * from "./noAuth";
11
14
  export * from "./tokenIdentity";
@@ -0,0 +1,26 @@
1
+ import { Identity, IdentityProvider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ * This may need to be configurable in the future, but for now it is defaulted to 5min.
5
+ */
6
+ export declare const EXPIRATION_MS = 300000;
7
+ /**
8
+ * @internal
9
+ */
10
+ export declare const isIdentityExpired: (identity: Identity) => boolean;
11
+ /**
12
+ * @internal
13
+ */
14
+ export declare const doesIdentityRequireRefresh: (identity: Identity) => boolean;
15
+ /**
16
+ * @internal
17
+ */
18
+ export interface MemoizedIdentityProvider<IdentityT extends Identity> {
19
+ (options?: Record<string, any> & {
20
+ forceRefresh?: boolean;
21
+ }): Promise<IdentityT>;
22
+ }
23
+ /**
24
+ * @internal
25
+ */
26
+ export declare const memoizeIdentityProvider: <IdentityT extends Identity>(provider: IdentityT | IdentityProvider<IdentityT> | undefined, isExpired: (resolved: Identity) => boolean, requiresRefresh: (resolved: Identity) => boolean) => MemoizedIdentityProvider<IdentityT> | undefined;
@@ -0,0 +1,10 @@
1
+ import { MetadataBearer, Pluggable, RelativeMiddlewareOptions, SerializeHandlerOptions } from "@smithy/types";
2
+ import { PreviouslyResolved } from "./httpAuthSchemeMiddleware";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare const httpAuthSchemeMiddlewareOptions: SerializeHandlerOptions & RelativeMiddlewareOptions;
7
+ /**
8
+ * @internal
9
+ */
10
+ export declare const getHttpAuthSchemePlugin: <Input extends Record<string, unknown> = Record<string, unknown>, Output extends MetadataBearer = MetadataBearer>(config: PreviouslyResolved) => Pluggable<Input, Output>;
@@ -0,0 +1,17 @@
1
+ import { MetadataBearer, SerializeMiddleware } from "@smithy/types";
2
+ import { HttpAuthScheme } from "../HttpAuthScheme";
3
+ import { HttpAuthSchemeParametersProvider, HttpAuthSchemeProvider } from "../HttpAuthSchemeProvider";
4
+ import { IdentityProviderConfig } from "../IdentityProviderConfig";
5
+ /**
6
+ * @internal
7
+ */
8
+ export interface PreviouslyResolved {
9
+ httpAuthSchemes: HttpAuthScheme[];
10
+ httpAuthSchemeProvider: HttpAuthSchemeProvider;
11
+ httpAuthSchemeParametersProvider: HttpAuthSchemeParametersProvider;
12
+ identityProviderConfig: IdentityProviderConfig;
13
+ }
14
+ /**
15
+ * @internal
16
+ */
17
+ export declare const httpAuthSchemeMiddleware: <Input extends Record<string, unknown> = Record<string, unknown>, Output extends MetadataBearer = MetadataBearer>(config: PreviouslyResolved) => SerializeMiddleware<Input, Output>;
@@ -0,0 +1,2 @@
1
+ export * from "./httpAuthSchemeMiddleware";
2
+ export * from "./getHttpAuthSchemePlugin";
@@ -13,7 +13,7 @@ export interface IdentityProviderConfig {
13
13
  getIdentityProvider(schemeId: HttpAuthSchemeId): IdentityProvider<Identity> | undefined;
14
14
  }
15
15
  /**
16
- * Default implementation of IddentityProviderConfig
16
+ * Default implementation of IdentityProviderConfig
17
17
  * @internal
18
18
  */
19
19
  export declare class DefaultIdentityProviderConfig implements IdentityProviderConfig {
@@ -23,6 +23,6 @@ export declare class DefaultIdentityProviderConfig implements IdentityProviderCo
23
23
  *
24
24
  * @param config scheme IDs and identity providers to configure
25
25
  */
26
- constructor(config: Record<HttpAuthSchemeId, IdentityProvider<Identity>>);
26
+ constructor(config: Record<HttpAuthSchemeId, IdentityProvider<Identity> | undefined>);
27
27
  getIdentityProvider(schemeId: HttpAuthSchemeId): IdentityProvider<Identity> | undefined;
28
28
  }
@@ -0,0 +1,25 @@
1
+ import { EndpointParameters, EndpointV2, Logger } from "@smithy/types";
2
+ import { HttpAuthSchemeParameters, HttpAuthSchemeProvider } from "./HttpAuthSchemeProvider";
3
+ /**
4
+ * @internal
5
+ */
6
+ export interface EndpointRuleSetHttpAuthSchemeProvider<EndpointParametersT extends EndpointParameters = EndpointParameters, HttpAuthSchemeParametersT extends HttpAuthSchemeParameters = HttpAuthSchemeParameters> extends HttpAuthSchemeProvider<EndpointParametersT & HttpAuthSchemeParametersT> {
7
+ }
8
+ /**
9
+ * @internal
10
+ */
11
+ export interface DefaultEndpointResolver<EndpointParametersT extends EndpointParameters = EndpointParameters> {
12
+ (params: EndpointParametersT, context?: {
13
+ logger?: Logger;
14
+ }): EndpointV2;
15
+ }
16
+ /**
17
+ * @internal
18
+ */
19
+ export interface CreateEndpointRuleSetHttpAuthSchemeProvider<EndpointParametersT extends EndpointParameters = EndpointParameters, HttpAuthSchemeParametersT extends HttpAuthSchemeParameters = HttpAuthSchemeParameters> {
20
+ (defaultEndpointResolver: DefaultEndpointResolver<EndpointParametersT>, defaultHttpAuthSchemeResolver: HttpAuthSchemeProvider<HttpAuthSchemeParametersT>): EndpointRuleSetHttpAuthSchemeProvider;
21
+ }
22
+ /**
23
+ * @internal
24
+ */
25
+ export declare const createEndpointRuleSetHttpAuthSchemeProvider: CreateEndpointRuleSetHttpAuthSchemeProvider;
@@ -4,8 +4,11 @@ export * from "./HttpSigner";
4
4
  export * from "./IdentityProviderConfig";
5
5
  export * from "./SigV4Signer";
6
6
  export * from "./apiKeyIdentity";
7
+ export * from "./createEndpointRuleSetHttpAuthSchemeProvider";
7
8
  export * from "./httpApiKeyAuth";
8
9
  export * from "./httpBearerAuth";
10
+ export * from "./memoizeIdentityProvider";
11
+ export * from "./middleware-http-auth-scheme";
9
12
  export * from "./middleware-http-signing";
10
13
  export * from "./noAuth";
11
14
  export * from "./tokenIdentity";
@@ -0,0 +1,26 @@
1
+ import { Identity, IdentityProvider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ * This may need to be configurable in the future, but for now it is defaulted to 5min.
5
+ */
6
+ export declare const EXPIRATION_MS = 300000;
7
+ /**
8
+ * @internal
9
+ */
10
+ export declare const isIdentityExpired: (identity: Identity) => boolean;
11
+ /**
12
+ * @internal
13
+ */
14
+ export declare const doesIdentityRequireRefresh: (identity: Identity) => boolean;
15
+ /**
16
+ * @internal
17
+ */
18
+ export interface MemoizedIdentityProvider<IdentityT extends Identity> {
19
+ (options?: Record<string, any> & {
20
+ forceRefresh?: boolean;
21
+ }): Promise<IdentityT>;
22
+ }
23
+ /**
24
+ * @internal
25
+ */
26
+ export declare const memoizeIdentityProvider: <IdentityT extends Identity>(provider: IdentityT | IdentityProvider<IdentityT> | undefined, isExpired: (resolved: Identity) => boolean, requiresRefresh: (resolved: Identity) => boolean) => MemoizedIdentityProvider<IdentityT> | undefined;
@@ -0,0 +1,10 @@
1
+ import { MetadataBearer, Pluggable, RelativeMiddlewareOptions, SerializeHandlerOptions } from "@smithy/types";
2
+ import { PreviouslyResolved } from "./httpAuthSchemeMiddleware";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare const httpAuthSchemeMiddlewareOptions: SerializeHandlerOptions & RelativeMiddlewareOptions;
7
+ /**
8
+ * @internal
9
+ */
10
+ export declare const getHttpAuthSchemePlugin: <Input extends Record<string, unknown> = Record<string, unknown>, Output extends MetadataBearer = MetadataBearer>(config: PreviouslyResolved) => Pluggable<Input, Output>;
@@ -0,0 +1,17 @@
1
+ import { MetadataBearer, SerializeMiddleware } from "@smithy/types";
2
+ import { HttpAuthScheme } from "../HttpAuthScheme";
3
+ import { HttpAuthSchemeParametersProvider, HttpAuthSchemeProvider } from "../HttpAuthSchemeProvider";
4
+ import { IdentityProviderConfig } from "../IdentityProviderConfig";
5
+ /**
6
+ * @internal
7
+ */
8
+ export interface PreviouslyResolved {
9
+ httpAuthSchemes: HttpAuthScheme[];
10
+ httpAuthSchemeProvider: HttpAuthSchemeProvider;
11
+ httpAuthSchemeParametersProvider: HttpAuthSchemeParametersProvider;
12
+ identityProviderConfig: IdentityProviderConfig;
13
+ }
14
+ /**
15
+ * @internal
16
+ */
17
+ export declare const httpAuthSchemeMiddleware: <Input extends Record<string, unknown> = Record<string, unknown>, Output extends MetadataBearer = MetadataBearer>(config: PreviouslyResolved) => SerializeMiddleware<Input, Output>;
@@ -0,0 +1,2 @@
1
+ export * from "./httpAuthSchemeMiddleware";
2
+ export * from "./getHttpAuthSchemePlugin";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/experimental-identity-and-auth",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "tsc -p tsconfig.cjs.json",
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
+ "@smithy/middleware-endpoint": "^2.0.9",
26
27
  "@smithy/middleware-retry": "^2.0.12",
27
28
  "@smithy/protocol-http": "^3.0.5",
28
29
  "@smithy/signature-v4": "^2.0.9",