-
-
Notifications
You must be signed in to change notification settings - Fork 890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Login v2 #2908
Enable Login v2 #2908
Changes from 3 commits
45454db
e0563bc
d8b1e53
b705120
7315858
498882e
dbfb2f2
33feeaf
c1eb3b0
eb75e20
90ce7e5
1edaba3
2fcd32a
e68f305
4d3b6b2
8d0e157
fbb8fb3
e57151a
077e5d2
aa1d335
de1b1d2
99f1e2d
768970f
e6e9734
8de1a2d
7d9ab9f
33e6f39
6d776a5
86ccf8a
d560133
b86242c
e87f4a1
b01a8bb
91b5322
3365b4c
527cb47
0b68beb
ce53ed7
7289bf1
d3e2781
d1be553
b3dd8ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,9 @@ class NCLoginWeb: UIViewController { | |
var loginFlowV2Endpoint = "" | ||
var loginFlowV2Login = "" | ||
|
||
// Opens the login URL in external browser instead of in app. User must manually go back to the app. | ||
let loginFlowv2ExternalBrowser = false | ||
|
||
// MARK: - View Life Cycle | ||
|
||
override func viewDidLoad() { | ||
|
@@ -145,6 +148,8 @@ class NCLoginWeb: UIViewController { | |
} | ||
} | ||
self.title = titleView | ||
|
||
NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil) | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
|
@@ -169,21 +174,32 @@ class NCLoginWeb: UIViewController { | |
} | ||
|
||
func loadWebPage(webView: WKWebView, url: URL) { | ||
if loginFlowV2Available, loginFlowv2ExternalBrowser { | ||
UIApplication.shared.open(url) | ||
} else { | ||
let language = NSLocale.preferredLanguages[0] as String | ||
var request = URLRequest(url: url) | ||
|
||
let language = NSLocale.preferredLanguages[0] as String | ||
var request = URLRequest(url: url) | ||
if let deviceName = "\(UIDevice.current.name) (\(NCBrandOptions.shared.brand) iOS)".cString(using: .utf8), | ||
let deviceUserAgent = String(cString: deviceName, encoding: .ascii) { | ||
webView.customUserAgent = deviceUserAgent | ||
} else { | ||
webView.customUserAgent = userAgent | ||
} | ||
|
||
if let deviceName = "\(UIDevice.current.name) (\(NCBrandOptions.shared.brand) iOS)".cString(using: .utf8), | ||
let deviceUserAgent = String(cString: deviceName, encoding: .ascii) { | ||
webView.customUserAgent = deviceUserAgent | ||
} else { | ||
webView.customUserAgent = userAgent | ||
} | ||
request.addValue("true", forHTTPHeaderField: "OCS-APIRequest") | ||
request.addValue(language, forHTTPHeaderField: "Accept-Language") | ||
|
||
request.addValue("true", forHTTPHeaderField: "OCS-APIRequest") | ||
request.addValue(language, forHTTPHeaderField: "Accept-Language") | ||
webView.load(request) | ||
} | ||
} | ||
|
||
webView.load(request) | ||
private func pollLogin() { | ||
NextcloudKit.shared.getLoginFlowV2Poll(token: self.loginFlowV2Token, endpoint: self.loginFlowV2Endpoint) { server, loginName, appPassword, _, error in | ||
if error == .success, let server, let loginName, let appPassword { | ||
self.createAccount(server: server, username: loginName, password: appPassword) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I stopped using |
||
} | ||
} | ||
|
||
func getAppPassword(serverUrl: String, username: String, password: String) { | ||
|
@@ -205,6 +221,10 @@ class NCLoginWeb: UIViewController { | |
@objc func changeUser(sender: UIBarButtonItem) { | ||
toggleMenu() | ||
} | ||
|
||
@objc func applicationDidBecomeActive(_ notification: NSNotification) { | ||
pollLogin() | ||
} | ||
} | ||
|
||
extension NCLoginWeb: WKNavigationDelegate { | ||
|
@@ -271,15 +291,7 @@ extension NCLoginWeb: WKNavigationDelegate { | |
|
||
NCActivityIndicator.shared.stop() | ||
|
||
if loginFlowV2Available { | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { | ||
NextcloudKit.shared.getLoginFlowV2Poll(token: self.loginFlowV2Token, endpoint: self.loginFlowV2Endpoint) { server, loginName, appPassword, _, error in | ||
if error == .success && server != nil && loginName != nil && appPassword != nil { | ||
self.createAccount(server: server!, username: loginName!, password: appPassword!) | ||
} | ||
} | ||
} | ||
} | ||
pollLogin() | ||
} | ||
|
||
// MARK: - | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marinofaggiana Please test with this enabled and disabled