Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(experimentalIdentityAndAuth): update HttpAuthOption and HttpAuthScheme codegen #907

Merged
merged 3 commits into from Sep 6, 2023

Conversation

syall
Copy link
Contributor

@syall syall commented Sep 2, 2023

Issue

Issue number, if available, prefixed with "#"

N/A.

Description

What does this implement/fix? Explain your changes.

After upgrading to Smithy 1.37.0
(#906), upgrade to
getEffectiveAuthSchemes using NO_AUTH_AWARE and remove redundant
code.

For HttpAuthOption, allow any auth scheme to generate the
corresponding HttpAuthOption function regardless of registering it in
codegen.

For HttpAuthScheme, reduce code duplication by looking at "inherited"
LanguageTarget platforms (e.g. REACT_NATIVE inherits from
BROWSER). httpAuthSchemes is only written in a runtimeConfig if
the IdentityProvider and Signer are different between platforms, or
if the registered HttpAuthSchemes are different. httpAuthSchemes is
always written for SHARED as a default.

For the httpAuthSchemes property on the client config interface,
update it to HttpAuthScheme[] rather than
IdentityProviderConfiguration.

Also, add @customAuth auth scheme to generic tests.

Testing

How was this change tested?

Everything is gated behind the experimentalIdentityAndAuth flag.

Observed codegen diff between the source projection and the client-identity-and-auth projection in smithy-typescript-codegen-test: https://gist.github.com/syall/03a85aa0578d37a78413d0689cdfb1ad#file-pr-907-diff

HttpAuthOption

Auth options will be generated even for unregistered auth schemes, e.g. @example.weather#customAuth in the smithy-typescript-codegen-test:

diff --color -Nur smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/auth/httpAuthSchemeProvider.ts smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/auth/httpAuthSchemeProvider.ts
--- smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/auth/httpAuthSchemeProvider.ts	1969-12-31 16:00:00
+++ smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/auth/httpAuthSchemeProvider.ts	2023-09-05 15:50:34
@@ -0,0 +1,132 @@
+
+function createExampleWeatherCustomAuthHttpAuthOption(authParameters: WeatherHttpAuthSchemeParameters): HttpAuthOption {
+  return {
+    schemeId: "example.weather#customAuth",
+  };
+};
@@ Skipping a bunch of lines @@
+    case "OnlyCustomAuth": {
+      options.push(createExampleWeatherCustomAuthHttpAuthOption(authParameters));
+      break;
+    };
+    case "OnlyCustomAuthOptional": {
+      options.push(createExampleWeatherCustomAuthHttpAuthOption(authParameters));
+      options.push(createSmithyApiNoAuthHttpAuthOption(authParameters));
+      break;
+    };

HttpAuthScheme

HttpAuthScheme now accepts IdentityProviderConfig as a parameter, and by default will try to get an identity resolver from the config abstraction:

diff --color -Nur smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/runtimeConfig.shared.ts smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/runtimeConfig.shared.ts
--- smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/runtimeConfig.shared.ts	2023-09-05 15:50:34
+++ smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/runtimeConfig.shared.ts	2023-09-05 15:50:34
@@ -1,4 +1,12 @@
 // smithy-typescript generated code
+import { defaultWeatherHttpAuthSchemeProvider } from "./auth/httpAuthSchemeProvider";
+import {
+  HttpApiKeyAuthSigner,
+  HttpBearerAuthSigner,
+  IdentityProviderConfig,
+  NoAuthSigner,
+  SigV4Signer,
+} from "@smithy/experimental-identity-and-auth";
 import { NoOpLogger } from "@smithy/smithy-client";
 import { parseUrl } from "@smithy/url-parser";
 import {
@@ -21,6 +29,28 @@
   base64Encoder: config?.base64Encoder ?? toBase64,
   disableHostPrefix: config?.disableHostPrefix ?? false,
   extensions: config?.extensions ?? [],
+  httpAuthSchemeProvider: config?.httpAuthSchemeProvider ?? defaultWeatherHttpAuthSchemeProvider,
+  httpAuthSchemes: config?.httpAuthSchemes ?? [{
+        schemeId: "aws.auth#sigv4",
+        identityProvider: (config: IdentityProviderConfig) =>
+          config.getIdentityProvider("aws.auth#sigv4"),
+        signer: new SigV4Signer(),
+      }, {
+        schemeId: "smithy.api#httpApiKeyAuth",
+        identityProvider: (config: IdentityProviderConfig) =>
+          config.getIdentityProvider("smithy.api#httpApiKeyAuth"),
+        signer: new HttpApiKeyAuthSigner(),
+      }, {
+        schemeId: "smithy.api#httpBearerAuth",
+        identityProvider: (config: IdentityProviderConfig) =>
+          config.getIdentityProvider("smithy.api#httpBearerAuth"),
+        signer: new HttpBearerAuthSigner(),
+      }, {
+        schemeId: "smithy.api#noAuth",
+        identityProvider: (config: IdentityProviderConfig) =>
+          config.getIdentityProvider("smithy.api#noAuth") || (async () => ({})),
+        signer: new NoAuthSigner(),
+      }],
   logger: config?.logger ?? new NoOpLogger(),
   sdkStreamMixin: config?.sdkStreamMixin ?? sdkStreamMixin,
   urlParser: config?.urlParser ?? parseUrl,

Additional context

Add any other context about the PR here.

N/A.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…ityProviderConfig` interfaces

Update `HttpAuthScheme` to use `IdentityProviderConfig` as an
abstraction over a client's configuration.
…uthScheme` codegen

After upgrading to Smithy 1.37.0
(smithy-lang#906), upgrade to
`getEffectiveAuthSchemes` using `NO_AUTH_AWARE` and remove redundant
code.

For `HttpAuthOption`, allow any auth scheme to generate the
corresponding `HttpAuthOption` function regardless of registering it in
codegen.

For `HttpAuthScheme`, reduce code duplication by looking at "inherited"
`LanguageTarget` platforms (e.g. `REACT_NATIVE` inherits from
`BROWSER`). `httpAuthSchemes` is only written in a `runtimeConfig` if
the `IdentityProvider` and `Signer` are different between platforms, or
if the registered `HttpAuthScheme`s are different. `httpAuthSchemes` is
always written for `SHARED` as a default.

For the `httpAuthSchemes` property on the client config interface,
update it to `HttpAuthScheme[]` rather than
`IdentityProviderConfiguration`.
@syall syall merged commit 98a8e90 into smithy-lang:main Sep 6, 2023
7 checks passed
@syall syall deleted the ts-ia-no-auth-aware branch September 7, 2023 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants