fix(cli): fix OAuth provider scopes and attribute mappings in generate#14777
Draft
9pace wants to merge 1 commit intogen2-migrationfrom
Draft
fix(cli): fix OAuth provider scopes and attribute mappings in generate#147779pace wants to merge 1 commit intogen2-migrationfrom
9pace wants to merge 1 commit intogen2-migrationfrom
Conversation
Three bugs in auth.renderer.ts caused generate to produce broken OAuth config for social identity providers (Google, Facebook): 1. Scope field name typo: deriveProviderSpecificScopes() looked for 'authorized_scopes' but Cognito returns 'authorize_scopes'. Scopes were never collected. Added the correct field name to the lookup. 2. Scope mangling: provider scopes were filtered against VALID_SCOPES (Cognito OAuth scopes), which is the wrong namespace. Facebook's 'public_profile' was mapped to 'profile'. Removed the filter — provider scopes are now passed through as-is. 3. Attribute mapping: filterAttributeMapping() dropped keys not in MAPPED_USER_ATTRIBUTE_NAME (e.g. 'username' -> 'sub' for Google, 'username' -> 'id' for Facebook). Changed to route unknown keys into a 'custom' sub-object matching Gen2's AttributeMapping CDK interface. Caveats: - Provider scopes are no longer validated. The old validation was incorrect (wrong namespace), but there is now no validation at all — whatever the provider returns is passed through verbatim. - OIDC/SAML providers flatten standard + custom back into a single Record since their rendering path doesn't support the custom sub-object. If a custom key collides with a mapped standard key, the custom value wins. Verified end-to-end with a test app using Google and Facebook social login. Gen2 deployed with correct scopes and attribute mappings without manual post-generate edits to OAuth config.
1ffface to
66e090b
Compare
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.
Summary
authorized_scopes→authorize_scopes(Cognito's actual field name)VALID_SCOPESfilter that mangled provider scopes (e.g. Facebook'spublic_profile→profile)username→sub/id) intocustomsub-object instead of dropping themBefore (generated
resource.ts)Scopes missing entirely.
username→sub/idmapping dropped.After (generated
resource.ts)Caveats
customsub-objectTest plan