Skip to content

feat(util): add authType derived from the request identity - #296

Open
bentsku wants to merge 1 commit into
mainfrom
aws-1680-appsync-authtype-from-identity
Open

feat(util): add authType derived from the request identity#296
bentsku wants to merge 1 commit into
mainfrom
aws-1680-appsync-authtype-from-identity

Conversation

@bentsku

@bentsku bentsku commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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 "" under EvaluateCode where AWS returns an auth mode.

What this does

util.authType() derives the mode from ctx.identity, which AppSync shapes per authorization mode. A host installs the request with a new setResolverContext export immediately before calling the resolver.

Recorded from EvaluateCode over 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:

mode key set required
Lambda Authorization resolverContext none
IAM Authorization accountId, sourceIp, username, userArn, cognitoIdentityPoolId, cognitoIdentityId, cognitoIdentityAuthType, cognitoIdentityAuthProvider the first four
User Pool Authorization sourceIp, username, groups, sub, issuer, claims, defaultAuthStrategy all but groups
Open ID Connect Authorization sub, issuer, claims all three

Anything 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 a checkValid case. A separate block asserts the setResolverContext seam with plain expect; those are not compared against AWS and the comment says so.

npm test: 345 passed, 3 skipped, 337 snapshots.

🤖 Generated with Claude Code

`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
bentsku force-pushed the aws-1680-appsync-authtype-from-identity branch from e68214e to ccc0620 Compare September 2, 2026 20:46
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.

1 participant