feat(util): add authType derived from the request identity - #296
Open
bentsku wants to merge 1 commit into
Open
Conversation
`util.authType()` was implemented in localstack-pro by threading a request-scoped string through the resolver stack and monkey-patching `globalThis.util.authType` on every JS invocation, which mutated the module singleton user code imports and left `EvaluateCode` returning an empty string where AWS returns an auth mode. The utils now own the function and read it off `ctx.identity`, which AppSync shapes per authorization mode. A host installs the request with the new `setResolverContext` export before calling the resolver. The mapping is recorded from `EvaluateCode` across every identity shape in the AppSync resolver context reference plus the mixtures between two modes: an identity belongs to a mode when all of its keys are keys of that mode and every key the mode requires is present and not null. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
bentsku
force-pushed
the
aws-1680-appsync-authtype-from-identity
branch
from
September 2, 2026 20:46
e68214e to
ccc0620
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.
1/2 of a stack. 2/2 is #297; the two are meant to land under one release.
Problem
util.authType()was missing, so a host had to patch it onto the module at request time. That mutates the singleton every resolver imports, and it left the function returning""underEvaluateCodewhere AWS returns an auth mode.What this does
util.authType()derives the mode fromctx.identity, which AppSync shapes per authorization mode. A host installs the request with a newsetResolverContextexport immediately before calling the resolver.Recorded from
EvaluateCodeover every identity shape in the resolver context reference plus the mixtures between two modes. An identity belongs to a mode when every key of the identity is a key of that mode and every key the mode requires is present and not null:Lambda AuthorizationresolverContextIAM AuthorizationaccountId,sourceIp,username,userArn,cognitoIdentityPoolId,cognitoIdentityId,cognitoIdentityAuthType,cognitoIdentityAuthProviderUser Pool AuthorizationsourceIp,username,groups,sub,issuer,claims,defaultAuthStrategygroupsOpen ID Connect Authorizationsub,issuer,claimsAnything unmatched, an absent identity included, is
API Key Authorization. Two consequences that are easy to get wrong: an identity with no keys at all is a Lambda identity, and a key belonging to another mode rules a mode out rather than being ignored, so{sub, issuer, claims, username}is an incomplete user pool identity and not an OIDC one.Tests
15 snapshots recorded from
EvaluateCode, one per identity shape and per fallback, plus acheckValidcase. A separate block asserts thesetResolverContextseam with plainexpect; those are not compared against AWS and the comment says so.npm test: 345 passed, 3 skipped, 337 snapshots.🤖 Generated with Claude Code