SDK
Swift SDK
Authon (Swift) — AuthonClient, ASWebAuthenticationSession 기반 OAuth, 네이티브 Sign in with Apple, Keychain 토큰 저장소를 제공하는 iOS/macOS SDK입니다.
설치
Package.swift
dependencies: [
.package(url: "https://github.com/mikusnuz/authon-sdk.git", from: "0.1.0")
]초기화
Authon.swift
import Authon
let authon = AuthonClient(publishableKey: "pk_live_...")OAuth 로그인
LoginViewModel.swift
let user = try await authon.signIn(with: .google)
let authonAccessToken = try await authon.getToken()
// If your app also has its own backend session, exchange authonAccessToken here.SwiftUI
ContentView.swift
import SwiftUI
import Authon
struct ContentView: View {
@StateObject private var auth = AuthonObservable(publishableKey: "pk_live_...")
var body: some View {
Group {
if auth.isLoading {
ProgressView()
} else if let user = auth.user {
VStack {
Text("Welcome, \(user.displayName ?? user.email ?? "User")")
Button("Sign Out") {
Task { try await auth.signOut() }
}
}
} else {
VStack {
Button("Sign in with Google") {
Task { try await auth.signIn(with: .google) }
}
Button("Sign in with Apple") {
Task { try await auth.signIn(with: .apple) }
}
}
}
}
}
}중요한 주의사항
- 네이티브 Swift SDK는 `ASWebAuthenticationSession`을 내부에서 처리합니다. 이 SDK를 직접 쓸 때는 Expo / React Native용 `returnTo` 브리지 플로우가 필요하지 않습니다.
- 앱이 자체 백엔드 세션도 운영한다면 로그인 직후 `try await authon.getToken()`을 백엔드에 전달해 자체 세션을 발급받으세요.
- Expo나 React Native 앱이라면 Swift 플로우가 아니라 React Native SDK 가이드를 따라야 합니다.