Repository navigation
Keep logout from being undone by an in-flight JWT refresh; tighten docs - #22
Merged
Merged
Conversation
JWTAuth committed a refresh's tokens even when setTokens(_:) or clearTokens() had replaced them while the refresh was in flight, and persisted them through onTokensUpdated. A logout during a refresh could silently sign the user back in. With several requests sharing one refresh, a later waiter could also restore tokens after a logout that landed between waiters resuming. A refresh now commits only while it is still the pending refresh, so the first waiter commits once and a superseded refresh never does. A superseded refresh does not call onTokensUpdated or onRefreshFailed. Requests waiting on it continue with the current tokens, or fail with notAuthenticated after a logout. A persistence callback that has already started cannot be revoked, and the docs now say so. Also: - An empty JWTAuth tokenPrefix sends the bare token, with no leading space. - Fold EnvironmentType.swift into Server.swift and remove the internal sample ApiServer/TestEndpoint types that shipped in the library. - Document that credentials are bound to an environment, and how to pair per-request environment and auth. - Fix the Mocking guide: remove the nonexistent continuation.endpoint, fix non-Sendable examples, and describe the resume() swizzling accurately. - Document the environment/auth parameters on every request method, and fix DocC warnings.
- README: shorter, with installation up front, a single getting-started path, accurate requirements and migration notes from 0.4, and working links. The wiki it linked to doesn't exist. - DocC: new Authentication article. Examples now compile: they use ParameterComponents/HeaderComponents, the real multipart types, and the correct errorResponse pattern. Mocking documents the actual behavior of .fail and .none, typed-error matching inside withMock, a URLProtocol example for testing refresh, and building requests without sending them. - Doc comments: document every public enum case, fix comments that described the wrong encoder or decoder, and use American spelling. Drop filler and em-dashes. The README and guide examples were compiled and run against the library before committing. The only non-comment change is the wording of a debug assertion message.
The Documentation workflow had failed on every run since the release trigger was added, so the hosted docs were from 2024. It also built only the Endpoints module. .spi.yml asks the Swift Package Index to build and host docs for both Endpoints and EndpointsMocking on each release. EndpointsMocking gets a landing page, and its doc comments no longer link to types in the other module, which separately built archives can't resolve. The README badges and documentation link now point to the index.
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.
Bug fix
JWTAuthcommitted a refresh's tokens even whensetTokens(_:)orclearTokens()had replaced them while the refresh was in flight. It also persisted those tokens throughonTokensUpdated. A logout during a refresh could silently sign the user back in, and a new login could be overwritten by stale refreshed tokens. With several requests sharing one refresh, a later waiter could also restore tokens after a logout that landed between two waiters resuming.A refresh now commits only while it is still the pending refresh. The first waiter commits once, and a superseded refresh never commits. A superseded refresh calls neither
onTokensUpdatednoronRefreshFailed. Requests waiting on it continue with the current tokens, or fail with.notAuthenticatedafter a logout.Known limit, now documented: a persistence callback that has already started cannot be revoked. If a logout lands while
onTokensUpdatedis still writing, the write can finish after the logout. Apps that need a hard guarantee should have their store reject writes from a signed-out session.Other changes
JWTAuth.Configuration.tokenPrefixsends the bare token instead of a leading space.EnvironmentType.swiftis folded intoServer.swift. The internal sampleApiServer/TestEndpointtypes that shipped inside the library are removed. There is no public API change.static let authsuits single-environment apps. Multi-environment apps should pass matchingauth:per request.continuation.endpoint.Sendable-safe.environment:andauth:parameters are documented on every request method. DocC builds with no warnings.Documentation pass
.failand.none, typed-error matching insidewithMock, aURLProtocolstub for testing refresh, and building requests without sending them.The README and guide examples were compiled and run against the library. DocC builds with no warnings.
Documentation hosting
The Documentation workflow is removed. It had failed on every run since its trigger moved to releases, because the
github-pagesenvironment only allowed deploys frommain. As a result, velosmobile.com/Endpoints still shows docs from 2024. A new.spi.ymlasks the Swift Package Index to build and host docs for bothEndpointsandEndpointsMockingon each release. I checked that both modules build the way the index builds them, with no warnings. The README badges and documentation link now point to the index. The package still needs to be submitted to the index before those links work.Testing
swift testpasses on macOS across repeated runs.JWTAuthSupersededRefreshTestscover these scenarios: