原因:SZSAuthManager 被弃用是为了专注于特定于提供商的身份验证解决方案,从而可以更深入地集成每个提供商的独特功能。 这种方法简化了维护,降低了复杂性,并可以更有效地更新针对各个身份验证服务量身定制的内容。
SZSAuthManager 是一个适用于 Swift 应用程序的灵活的身份验证管理系统。 它支持多个身份验证提供商,并为常见的身份验证操作提供统一的接口。
将以下内容添加到您的 Package.swift
文件
dependencies: [
.package(url: "https://github.com/assad62/SZSAuthManager.git", from: "1.0.0")
]
使用 Builder 模式创建 SZSAuthManager 的实例
import SZSAuth
func readGoogleServiceInfo() -> [String: Any]? {
guard let plistPath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"),
let plistContent = NSDictionary(contentsOfFile: plistPath) as? [String: Any] else {
print("Failed to read GoogleService-Info.plist")
return nil
}
return plistContent
}
let firebaseConfig = FirebaseConfig(plistContent: readGoogleServiceInfo()!)
let authManager = SZSAuthManager.Builder(authProvider: .firebase)
.setFirebaseConfig(firebaseConfig)
.build()
authManager.signIn(email: "user@example.com", password: "password")
.sink(receiveCompletion: { completion in
switch completion {
case .finished:
print("Sign in completed")
case .failure(let error):
print("Sign in failed: \(error)")
}
}, receiveValue: { user in
print("Signed in user: \(user)")
})
.store(in: &cancellables)
authManager.signUp(email: "newuser@example.com", password: "password", name: "New User")
.sink(receiveCompletion: { completion in
// Handle completion
}, receiveValue: { user in
print("Signed up user: \(user)")
})
.store(in: &cancellables)
authManager.signOut()
.sink(receiveCompletion: { completion in
// Handle completion
}, receiveValue: {
print("User signed out")
})
.store(in: &cancellables)
authManager.getCurrentUser()
.sink(receiveValue: { user in
if let user = user {
print("Current user: \(user)")
} else {
print("No user is currently signed in")
}
})
.store(in: &cancellables)
authManager.sendVerificationEmail()
.sink(receiveCompletion: { completion in
switch completion {
case .finished:
print("Verification email sent successfully")
case .failure(let error):
print("Failed to send verification email: \(error)")
}
}, receiveValue: { _ in })
.store(in: &cancellables)
authManager.deleteUser()
.sink(receiveCompletion: { completion in
// Handle completion
}, receiveValue: {
print("User account deleted")
})
.store(in: &cancellables)
SZSAuthManager 在以下场景中特别有用
多平台应用程序:在 iOS、macOS 和 tvOS 上提供一致的身份验证接口。
白标应用程序:轻松切换不同品牌版本的应用程序的身份验证提供商。
在身份验证提供商之间转换:逐渐从一个身份验证系统迁移到另一个身份验证系统。
具有多种身份验证方法的应用程序:抽象出各种身份验证方法之间的差异。
测试和开发:创建模拟身份验证服务以进行测试或本地开发。
要使用不同的提供商,请在创建 SZSAuthManager 时更改 authProvider
参数,并提供相应的配置。
要添加自定义身份验证提供商
AuthProvider
枚举中创建一个新的 case。AuthService
,使其符合 AuthService
协议。SZSAuthManager.Builder
以处理新的提供商。[在此处添加您的许可信息]
[添加支持信息,例如如何报告问题或在哪里提问]