Sign and verify identity tokens through the JWT package's HMAC implementation - #8
Merged
Conversation
…entation `Identity Shared` declared its own `SigningKey` and `VerificationKey`, which shadowed the types of the same name vended by the `JWT` module and stood in for them throughout the token layer. Those declarations, the local `JWT.signed` and `verifyAndValidate` extensions, `JWTError` and `String.hmacSHA256` are removed; the token layer now uses the `JWT` package's swift-crypto-backed key types, `SigningAlgorithm` and signing and verification entry points. Adds `Identity.Token.Signing`, which names the one algorithm identity tokens are issued under and routes verification through it. Issuing and verification both pass that algorithm explicitly, so the `alg` header of a presented token is compared against it rather than selecting the verifier. Access, refresh, reauthorization and MFA challenge tokens take their throws clauses to `RFC_7519.Error` or their own nested `TokenError`, per the typed throws rule. Adds a suite covering the rejection paths at the identity-token layer: a token signed with a different key, a replaced signature, a payload or expiry changed after signing, a token declaring an unexpected algorithm, and a token presented to `Identity.Token.Client` under another key. Requires swift-foundations/swift-json-web-token#6. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Guards the signing path itself: a signing implementation that returned its input unchanged would satisfy every existing rejection test, since verification would still be consistent with it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
What changes
The token layer uses the
JWTpackage directly —SigningKey.symmetric(string:),VerificationKey.symmetric(string:),SigningAlgorithm, andJWT.signed/verify/verifyAndValidate.Sources/Identity Shared/JWT+Extensions.swift, which declared localSigningKey,VerificationKey,JWTErrorandString.hmacSHA256, is removed.New
Identity.Token.Signingnames the single algorithm identity tokens are issued under (HS256) and routes verification through it. Issuing and verification both pass that algorithm explicitly.Typed throws. Access, refresh, reauthorization and MFA challenge tokens move from bare
throwstothrows(RFC_7519.Error)for the issuing paths and thetokengetters, andthrows(TokenError)forinit(jwt:).Tests
New
Token Signing Testssuite covering the rejection paths across all four token kinds andIdentity.Token.Client. ExistingIdentity Shared Testsare updated for the key constructors.swift buildandswift testare green — 51 tests in 9 suites, plus 10 in 3 suites in the router parity target.Dependency
Requires swift-foundations/swift-json-web-token#6, which adds the required
algorithm:parameter to the verification entry points. Verified against that PR's head; merges after it.Two unrelated pre-existing breaks in the dependency graph were worked around locally to get a build:
swift-json(fixed on its main) andswift-faviconFavicon.Head.swift, which needsimport FoundationforabsoluteStringunderMemberImportVisibility. Neither is touched here.🤖 Generated with Claude Code