feat(mobile): ios oauth & magic-link login (#8581)

Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
Cats Juice
2024-10-28 14:12:33 +08:00
committed by GitHub
parent d6ec4cc597
commit 06dda70319
59 changed files with 929 additions and 219 deletions

View File

@@ -8,4 +8,8 @@ class AFFiNEViewController: CAPBridgeViewController {
webView?.allowsBackForwardNavigationGestures = true
}
override func capacitorDidLoad() {
bridge?.registerPluginInstance(CookiePlugin())
}
}

View File

@@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
@@ -20,8 +18,23 @@
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>CFBundleURLName</key>
<string>affine</string>
<key>CFBundleURLSchemes</key>
<array>
<string>affine</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>10</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchScreen</key>

View File

@@ -0,0 +1,30 @@
import Foundation
import UIKit
public class CookieManager: NSObject {
public func getCookies(_ urlString: String) -> [String: String] {
var cookiesMap: [String: String] = [:]
let jar = HTTPCookieStorage.shared
guard let url = getServerUrl(urlString) else { return [:] }
if let cookies = jar.cookies(for: url) {
for cookie in cookies {
cookiesMap[cookie.name] = cookie.value
}
}
return cookiesMap
}
private func isUrlSanitized(_ urlString: String) -> Bool {
return urlString.hasPrefix("http://") || urlString.hasPrefix("https://")
}
public func getServerUrl(_ urlString: String) -> URL? {
let validUrlString = (isUrlSanitized(urlString)) ? urlString : "http://\(urlString)"
guard let url = URL(string: validUrlString) else {
return nil
}
return url
}
}

View File

@@ -0,0 +1,21 @@
import Foundation
import Capacitor
@objc(CookiePlugin)
public class CookiePlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "CookiePlugin"
public let jsName = "Cookie"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "getCookies", returnType: CAPPluginReturnPromise)
]
let cookieManager = CookieManager()
@objc public func getCookies(_ call: CAPPluginCall) {
guard let url = call.getString("url") else {
return call.resolve([:])
}
call.resolve(cookieManager.getCookies(url))
}
}