SDK
Swift SDK
AuthonSwift — iOS/macOS SDK with native Sign in with Apple, ASWebAuthenticationSession for OAuth, and Keychain token storage.
Installation
Add via Swift Package Manager in Xcode:
Package.swift
dependencies: [
.package(url: "https://github.com/mikusnuz/authon-swift", from: "1.0.0")
]Setup
AuthonApp.swift
import SwiftUI
import AuthonSwift
@main
struct AuthonApp: App {
init() {
Authon.configure(
publishableKey: "pk_live_your_key",
redirectScheme: "myapp"
)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}SwiftUI Usage
ContentView.swift
import SwiftUI
import AuthonSwift
struct ContentView: View {
@StateObject private var auth = AuthonState.shared
var body: some View {
Group {
if auth.isLoading {
ProgressView()
} else if auth.isSignedIn {
VStack {
Text("Welcome, \(auth.user?.displayName ?? "")!")
Button("Sign out") {
Task { await Authon.shared.signOut() }
}
}
} else {
Button("Sign in") {
Task { await Authon.shared.openSignIn() }
}
}
}
}
}OAuth Sign In
swift
// Sign in with Google via ASWebAuthenticationSession
try await Authon.shared.signInWithOAuth(provider: "google")
// Sign in with Apple (native)
try await Authon.shared.signInWithApple()