- Swift 100%
ATProto OAuth #
An app can let someone read public records without signing in. When they choose an action that needs their account, it asks for the declared permission, opens the authorization page, receives the callback, and resumes with a DPoP-bound session. A request that requires authorization fails closed if that session is missing, belongs to another account, or lacks permission. An optional request can continue anonymously without prompting.
Try the complete local-browser flow from this package directory:
swift run atproto-login-example alice.example.com
swift run atproto-login-example --url-only did:plc:your-account-id
The example binds a loopback callback, opens the authorization page (or prints its URL for a browser on the same computer), and prints only the authenticated DID. It keeps the returned session in memory and exits. An app must supply its own OAuth manifest, callback routing, saved session store, and account selection.
For a signed-in account, the live server client uses the configured default
OAuth session for getSession. Configure the app manifest and session
dependencies at launch, then call:
import ATProto
import ATProtoOAuth
import Dependencies
@Dependency(ATProto.Server.Client.self) var serverClient
let currentAccount = try await serverClient.getSession()
This request throws if authentication cannot be satisfied.
serverClient.describeServer("pds.example.com") remains a public call.
The caller owns the saved OAuth.SessionStore and selected account. OAuth
handles discovery, PAR, PKCE, DPoP, refresh, permission checks, and the XRPC
authorization gate. Its live ATProto.Server.Client uses the current
authenticated session for getSession; describeServer stays public.
Source and tests follow the same Configuration, Authorization, and
Sessions folders. The CLI listener and example remain separate targets.
ATProtoOAuth does not link Sharing by default. Enable the Sharing
trait to use KeychainSharedKey and the Shared DPoP nonce adapter. The
underlying KeychainStorageClient is available in either configuration.
SwiftPM may still resolve the declared swift-sharing package when the
trait is off.
ATProtoOAuthCLI and atproto-login-example remain explicit targets. The
CLI opens a local callback listener and returns a session; it does not save or
select it. The example prints only the authenticated DID.
Development and release status #
Use Swift 6.4 (Xcode 27 on macOS) for the current dependency graph, even though this package's manifest declares Swift tools 6.3. Run from this package directory:
swift test --build-system native
swift test --build-system native --enable-all-traits
This is a branch-publication candidate; no version tag has been published.
After the reviewed candidate is pushed, consume its remote main branch:
.package(url: "https://tangled.org/woody.fm/swift-atproto-oauth", branch: "main")
The graph uses prerelease Point-Free branches. Consumers and CI need access to any private upstream dependencies selected by their graph, including TCA26 for the server package and Composable Atmosphere. Private upstream source is not included in this repository.
The planned 0.1.0 release follows TCA 2 and compatible versioned requirements
throughout the dependency graph. Existing version tags will not be moved.
See source provenance for the frozen integration revision.