Repository navigation
Releases
1.1.0
This release renames the main objects so that each one says which OAuth party it talks to (ADR 0016):
OAuthClient for the authorization server, OAuthSession for the signed-in user and ProtectedResourceClient for
the protected resource. The renames break source compatibility in a minor release. This is a deliberate exception to
the promise of 1.0.0, made while the library has no known consumers, and no deprecated aliases are kept. Protocol
behaviour and the format of stored credentials are unchanged, so signed-in users stay signed in after the update.
Added
CredentialStorelists its built-in stores as static members, sostore: .keychain()andstore: .inMemory()
appear in autocomplete. They take the parameters of theKeychainCredentialStoreandInMemoryCredentialStore
initializers.- Documentation of what signing in and out leave at the server:
OAuthSession.signIn(with:requestedScope:)adopts
tokens and authenticates nobody, andsignOut(revoke:)leaves the person signed in at the authorization server.
The session article and the spec name an ephemeral browser session as the only control the client enforces, and
say thatprompt=login(OpenID Connect Core §3.1.2.1) is a request that the server may ignore.
Changed
- Breaking:
TokenManagerisOAuthSession, so the two entry pointsOAuthClientandOAuthSessionappear
together in autocomplete.load()isrestore().invalidate(_:)isdiscard(_:), because it drops a cached
token and sends nothing to the server. - Breaking: the types that belong to the session are nested in it.
SessionEventisOAuthSession.Event, and
SignOutReason,SignOutResultandPendingSignOutareOAuthSession.SignOutReason,
OAuthSession.SignOutResultandOAuthSession.PendingSignOut. - Breaking: the event
refreshed(target:)isaccessTokenUpdated(target:), because a token exchange emits it
too. Its documentation states that the session caches the token only when its lifetime is known, and that a
sign-in andexchangeRefreshTokendo not emit it. - Breaking:
CredentialCoding.encode(_:)andCredentialCoding.decode(_:)areCredential.serializedData()
andCredential(serializedData:). The record format and its version are unchanged, so credentials stored by 1.0
stay readable. - Breaking:
RequestAuthorizerisProtectedResourceClient, because it talks to a protected resource (RFC 6749
§1.1) and "authorize" names the sign-in flow. Its initializer takessession:instead ofmanager:.
sign(_:for:)isaddingToken(to:for:), because a bearer token is not a signature.
data(for:target:session:)isdata(for:target:urlSession:), because "session" means the OAuth session.
RetryDecisionisProtectedResourceClient.RetryDecision. - Breaking:
PassportObserverisRequestObserverandPassportEventisRequestEvent, because the events
report requests and thePassportprefix said only which library they come from.EndpointKindis
RequestEvent.Endpoint.PassportErroris the only type left with the library prefix.
Removed
- Breaking:
EndpointKind.resource. No code emitted it, so an observer never received it.
1.0.1
Fixed
- An app that depends on PassportKit through Xcode can build it again.
Package.swifttreated all warnings as errors,
which Xcode combines with the-suppress-warningsit uses for remote packages and then refuses ("conflicting options
'-warnings-as-errors' and '-suppress-warnings'"). Warnings are now errors only in this repository's ownmake
targets.
1.0.0
The first stable release: from here on, a breaking change to the public API of PassportKit or PassportKitTesting
needs a new major version.
Added
OAuthClient.revokeBestEffort(_:typeHint:timeLimit:)revokes a token best effort (RFC 7009) and returns a
RevocationOutcomeinstead of throwing:revoked,failed,timedOutafter the limit on the client's clock,
cancelled, orskippedwithout a revocation endpoint. It is for a token that never became a session, such as a
refresh token the app obtained but did not adopt. The limit defaults toOAuthClient.revocationTimeLimit(5
seconds), the limitTokenManagerapplies on sign-out, so apps need not copy it.TokenManager.beginSignOut(revoke:)clears the session without suspending and returns aPendingSignOut, whose
result(get async, likeTask.value) waits for the store delete and the revocation (RFC 7009) and returns the
SignOutResult. Apps no longer need to watch for.signedOut(.userInitiated)to learn that the session is gone
(ADR 0014).
Changed
- Breaking:
OAuthClient.beginAuthorization(_:)throws.invalidConfigurationwhenpromptcombines
.noInteraction(none) with another value, which OpenID Connect Core §3.1.2.1 forbids. Such a request used to be
sent. - Breaking:
LoopbackRedirectListener.waitForCallback(timeout:accept:)iswaitForCallback(timeLimit:accept:)
andLoopbackUserAgent(listener:timeout:openURL:)isLoopbackUserAgent(listener:timeLimit:openURL:), matching
thetimeLimitof the other APIs that give up after a duration on the injected clock. - Breaking: the members of
PassportError(code,recovery,statusCode,errorURI,underlying) are
read-only outside the library, likedetailalready was. Create an error with the initializers instead of
changing one. - Breaking:
SignOutResult.Revocationis the top-levelRevocationOutcome, shared by sign-out and
OAuthClient.revokeBestEffort(_:typeHint:timeLimit:);SignOutResult.revocationhas that type. Its cases are
unchanged. - Breaking:
TokenManager.exchangeRefreshTokenreturns the response when the server answered, even if the
session ended or was replaced while the request was in flight; it used to throw.notAuthenticatedand drop the
issued token, which stayed valid at the server. The rotated subject still goes to the ended session's revocation
and the new session is not touched. Callers that must not use a token of an ended session check their own state
and revoke it as the audience client (ADR 0015). - Breaking: the response of
TokenManager.exchangeRefreshTokenhasrefreshTokenset tonil. The rotated
refresh token belongs to the session, which saves it; handing it out invited presenting it twice. TokenManager.signOut(revoke:)isbeginSignOut(revoke:)followed byawait result. The revocation's time
limit and its log line now run in a task the manager owns, so a revocation outcome is logged even when the caller
ofsignOutwas cancelled. Results are unchanged.- Every public enumeration states whether it is frozen.
TokenAcceptanceandJSONValueare frozen;PassportEvent,
IssuerValidation,Discovery.Style,KeychainCredentialStore.Accessibilityand the enumerations of
PassportKitTestingmay gain cases in a minor release, so aswitchover them needs adefault.
Removed
- Breaking:
Credential.additionalFieldsand the matching initializer parameter. Nothing in the library set or
read it, andTokenManageroffered no way to fill it. Stored records that carry the field still decode; the field
is ignored.
Fixed
- A
Retry-Afterin the obsolete RFC 850 date form with a two-digit year up to 50 years ahead is read as a future
date (RFC 9110 §5.6.7); years 46 to 76 used to be read as the 20th century, which made the delay zero. LoopbackUserAgentinstalls itsstatefilter before it opens the browser, so a request with anotherstate
that reaches the listener while the browser opens is refused instead of being taken as the redirect.TokenManager.load()reads the store only after every save and delete decided before it, so a load that runs
while the delete of a signed-out or rejected session is still in progress no longer restores that session.KeychainCredentialStoreupdates an existing item in place instead of deleting it and adding it again, so a save
that fails (device locked, denied prompt) or a process that dies mid-save no longer loses the stored credential,
and stores writing the same item at once no longer fail witherrSecDuplicateItem. A save whose payload could not
be archived fails with.storageFailureinstead of storing an item without data.KeychainCredentialStorefinds, replaces and deletes its item by class, service, account and access group, never
by accessibility class. An app that changesaccessibilitykeeps its stored credential (on iOS it was no longer
found), and the next save moves the item to the new class.- The documentation of
RequestAuthorizer.sign(_:for:)forHTTPRequestand ofURLSessionTransportstates that
the never-indexed marking ofAuthorization(RFC 7541 §7.1.3) reaches the wire only through a transport that keeps
the indexing strategy ofHTTPFields.URLSessionTransportconverts toURLRequest, which drops it. DeviceAuthorization.expiresAtkeeps the fractional part of a fractionalexpires_ininstead of truncating it to
whole seconds.
0.3.2
Changed
- Expected failures are logged at
.noticeinstead of.warning, so apps that forward.infoand above to remote
logging no longer report them: a request to the authorization server that failed for lack of connectivity (offline,
timeout, DNS), a revocation on sign-out that failed that way or timed out, and a renewed access token that the
resource rejects again. Other transport failures (TLS, certificates, refused redirects, oversized responses) and
revocations refused by the server stay at.warning. Messages and metadata are unchanged.
0.3.1
Fixed
PassportKitTesting: a token exchange with a refresh token subject,requested_token_typerefresh token and an
audiencethat names a registered client issued the refresh token for the requesting client inside the requester's
own grant. It is now issued for the audience client in a new grant with its own rotation chain, lifetimes and
rotation settings, so that client can redeem it, other clients getinvalid_grant, and revoking either chain does
not revoke the other. An audience that is not a registered client behaves as before, and a registered audience
client without the refresh token grant getsinvalid_target.
0.3.0
Changed
- Breaking (security, #1): endpoints are
httpsonly. Plainhttpon a loopback host (localhost,127.0.0.1,
::1) is no longer accepted for the authorization, token, device authorization and revocation endpoints, the issuer,
the discovery URL, the endpoints in fetched metadata, device verification URIs and the resource URLs of
RequestAuthorizer. Local development servers need the new opt-in
ClientConfiguration.allowsInsecureLoopbackEndpoints, which is also a parameter of
Discovery.fetchMetadata(issuer:…),Endpoints.init(metadata:)andClientConfiguration.init(metadata:…)(all
defaultfalse). A non-loopbackhttpURL is refused even with it. Violations throwinvalidConfigurationand the
message names the opt-in.httploopback redirect URIs (RFC 8252 §7.3) are unaffected. See ADR 0012. - Breaking (security, #2): the authorization code flow requires
ClientConfiguration.issuer.
beginAuthorization(_:),authorize(_:using:)andcompleteAuthorization(_:callbackURL:additionalParameters:)
throwinvalidConfiguration, before any request, when it isnil. Before, a responseisswas accepted unchecked
without a configured issuer. Comparison stays exact (RFC 9207 §2.4), and
requiresIssuerInAuthorizationResponsestill followsauthorization_response_iss_parameter_supportedwhen the
configuration comes from metadata. Servers without RFC 9207 need another mix-up defence, such as a distinct redirect
URI per authorization server; the device flow is not affected. See ADR 0013.
0.2.0
Upgrading from 0.1.0: macOS 14 and iOS 17 are the only supported platforms, KeychainCredentialStore.init(decodeLegacy:)
is gone, and the ManualClock waits in PassportKitTesting throw. See the Breaking entries.
Added
TokenManager.signIn(refreshToken:grantedScope:idToken:) async throwsstarts a session from a refresh token the app
already holds, for example the oneexchangeRefreshToken(audiences:)issued for another client, or one read from
the storage of a previous OAuth library. LikesignIn(with:requestedScope:)it replaces the session, saves the
credential and emits.signedIn, but it caches no access token: the firstaccessToken(for:)refreshes. It throws
invalidConfigurationfor an empty token and then leaves the current session untouched.- A DocC article, "Migrating stored tokens", on moving users from another OAuth library without signing them out: read
the old refresh token, callsignIn(refreshToken:)under a new account, delete the old item once a token request
succeeded. ManualClock.WaitTimeout, thrown by the waits ofManualClock(see Changed).- Documentation of exact scope matching:
RequireAnyScopeand the resource access article state that scopes are
compared as exact strings and*is not a wildcard, with a compiled.custompolicy that accepts a scope prefix. - A release workflow: pushing a version tag runs the CI workflow (now also callable with
workflow_call) and, only if
every job passes, creates the GitHub release with the tag's changelog section as notes. The procedure is in
CONTRIBUTING.md.
Changed
- Breaking (
PassportKitTesting):ManualClock.waitForSleeper()andManualClock.advanceToNextSleeper()are
throws; call them withtry await. When no task sleeps within 60 seconds of real time (it was 10 seconds) they
throwManualClock.WaitTimeoutinstead of stopping the whole test process, so a slow wake-up on a loaded machine
fails only the waiting test. The wait is resumed by the sleeper that arrives instead of polling.
waitForSleeper(timeout:)is unchanged. TokenManager.init: the default ofrejectedTokenCacheDurationis 5 seconds (it was 30). The window only has to
absorb tight retry loops, which would otherwise rotate the refresh token on every attempt; a long one makes a
permission that was just granted look denied. Pass.seconds(30)to keep the old behaviour.- The iOS test job boots the simulator first, prints the full test output and uploads the result bundle when it
fails.
Removed
- Breaking:
KeychainCredentialStore.init(decodeLegacy:)and the migration code behind it. The store reads and
writes only its own format, and an item it cannot decode is a.storageFailure. An app migrates by reading its old
storage itself and callingTokenManager.signIn(refreshToken:grantedScope:idToken:). This also removes the
write-back, which replaced the migrated item by deleting and adding it and could lose it. Items written directly as
the record JSON by builds before 0.1.0 are no longer read. - Breaking: tvOS, watchOS and visionOS are no longer supported.
Package.swiftdeclares macOS 14 and iOS 17 only,
and the platform guards that existed for the other three are gone:WebAuthenticationSessionUserAgent,
LoopbackRedirectListenerandLoopbackUserAgentexist on both supported platforms (ADR 0011, Update).
Fixed
KeychainCredentialStore.deletematches the item by service, account and access group only. It no longer carries
the accessibility class, so an item stored with another class is removed on sign-out, and it no longer matches items
of other access groups.- The documentation of
KeychainCredentialStore,KeychainCredentialStore.Accessibilityand the security model said
accessibility classes and access groups protect the item. On macOS the store uses the file-based login keychain,
which enforces neither; they apply on iOS.
Security
KeychainCredentialStoresetskSecAttrSynchronizabletofalseexplicitly when it adds, fetches and deletes an
item, instead of relying on the default, so a credential never reaches iCloud Keychain. Items written before are
found as before.
0.1.0
First release of PassportKit, an OAuth 2.0 client library for Apple platforms (macOS 14, iOS 17, tvOS 17, watchOS 10, visionOS 1).
Highlights
- Grants: authorization code with PKCE (RFC 7636, RFC 9207
iss), device authorization (RFC 8628), refresh, client credentials, token exchange (RFC 8693) with resource indicators (RFC 8707), revocation (RFC 7009), metadata discovery (RFC 8414). TokenManager: one session per app with refresh-token rotation handled safely (single refresh lane, persist before use, coalesced requests), token targets for resource-bound tokens, and an acceptance policy that turns "200 with narrowed scope" into.resourceDeniedwithout signing the user out.RequestAuthorizer: bearer signing with one 401 retry.- Keychain storage,
ASWebAuthenticationSessionand loopback redirect user agents. PassportKitTesting: a fake authorization server and manual clocks for your own tests.- Logging through swift-log; secrets are redacted everywhere.
The API may change in 0.x releases. See CHANGELOG.md for details and known limitations (docs/security-model.md, "Known limits").