SDK
Swift SDK
AuthonSwift — 네이티브 Sign in with Apple, OAuth를 위한 ASWebAuthenticationSession, Keychain 토큰 저장소를 갖춘 iOS/macOS SDK.
설치
Xcode에서 Swift Package Manager를 통해 추가:
Package.swift
dependencies: [
.package(url: "https://github.com/mikusnuz/authon-swift", from: "1.0.0")
]설정
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 사용법
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 로그인
swift
// Sign in with Google via ASWebAuthenticationSession
try await Authon.shared.signInWithOAuth(provider: "google")
// Sign in with Apple (native)
try await Authon.shared.signInWithApple()