Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion datalayer_core/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

"""Datalayer Core version information."""

__version__ = "1.1.7"
__version__ = "1.1.8"
4 changes: 1 addition & 3 deletions datalayer_core/cli/commands/authn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
import os
import threading
import time
import warnings
from typing import Optional

import questionary
import typer
from rich.console import Console

from datalayer_core.client.client import DatalayerClient
from datalayer_core.displays.me import display_me
from datalayer_core.services.authn.http_server import get_token
from datalayer_core.utils.network import fetch, find_http_port
from datalayer_core.utils.urls import DEFAULT_DATALAYER_RUN_URL, DatalayerURLs
from datalayer_core.utils.urls import DatalayerURLs

# Create a Typer app for auth commands
app = typer.Typer(name="auth", help="Authentication commands")
Expand Down
2 changes: 1 addition & 1 deletion datalayer_core/cli/commands/runtime_snapshots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2023-2025 Datalayer, Inc.
# Distributed under the terms of the Modified BSD License.

"""Snapshot commands for Datalayer CLI."""
"""Runtime Snapshot commands for Datalayer CLI."""

from typing import Optional

Expand Down
15 changes: 8 additions & 7 deletions datalayer_core/services/authn/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _save_token(self, query: str) -> None:

if not user_raw or not token:
self.send_error(HTTPStatus.BAD_REQUEST, "User and token must be provided.")

user = json.loads(urllib.parse.unquote(user_raw))
content = AUTH_SUCCESS_PAGE.format(
user_key=DATALAYER_IAM_USER_KEY,
Expand All @@ -107,10 +108,10 @@ def _save_token(self, query: str) -> None:

def do_GET(self) -> None:
"""Handle GET requests for authentication flow."""
parts = urllib.parse.urlsplit(self.path)
if parts[2].strip("/").endswith("oauth/callback"):
self._save_token(parts[3])
elif parts[2] in {"/", "/datalayer/login/cli"}:
(scheme, netloc, path, query, fragment) = urllib.parse.urlsplit(self.path)
if path.strip("/").endswith("callback"):
self._save_token(query)
elif path in {"/", "/datalayer/login/cli"}:
content = LANDING_PAGE.format(
config=json.dumps(
{
Expand Down Expand Up @@ -165,9 +166,9 @@ def log_message(self, format: str, *args: t.Tuple[t.Any]) -> None:
)


class DualStackServer(HTTPServer):
class AuthHTTPServer(HTTPServer):
"""
HTTP server supporting both IPv4 and IPv6.
HTTP server supporting authentication.

Parameters
----------
Expand Down Expand Up @@ -297,7 +298,7 @@ def get_token(
# return None if httpd.token is None else (httpd.user_handle, httpd.token)
return None
else:
httpd = DualStackServer(server_address, LoginRequestHandler, run_url)
httpd = AuthHTTPServer(server_address, LoginRequestHandler, run_url)
logger.info(
f"Waiting for user logging, open http://localhost:{port}. Press CTRL+C to abort.\n"
)
Expand Down
42 changes: 22 additions & 20 deletions datalayer_core/services/authn/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,28 @@

AUTH_SUCCESS_PAGE = """<!DOCTYPE html>
<html>
<body>
<script type="module">
// Store the user information
window.localStorage.setItem(
'{user_key}',
JSON.stringify({{
uid: '{uid}',
handle: '{handle}',
firstName: '{first_name}',
lastName: '{last_name}',
email: '{email}',
displayName: '{display_name}'
}})
);
// Store the token
localStorage.setItem('{token_key}', '{token}');
// Redirect to default page
window.location.replace('{base_url}');
</script>
</body>
<head>
<script type="module">
// Store the user information
window.localStorage.setItem(
'{user_key}',
JSON.stringify({{
uid: '{uid}',
handle: '{handle}',
firstName: '{first_name}',
lastName: '{last_name}',
email: '{email}',
displayName: '{display_name}'
}})
);
// Store the token.
localStorage.setItem('{token_key}', '{token}');
// Redirect to login page.
window.location.pathname = '/datalayer/login/cli';
</script>
</head>
<body>
</body>
</html>"""


Expand Down
Loading