-
Notifications
You must be signed in to change notification settings - Fork 2
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
Login in the browser when possible #50
Open
LeoGrin
wants to merge
4
commits into
main
Choose a base branch
from
login_on_gui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from threading import Event | ||
import http.server | ||
import socketserver | ||
import webbrowser | ||
import urllib.parse | ||
from typing import Optional, Tuple | ||
|
||
|
||
class BrowserAuthHandler: | ||
def __init__(self, gui_url: str): | ||
self.gui_url = gui_url | ||
|
||
def try_browser_login(self) -> Tuple[bool, Optional[str]]: | ||
""" | ||
Attempts to perform browser-based login | ||
Returns (success: bool, token: Optional[str]) | ||
""" | ||
auth_event = Event() | ||
received_token = None | ||
|
||
class CallbackHandler(http.server.SimpleHTTPRequestHandler): | ||
def do_GET(self): | ||
nonlocal received_token | ||
|
||
parsed = urllib.parse.urlparse(self.path) | ||
query = urllib.parse.parse_qs(parsed.query) | ||
|
||
if "token" in query: | ||
received_token = query["token"][0] | ||
|
||
self.send_response(200) | ||
self.send_header("Content-type", "text/html") | ||
self.end_headers() | ||
success_html = """ | ||
<html> | ||
<body style="text-align: center; font-family: Arial, sans-serif; padding: 50px;"> | ||
<h2>Login successful!</h2> | ||
<p>You can close this window and return to your application.</p> | ||
</body> | ||
</html> | ||
""" | ||
self.wfile.write(success_html.encode()) | ||
auth_event.set() | ||
|
||
def log_message(self, format, *args): | ||
pass | ||
|
||
try: | ||
with socketserver.TCPServer(("", 0), CallbackHandler) as httpd: | ||
port = httpd.server_address[1] | ||
callback_url = f"http://localhost:{port}" | ||
|
||
login_url = f"{self.gui_url}/login?callback={callback_url}" | ||
|
||
print( | ||
"\nOpening browser for login. Please complete the login/registration process in your browser and return here.\n" | ||
) | ||
|
||
if not webbrowser.open(login_url): | ||
print( | ||
"\nCould not open browser automatically. Falling back to command-line login...\n" | ||
) | ||
return False, None | ||
|
||
while not auth_event.is_set(): | ||
httpd.handle_request() | ||
|
||
return received_token is not None, received_token | ||
|
||
except Exception: | ||
print("\n Browser auth failed. Falling back to command-line login...\n") | ||
return False, None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ protocol: "https" | |
host: "tabpfn-server-wjedmz7r5a-ez.a.run.app" | ||
# host: tabpfn-server-preprod-wjedmz7r5a-ez.a.run.app # preprod | ||
port: "443" | ||
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. Before merging the PR change the logo and title of the UI 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. |
||
gui_url: "https://frontend-1039906307296.europe-west4.run.app" | ||
endpoints: | ||
root: | ||
path: "/" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you provide more info on how this could fail? Is there e.g. times when the user doesn't have gui? in which situations might it be more comfortable in the cli?
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.
The main thing I had in mind is when the user is on a remote cluster. (in this case, there could also be a different workflow where we give the user the url and ask the user to paste the access token once he's logged in)