Skip to content

Commit

Permalink
feat(experimentalIdentityAndAuth): add @aws.auth#sigv4 TypeScript code
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Yuan authored and syall committed Sep 1, 2023
1 parent 7dc6d76 commit 019109d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-adults-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/experimental-identity-and-auth": patch
---

INTERNAL USE ONLY: Add `@aws.auth#sigv4` interfaces and classes
1 change: 1 addition & 0 deletions packages/experimental-identity-and-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"license": "Apache-2.0",
"dependencies": {
"@smithy/protocol-http": "workspace:^",
"@smithy/signature-v4": "workspace:^",
"@smithy/types": "workspace:^",
"tslib": "^2.5.0"
},
Expand Down
33 changes: 33 additions & 0 deletions packages/experimental-identity-and-auth/src/SigV4Signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { HttpRequest } from "@smithy/protocol-http";
import { SignatureV4 } from "@smithy/signature-v4";
import { AwsCredentialIdentity, HttpRequest as IHttpRequest } from "@smithy/types";

import { HttpSigner } from "./HttpSigner";

/**
* @internal
*/
export class SigV4Signer implements HttpSigner {
async sign(
httpRequest: HttpRequest,
identity: AwsCredentialIdentity,
signingProperties: Record<string, any>
): Promise<IHttpRequest> {
const clonedRequest = httpRequest.clone();
const signer = new SignatureV4({
applyChecksum: signingProperties.applyChecksum !== undefined ? signingProperties.applyChecksum : true,
credentials: identity,
region: signingProperties.region,
service: signingProperties.name,
sha256: signingProperties.sha256,
uriEscapePath: signingProperties.uriEscapePath !== undefined ? signingProperties.uriEscapePath : true,
});
return signer.sign(clonedRequest, {
signingDate: new Date(),
signableHeaders: signingProperties.signableHeaders,
unsignableHeaders: signingProperties.unsignableHeaders,
signingRegion: signingProperties.signingRegion,
signingService: signingProperties.signingService,
});
}
}
3 changes: 2 additions & 1 deletion packages/experimental-identity-and-auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export * from "./IdentityProviderConfiguration";
export * from "./HttpAuthScheme";
export * from "./HttpSigner";
export * from "./noAuth";
export * from "./SigV4Signer";
export * from "./apiKeyIdentity";
export * from "./httpApiKeyAuth";
export * from "./httpBearerAuth";
export * from "./noAuth";
export * from "./tokenIdentity";
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,7 @@ __metadata:
resolution: "@smithy/experimental-identity-and-auth@workspace:packages/experimental-identity-and-auth"
dependencies:
"@smithy/protocol-http": "workspace:^"
"@smithy/signature-v4": "workspace:^"
"@smithy/types": "workspace:^"
"@tsconfig/recommended": 1.0.1
concurrently: 7.0.0
Expand Down Expand Up @@ -2330,7 +2331,7 @@ __metadata:
languageName: unknown
linkType: soft

"@smithy/signature-v4@workspace:packages/signature-v4":
"@smithy/signature-v4@workspace:^, @smithy/signature-v4@workspace:packages/signature-v4":
version: 0.0.0-use.local
resolution: "@smithy/signature-v4@workspace:packages/signature-v4"
dependencies:
Expand Down

0 comments on commit 019109d

Please sign in to comment.