fix(gen2-migration): convert OIDC TTL values from milliseconds to seconds#14846
Draft
fix(gen2-migration): convert OIDC TTL values from milliseconds to seconds#14846
Conversation
…ds (#14812) The AppSync OpenIDConnectConfig stores authTTL and iatTTL in milliseconds, but the Gen 2 oidcAuthorizationMode expects tokenExpiryFromAuthInSeconds and tokenExpireFromIssueInSeconds in seconds. The renderer was passing the millisecond values through without dividing by 1000, producing incorrect TTL values in the generated resource.ts. Updated the test mock data to use millisecond values (matching the real authConfig format from amplify-meta.json) to ensure the conversion is exercised. Tested: yarn build && yarn test in packages/amplify-cli — 131 suites, 755 tests, 125 snapshots all pass. --- Prompt: Fix issue #14812 — OIDC clientId and TTL conversion bugs in gen2-migration generate step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solves #14812.
Issue Summary
When migrating a Gen 1 GraphQL API with OIDC as an additional authorization provider to Gen 2, the
tokenExpiryFromAuthInSecondsandtokenExpireFromIssueInSecondsfields in the generatedoidcAuthorizationModeconfig receive incorrect values. The AppSyncOpenIDConnectConfigstoresauthTTLandiatTTLin milliseconds, but the migration code passes them through to the Gen 2 output (which expects seconds) without dividing by 1000.The issue also mentions
clientId— the renderer already handlesclientIdcorrectly (it emits it when present in theauthConfig). TheclientIdconcern in the issue is about the Gen 2@aws-amplify/backend-datatype definition not exposing the property, which is outside the scope of the migration CLI.Reasoning
clientIdand wrong TTL values.data.renderer.ts→ foundaddOidcConfig()method.clientIdwhencfg.clientIdis present — no bug there.OpenIDConnectConfigdocumentation —authTTLandiatTTLare in milliseconds.authConfiginamplify-meta.jsonstores TTL values in milliseconds (matching the AppSync/CFN format).cfg.authTTLdirectly totokenExpiryFromAuthInSecondswithout conversion — this is the bug.authTTL: 3600(already in seconds), masking the bug. Updated the test to useauthTTL: 3600000(milliseconds) to match real data.Solution
packages/amplify-cli/src/commands/gen2-migration/generate/amplify/data/data.renderer.tsaddOidcConfig(), dividecfg.authTTLandcfg.iatTTLby 1000 (usingMath.floor) before emitting them astokenExpiryFromAuthInSecondsandtokenExpireFromIssueInSeconds.packages/amplify-cli/src/__tests__/commands/gen2-migration/generate/amplify/data/data.generator.test.tsauthTTL: 3600000,iatTTL: 7200000) matching the realauthConfigformat fromamplify-meta.json.Example
Input (Gen 1 / pre-generate):
amplify-meta.json→api.testApi.output.authConfig:{ "additionalAuthenticationProviders": [ { "authenticationType": "OPENID_CONNECT", "openIDConnectConfig": { "name": "MyOIDC", "issuerUrl": "https://example.com", "clientId": "client123", "authTTL": 3600000, "iatTTL": 7200000 } } ] }Output — before fix (post-generate):
Output — after fix (post-generate):