Skip to content

Commit 019109d

Browse files
Steven Yuansyall
authored andcommitted
feat(experimentalIdentityAndAuth): add @aws.auth#sigv4 TypeScript code
1 parent 7dc6d76 commit 019109d

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

.changeset/shaggy-adults-yawn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/experimental-identity-and-auth": patch
3+
---
4+
5+
INTERNAL USE ONLY: Add `@aws.auth#sigv4` interfaces and classes

packages/experimental-identity-and-auth/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"license": "Apache-2.0",
2525
"dependencies": {
2626
"@smithy/protocol-http": "workspace:^",
27+
"@smithy/signature-v4": "workspace:^",
2728
"@smithy/types": "workspace:^",
2829
"tslib": "^2.5.0"
2930
},
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { HttpRequest } from "@smithy/protocol-http";
2+
import { SignatureV4 } from "@smithy/signature-v4";
3+
import { AwsCredentialIdentity, HttpRequest as IHttpRequest } from "@smithy/types";
4+
5+
import { HttpSigner } from "./HttpSigner";
6+
7+
/**
8+
* @internal
9+
*/
10+
export class SigV4Signer implements HttpSigner {
11+
async sign(
12+
httpRequest: HttpRequest,
13+
identity: AwsCredentialIdentity,
14+
signingProperties: Record<string, any>
15+
): Promise<IHttpRequest> {
16+
const clonedRequest = httpRequest.clone();
17+
const signer = new SignatureV4({
18+
applyChecksum: signingProperties.applyChecksum !== undefined ? signingProperties.applyChecksum : true,
19+
credentials: identity,
20+
region: signingProperties.region,
21+
service: signingProperties.name,
22+
sha256: signingProperties.sha256,
23+
uriEscapePath: signingProperties.uriEscapePath !== undefined ? signingProperties.uriEscapePath : true,
24+
});
25+
return signer.sign(clonedRequest, {
26+
signingDate: new Date(),
27+
signableHeaders: signingProperties.signableHeaders,
28+
unsignableHeaders: signingProperties.unsignableHeaders,
29+
signingRegion: signingProperties.signingRegion,
30+
signingService: signingProperties.signingService,
31+
});
32+
}
33+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export * from "./IdentityProviderConfiguration";
22
export * from "./HttpAuthScheme";
33
export * from "./HttpSigner";
4-
export * from "./noAuth";
4+
export * from "./SigV4Signer";
55
export * from "./apiKeyIdentity";
66
export * from "./httpApiKeyAuth";
77
export * from "./httpBearerAuth";
8+
export * from "./noAuth";
89
export * from "./tokenIdentity";

yarn.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,7 @@ __metadata:
18901890
resolution: "@smithy/experimental-identity-and-auth@workspace:packages/experimental-identity-and-auth"
18911891
dependencies:
18921892
"@smithy/protocol-http": "workspace:^"
1893+
"@smithy/signature-v4": "workspace:^"
18931894
"@smithy/types": "workspace:^"
18941895
"@tsconfig/recommended": 1.0.1
18951896
concurrently: 7.0.0
@@ -2330,7 +2331,7 @@ __metadata:
23302331
languageName: unknown
23312332
linkType: soft
23322333

2333-
"@smithy/signature-v4@workspace:packages/signature-v4":
2334+
"@smithy/signature-v4@workspace:^, @smithy/signature-v4@workspace:packages/signature-v4":
23342335
version: 0.0.0-use.local
23352336
resolution: "@smithy/signature-v4@workspace:packages/signature-v4"
23362337
dependencies:

0 commit comments

Comments
 (0)