Skip to content

Sign and verify identity tokens through the JWT package's HMAC implementation - #8

Merged
coenttb merged 2 commits into
mainfrom
token-hmac-signing
Jul 28, 2026
Merged

Sign and verify identity tokens through the JWT package's HMAC implementation#8
coenttb merged 2 commits into
mainfrom
token-hmac-signing

Conversation

@coenttb

@coenttb coenttb commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

What changes

The token layer uses the JWT package directly — SigningKey.symmetric(string:), VerificationKey.symmetric(string:), SigningAlgorithm, and JWT.signed / verify / verifyAndValidate. Sources/Identity Shared/JWT+Extensions.swift, which declared local SigningKey, VerificationKey, JWTError and String.hmacSHA256, is removed.

New Identity.Token.Signing names 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 throws to throws(RFC_7519.Error) for the issuing paths and the token getters, and throws(TokenError) for init(jwt:).

Tests

New Token Signing Tests suite covering the rejection paths across all four token kinds and Identity.Token.Client. Existing Identity Shared Tests are updated for the key constructors.

swift build and swift test are 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) and swift-favicon Favicon.Head.swift, which needs import Foundation for absoluteString under MemberImportVisibility. Neither is touched here.

🤖 Generated with Claude Code

coenttb and others added 2 commits July 28, 2026 15:12
…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>
@coenttb
coenttb merged commit 678043d into main Jul 28, 2026
15 of 20 checks passed
@coenttb
coenttb deleted the token-hmac-signing branch July 28, 2026 14:09
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