@smithy/experimental-identity-and-auth 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SigV4Signer = void 0;
4
+ const signature_v4_1 = require("@smithy/signature-v4");
5
+ class SigV4Signer {
6
+ async sign(httpRequest, identity, signingProperties) {
7
+ const clonedRequest = httpRequest.clone();
8
+ const signer = new signature_v4_1.SignatureV4({
9
+ applyChecksum: signingProperties.applyChecksum !== undefined ? signingProperties.applyChecksum : true,
10
+ credentials: identity,
11
+ region: signingProperties.region,
12
+ service: signingProperties.name,
13
+ sha256: signingProperties.sha256,
14
+ uriEscapePath: signingProperties.uriEscapePath !== undefined ? signingProperties.uriEscapePath : true,
15
+ });
16
+ return signer.sign(clonedRequest, {
17
+ signingDate: new Date(),
18
+ signableHeaders: signingProperties.signableHeaders,
19
+ unsignableHeaders: signingProperties.unsignableHeaders,
20
+ signingRegion: signingProperties.signingRegion,
21
+ signingService: signingProperties.signingService,
22
+ });
23
+ }
24
+ }
25
+ exports.SigV4Signer = SigV4Signer;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpApiKeyAuthSigner = exports.HttpApiKeyAuthLocation = void 0;
4
+ var HttpApiKeyAuthLocation;
5
+ (function (HttpApiKeyAuthLocation) {
6
+ HttpApiKeyAuthLocation["HEADER"] = "header";
7
+ HttpApiKeyAuthLocation["QUERY"] = "query";
8
+ })(HttpApiKeyAuthLocation = exports.HttpApiKeyAuthLocation || (exports.HttpApiKeyAuthLocation = {}));
9
+ class HttpApiKeyAuthSigner {
10
+ async sign(httpRequest, identity, signingProperties) {
11
+ if (!signingProperties) {
12
+ throw new Error("request could not be signed with `apiKey` since the `name` and `in` signer properties are missing");
13
+ }
14
+ if (!signingProperties.name) {
15
+ throw new Error("request could not be signed with `apiKey` since the `name` signer property is missing");
16
+ }
17
+ if (!signingProperties.in) {
18
+ throw new Error("request could not be signed with `apiKey` since the `in` signer property is missing");
19
+ }
20
+ const clonedRequest = httpRequest.clone();
21
+ if (signingProperties.in === HttpApiKeyAuthLocation.QUERY) {
22
+ clonedRequest.query[signingProperties.name] = identity.apiKey;
23
+ }
24
+ else if (signingProperties.in === HttpApiKeyAuthLocation.HEADER) {
25
+ clonedRequest.headers[signingProperties.name] = signingProperties.scheme
26
+ ? `$${signingProperties.scheme} $${identity.apiKey}`
27
+ : identity.apiKey;
28
+ }
29
+ else {
30
+ throw new Error("request can only be signed with `apiKey` locations `query` or `header`, " +
31
+ "but found: `" +
32
+ signingProperties.in +
33
+ "`");
34
+ }
35
+ return clonedRequest;
36
+ }
37
+ }
38
+ exports.HttpApiKeyAuthSigner = HttpApiKeyAuthSigner;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpBearerAuthSigner = void 0;
4
+ class HttpBearerAuthSigner {
5
+ async sign(httpRequest, identity, signingProperties) {
6
+ const clonedRequest = httpRequest.clone();
7
+ clonedRequest.headers["Authorization"] = `Bearer ${identity.token}`;
8
+ return clonedRequest;
9
+ }
10
+ }
11
+ exports.HttpBearerAuthSigner = HttpBearerAuthSigner;
package/dist-cjs/index.js CHANGED
@@ -4,4 +4,9 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./IdentityProviderConfiguration"), exports);
5
5
  tslib_1.__exportStar(require("./HttpAuthScheme"), exports);
6
6
  tslib_1.__exportStar(require("./HttpSigner"), exports);
7
+ tslib_1.__exportStar(require("./SigV4Signer"), exports);
8
+ tslib_1.__exportStar(require("./apiKeyIdentity"), exports);
9
+ tslib_1.__exportStar(require("./httpApiKeyAuth"), exports);
10
+ tslib_1.__exportStar(require("./httpBearerAuth"), exports);
7
11
  tslib_1.__exportStar(require("./noAuth"), exports);
12
+ tslib_1.__exportStar(require("./tokenIdentity"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { SignatureV4 } from "@smithy/signature-v4";
2
+ export class SigV4Signer {
3
+ async sign(httpRequest, identity, signingProperties) {
4
+ const clonedRequest = httpRequest.clone();
5
+ const signer = new SignatureV4({
6
+ applyChecksum: signingProperties.applyChecksum !== undefined ? signingProperties.applyChecksum : true,
7
+ credentials: identity,
8
+ region: signingProperties.region,
9
+ service: signingProperties.name,
10
+ sha256: signingProperties.sha256,
11
+ uriEscapePath: signingProperties.uriEscapePath !== undefined ? signingProperties.uriEscapePath : true,
12
+ });
13
+ return signer.sign(clonedRequest, {
14
+ signingDate: new Date(),
15
+ signableHeaders: signingProperties.signableHeaders,
16
+ unsignableHeaders: signingProperties.unsignableHeaders,
17
+ signingRegion: signingProperties.signingRegion,
18
+ signingService: signingProperties.signingService,
19
+ });
20
+ }
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ export var HttpApiKeyAuthLocation;
2
+ (function (HttpApiKeyAuthLocation) {
3
+ HttpApiKeyAuthLocation["HEADER"] = "header";
4
+ HttpApiKeyAuthLocation["QUERY"] = "query";
5
+ })(HttpApiKeyAuthLocation || (HttpApiKeyAuthLocation = {}));
6
+ export class HttpApiKeyAuthSigner {
7
+ async sign(httpRequest, identity, signingProperties) {
8
+ if (!signingProperties) {
9
+ throw new Error("request could not be signed with `apiKey` since the `name` and `in` signer properties are missing");
10
+ }
11
+ if (!signingProperties.name) {
12
+ throw new Error("request could not be signed with `apiKey` since the `name` signer property is missing");
13
+ }
14
+ if (!signingProperties.in) {
15
+ throw new Error("request could not be signed with `apiKey` since the `in` signer property is missing");
16
+ }
17
+ const clonedRequest = httpRequest.clone();
18
+ if (signingProperties.in === HttpApiKeyAuthLocation.QUERY) {
19
+ clonedRequest.query[signingProperties.name] = identity.apiKey;
20
+ }
21
+ else if (signingProperties.in === HttpApiKeyAuthLocation.HEADER) {
22
+ clonedRequest.headers[signingProperties.name] = signingProperties.scheme
23
+ ? `$${signingProperties.scheme} $${identity.apiKey}`
24
+ : identity.apiKey;
25
+ }
26
+ else {
27
+ throw new Error("request can only be signed with `apiKey` locations `query` or `header`, " +
28
+ "but found: `" +
29
+ signingProperties.in +
30
+ "`");
31
+ }
32
+ return clonedRequest;
33
+ }
34
+ }
@@ -0,0 +1,7 @@
1
+ export class HttpBearerAuthSigner {
2
+ async sign(httpRequest, identity, signingProperties) {
3
+ const clonedRequest = httpRequest.clone();
4
+ clonedRequest.headers["Authorization"] = `Bearer ${identity.token}`;
5
+ return clonedRequest;
6
+ }
7
+ }
package/dist-es/index.js CHANGED
@@ -1,4 +1,9 @@
1
1
  export * from "./IdentityProviderConfiguration";
2
2
  export * from "./HttpAuthScheme";
3
3
  export * from "./HttpSigner";
4
+ export * from "./SigV4Signer";
5
+ export * from "./apiKeyIdentity";
6
+ export * from "./httpApiKeyAuth";
7
+ export * from "./httpBearerAuth";
4
8
  export * from "./noAuth";
9
+ export * from "./tokenIdentity";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { AwsCredentialIdentity, HttpRequest as IHttpRequest } from "@smithy/types";
3
+ import { HttpSigner } from "./HttpSigner";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare class SigV4Signer implements HttpSigner {
8
+ sign(httpRequest: HttpRequest, identity: AwsCredentialIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
9
+ }
@@ -0,0 +1,11 @@
1
+ import { Identity, IdentityProvider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export interface ApiKeyIdentity extends Identity {
6
+ readonly apiKey: string;
7
+ }
8
+ /**
9
+ * @internal
10
+ */
11
+ export type ApiKeyIdentityProvider = IdentityProvider<ApiKeyIdentity>;
@@ -0,0 +1,17 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { HttpRequest as IHttpRequest } from "@smithy/types";
3
+ import { ApiKeyIdentity } from "./apiKeyIdentity";
4
+ import { HttpSigner } from "./HttpSigner";
5
+ /**
6
+ * @internal
7
+ */
8
+ export declare enum HttpApiKeyAuthLocation {
9
+ HEADER = "header",
10
+ QUERY = "query"
11
+ }
12
+ /**
13
+ * @internal
14
+ */
15
+ export declare class HttpApiKeyAuthSigner implements HttpSigner {
16
+ sign(httpRequest: HttpRequest, identity: ApiKeyIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
17
+ }
@@ -0,0 +1,10 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { HttpRequest as IHttpRequest } from "@smithy/types";
3
+ import { HttpSigner } from "./HttpSigner";
4
+ import { TokenIdentity } from "./tokenIdentity";
5
+ /**
6
+ * @internal
7
+ */
8
+ export declare class HttpBearerAuthSigner implements HttpSigner {
9
+ sign(httpRequest: HttpRequest, identity: TokenIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
10
+ }
@@ -1,4 +1,9 @@
1
1
  export * from "./IdentityProviderConfiguration";
2
2
  export * from "./HttpAuthScheme";
3
3
  export * from "./HttpSigner";
4
+ export * from "./SigV4Signer";
5
+ export * from "./apiKeyIdentity";
6
+ export * from "./httpApiKeyAuth";
7
+ export * from "./httpBearerAuth";
4
8
  export * from "./noAuth";
9
+ export * from "./tokenIdentity";
@@ -0,0 +1,14 @@
1
+ import { Identity, IdentityProvider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export interface TokenIdentity extends Identity {
6
+ /**
7
+ * The literal token string
8
+ */
9
+ readonly token: string;
10
+ }
11
+ /**
12
+ * @internal
13
+ */
14
+ export type TokenIdentityProvider = IdentityProvider<TokenIdentity>;
@@ -0,0 +1,9 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { AwsCredentialIdentity, HttpRequest as IHttpRequest } from "@smithy/types";
3
+ import { HttpSigner } from "./HttpSigner";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare class SigV4Signer implements HttpSigner {
8
+ sign(httpRequest: HttpRequest, identity: AwsCredentialIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
9
+ }
@@ -0,0 +1,11 @@
1
+ import { Identity, IdentityProvider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export interface ApiKeyIdentity extends Identity {
6
+ readonly apiKey: string;
7
+ }
8
+ /**
9
+ * @internal
10
+ */
11
+ export type ApiKeyIdentityProvider = IdentityProvider<ApiKeyIdentity>;
@@ -0,0 +1,17 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { HttpRequest as IHttpRequest } from "@smithy/types";
3
+ import { ApiKeyIdentity } from "./apiKeyIdentity";
4
+ import { HttpSigner } from "./HttpSigner";
5
+ /**
6
+ * @internal
7
+ */
8
+ export declare enum HttpApiKeyAuthLocation {
9
+ HEADER = "header",
10
+ QUERY = "query"
11
+ }
12
+ /**
13
+ * @internal
14
+ */
15
+ export declare class HttpApiKeyAuthSigner implements HttpSigner {
16
+ sign(httpRequest: HttpRequest, identity: ApiKeyIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
17
+ }
@@ -0,0 +1,10 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { HttpRequest as IHttpRequest } from "@smithy/types";
3
+ import { HttpSigner } from "./HttpSigner";
4
+ import { TokenIdentity } from "./tokenIdentity";
5
+ /**
6
+ * @internal
7
+ */
8
+ export declare class HttpBearerAuthSigner implements HttpSigner {
9
+ sign(httpRequest: HttpRequest, identity: TokenIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
10
+ }
@@ -1,4 +1,9 @@
1
1
  export * from "./IdentityProviderConfiguration";
2
2
  export * from "./HttpAuthScheme";
3
3
  export * from "./HttpSigner";
4
+ export * from "./SigV4Signer";
5
+ export * from "./apiKeyIdentity";
6
+ export * from "./httpApiKeyAuth";
7
+ export * from "./httpBearerAuth";
4
8
  export * from "./noAuth";
9
+ export * from "./tokenIdentity";
@@ -0,0 +1,14 @@
1
+ import { Identity, IdentityProvider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export interface TokenIdentity extends Identity {
6
+ /**
7
+ * The literal token string
8
+ */
9
+ readonly token: string;
10
+ }
11
+ /**
12
+ * @internal
13
+ */
14
+ export type TokenIdentityProvider = IdentityProvider<TokenIdentity>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/experimental-identity-and-auth",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
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,8 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
+ "@smithy/protocol-http": "^2.0.5",
27
+ "@smithy/signature-v4": "^2.0.5",
26
28
  "@smithy/types": "^2.2.2",
27
29
  "tslib": "^2.5.0"
28
30
  },