Skip to content
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

Merged
merged 42 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
45454db
Enable login v2
mpivchev Apr 30, 2024
e0563bc
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 2, 2024
d8b1e53
Add external browser option
mpivchev May 2, 2024
b705120
WIP
mpivchev May 3, 2024
7315858
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 13, 2024
498882e
WIP
mpivchev May 14, 2024
dbfb2f2
WIP
mpivchev May 15, 2024
33feeaf
Remove NCLoginWeb for v2
mpivchev May 15, 2024
c1eb3b0
Cleanup
mpivchev May 15, 2024
eb75e20
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 15, 2024
90ce7e5
WIP
mpivchev May 17, 2024
1edaba3
WIP
mpivchev May 21, 2024
2fcd32a
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 21, 2024
e68f305
WIP
mpivchev May 21, 2024
4d3b6b2
WIP
mpivchev May 22, 2024
8d0e157
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 22, 2024
fbb8fb3
WIP
mpivchev May 22, 2024
e57151a
WIP
mpivchev May 22, 2024
077e5d2
WIP
mpivchev May 22, 2024
aa1d335
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 22, 2024
de1b1d2
Merge branch 'develop' of https://github.com/nextcloud/ios into ssl-cert
mpivchev May 23, 2024
99f1e2d
WIP
mpivchev May 23, 2024
768970f
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 28, 2024
e6e9734
WIP
mpivchev May 28, 2024
8de1a2d
WIP
mpivchev May 30, 2024
7d9ab9f
WIP
mpivchev May 30, 2024
33e6f39
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev Jun 10, 2024
6d776a5
Change design
mpivchev Jun 10, 2024
86ccf8a
Rename
mpivchev Jun 10, 2024
d560133
Remove unneeded code
mpivchev Jun 10, 2024
b86242c
Refactor
mpivchev Jun 10, 2024
e87f4a1
Fix acknowldgements
mpivchev Jun 11, 2024
b01a8bb
Remove unneeded brand flags
mpivchev Jun 12, 2024
91b5322
WIP
mpivchev Jun 13, 2024
3365b4c
Merge branch 'ssl-cert' into login-v2-enable
mpivchev Jun 14, 2024
527cb47
WIP
mpivchev Jun 17, 2024
0b68beb
WIP
mpivchev Jun 17, 2024
ce53ed7
WIP
mpivchev Jun 18, 2024
7289bf1
cleanup
mpivchev Jun 19, 2024
d3e2781
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev Jun 24, 2024
d1be553
WIP
mpivchev Jun 24, 2024
b3dd8ba
Remove UI test
mpivchev Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Brand/NCBrand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ let userAgent: String = {
@objc public var use_themingColor: Bool = true
@objc public var use_themingLogo: Bool = false
@objc public var use_storeLocalAutoUploadAll: Bool = false
@objc public var use_loginflowv2: Bool = false // Don't touch me !!

@objc public var disable_intro: Bool = false
@objc public var disable_request_login_url: Bool = false
Expand Down
8 changes: 4 additions & 4 deletions iOSClient/Login/NCLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,16 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
self.loginButton.isEnabled = true

// Login Flow V2
if error == .success && NCBrandOptions.shared.use_loginflowv2 && token != nil && endpoint != nil && login != nil {
if error == .success, let token, let endpoint, let login {

if let loginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb {

loginWeb.urlBase = url
loginWeb.user = user
loginWeb.loginFlowV2Available = true
loginWeb.loginFlowV2Token = token!
loginWeb.loginFlowV2Endpoint = endpoint!
loginWeb.loginFlowV2Login = login!
loginWeb.loginFlowV2Token = token
loginWeb.loginFlowV2Endpoint = endpoint
loginWeb.loginFlowV2Login = login

self.navigationController?.pushViewController(loginWeb, animated: true)
}
Expand Down
52 changes: 32 additions & 20 deletions iOSClient/Login/NCLoginWeb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

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


// MARK: - View Life Cycle

override func viewDidLoad() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simulator Screenshot - iPhone 15 Pro Max - 2024-05-15 at 13 30 34

If error write a message and goBack ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stopped using NCLoginWeb for v2 and this screen stopped appearing. Now we only use NCLogin. NCLoginWeb can be renamed to NCLoginProviders as now only external providers use it.

}
}

func getAppPassword(serverUrl: String, username: String, password: String) {
Expand All @@ -205,6 +221,10 @@ class NCLoginWeb: UIViewController {
@objc func changeUser(sender: UIBarButtonItem) {
toggleMenu()
}

@objc func applicationDidBecomeActive(_ notification: NSNotification) {
pollLogin()
}
}

extension NCLoginWeb: WKNavigationDelegate {
Expand Down Expand Up @@ -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: -
Expand Down
Loading