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

Use either a browser or sailfish webview for logging in. #20

Merged
merged 10 commits into from
Jan 23, 2021

Conversation

b100dian
Copy link
Collaborator

@b100dian b100dian commented Nov 14, 2020

Added an auth-server that actually listens on port 3000 and if you do connect with the browser it displays "You can now switch back to Sailslack".

Moved the sailfish webview to a lazy-loaded component as it still crashes if not run from terminal \o/
Crash is worked around, webview is still lazy loaded but now we can use it in WebViewPage which makes for better virtual keyboard support.
The sailfish webview redirect actually works, I left the comment for reference from my initial impressions..

Here's the stack of the crash.. sailfishos/sailfish-components-webview#26 (comment)
(The link actually has the fix for the crash now!)

To be able to build this, you need to tick the webview in Qt's Sailfish IDE Tools -> Options -> Sailfish OS -> Build Engine -> Manage Build Targets -> search for "webview" and tick sailfish-components-webview-qt5
image

@b100dian b100dian marked this pull request as ready for review January 4, 2021 00:31
@b100dian b100dian changed the title Try to use sailfish webview for loging in. Use either a browser or sailfish webview for logging in. Jan 4, 2021
Copy link
Owner

@danvratil danvratil left a comment

Choose a reason for hiding this comment

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

Looks really good, thanks a lot for this patch! There are some minor nitpicks, small issue, nothing major.

onClicked: {
// Closing the 3000 port as even though the webview would successfully connect to it, the timing it navigates away from this page makes
// the webview crash (at onResultUrlAvailable signal).
server.close();
Copy link
Owner

Choose a reason for hiding this comment

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

Without the server running, the login via webview never finishes for me.

To avoid the crash, you should close the client socket after sending the response HTML in AuthServer, then the webview no longer crashes, because the connection is terminated before the webview is destroyed by the pagestack pop.

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'll investigate this more. The first commit of this branch there wass no problem with the webivew connecting locally (it was actually the only way to get back the token)

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 think I got this: the webview was a bit more picky about my "http" response, and it was still 'loading' when destroyed. Adding Content-Length to the response seems to have fixed that. Let me know if this works on your end.

switch (status) {
case PageStatus.Active:
server.listen(3000);
Qt.openUrlExternally(page.startUrl + "&state=" + page.processId);
Copy link
Owner

Choose a reason for hiding this comment

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

This causes the web browser to be automatically opened when the page is first shown. Is that intended as default behaviour, where the alternative options are just for "advanced" users? Or would it be better to let the user to choose the right method for themselves?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What would be your preference?
I actually have more than one browser so this pops a dialog to let me chose the browser. But now I realize that fresh installs will directly start the login sequence in the browser (while I am still able to dismiss that dialog).
This was a last minute 'great idea' that maybe this new screen is not user friendly. I am open to suggestions if this should be enabled or removed.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm I would say let's keep the screen (for debugging purposes if nothing else) and go to webview by default (feels like a better flow). Regarding the browser, have you tried whether this works when the user users an Android browser, like Firefox?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I havent yet tried with an AD browser (can you register one as url handler?)
I will try to show the webview first and offer an "Advanced" pull-down menu

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, see latest commit @danvratil

Also closed the socket after sending the HTTP response.
The webview now has a header because I noticed that swipong may
be disabled before a connection is made and this would mean losing
the ability to access Advanced pulley in the future / in some cases.
Copy link
Owner

@danvratil danvratil left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this change! Great job!

@danvratil danvratil merged commit 0ebdb9f into danvratil:master Jan 23, 2021
@danvratil danvratil mentioned this pull request Jan 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants