在 Swift 中一行代码获取 Google 身份验证器导出数据链接 otpauth-migration://offline?data=
中的所有数据。
您可以使用 Swift Package Manager,并在 Package.swift
中通过添加以下内容来指定依赖项
dependencies: [
.package(url: "https://github.com/svyatoynick/GAuthSwiftParser.git", .upToNextMajor(from: "1.0.0"))
]
要通过 CocoaPods 安装,只需将以下行添加到您的 Podfile
pod 'GAuthSwiftParser'
然后在项目目录中运行 pod install
以安装。
在开始之前,您需要从 QR 码获取链接,以导出 Google 身份验证器数据,格式为:otpauth-migration://offline?data=YourData
之后,我们通过 getAccounts(code: String)
函数从此链接获取数据
// This is an example code, replace it with your own
let code = "otpauth-migration://offline?data=CiAKCkhlbGxvQp6tvu8SBEFsZXgaBkFtYXpvbiABKAEwAgogCgocIRIITUedUv2HEgRNYXJ5GgZHb29nbGUgASgBMAIKHwoKGekSCE1H3VL9hxIFRGFyeWEaBExvdmUgASgBMAIQARgBIAA%3D"
let data = GAuthSwiftParser.getAccounts(code: code)
之后,您可以使用 data
,这是一个 AccountModel
类的数组,其中包含 3 个参数:name
、issuer
和 secret
。 getLink()
函数也可用,您可以通过它从接收到的数据中获取 OTP 链接。
GAuthSwiftParser 基于 MIT 许可证发布。有关更多信息,请参见 LICENSE 文件。
GAuthSwiftParser 依赖于以下开源项目