sweatstack-cli 0.12.1__py3-none-any.whl → 0.14.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,12 @@ import httpx
10
10
 
11
11
  from sweatstack_cli.auth import Authenticator
12
12
  from sweatstack_cli.config import get_settings
13
- from sweatstack_cli.exceptions import APIError, AuthenticationError
13
+ from sweatstack_cli.exceptions import (
14
+ APIError,
15
+ AuthenticationError,
16
+ SecondFactorEnrollmentRequired,
17
+ SecondFactorRequired,
18
+ )
14
19
 
15
20
 
16
21
  class APIClient:
@@ -152,11 +157,16 @@ class APIClient:
152
157
  AuthenticationError: For 401 responses.
153
158
  APIError: For other error responses.
154
159
  """
160
+ # A step-up (RFC 9470) is a 401 too, but not an expired session: read the challenge first.
155
161
  if response.status_code == 401:
162
+ if "insufficient_user_authentication" in response.headers.get("WWW-Authenticate", ""):
163
+ raise SecondFactorRequired()
156
164
  raise AuthenticationError("Session expired. Run 'sweatstack login' again.")
157
165
 
158
166
  if response.status_code >= 400:
159
167
  detail, code = self._extract_error(response)
168
+ if code == "second_factor_enrollment_required":
169
+ raise SecondFactorEnrollmentRequired(detail)
160
170
  raise APIError(
161
171
  f"API error ({response.status_code}): {detail}",
162
172
  status_code=response.status_code,
@@ -154,6 +154,9 @@ class Authenticator:
154
154
  "code_challenge": pkce.challenge,
155
155
  "code_challenge_method": "S256",
156
156
  "state": pkce.state,
157
+ # SweatStack plan 084 D11: a user with a passkey confirms it in the browser here, and the
158
+ # CLI's tokens carry that confirmation. For anyone else it changes nothing.
159
+ "acr_values": "mfa",
157
160
  }
158
161
  return f"{self._settings.api_url}/oauth/authorize?{urlencode(params)}"
159
162
 
@@ -12,6 +12,7 @@ import typer
12
12
  from sweatstack_cli.api import APIClient
13
13
  from sweatstack_cli.console import console, stderr_console
14
14
  from sweatstack_cli.exceptions import APIError, AuthenticationError
15
+ from sweatstack_cli.go_live import app_url, print_go_live
15
16
  from sweatstack_cli.project import CONFIG_FILENAME, write_config
16
17
  from sweatstack_cli.services.applications import create_application
17
18
 
@@ -198,6 +199,11 @@ def _print_app_created(result: dict[str, str], env_path: Path | None, config_pat
198
199
  console.print()
199
200
  console.print("[yellow]Save the secret now — it won't be shown again.[/yellow]")
200
201
 
202
+ console.print()
203
+ console.print("Next: authorize with your own account. The app's overview walks you through it:")
204
+ console.print(f" {app_url(result['id'])}")
205
+ print_go_live(result)
206
+
201
207
 
202
208
  @app.command()
203
209
  def link(
@@ -2,10 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from datetime import datetime
6
+
5
7
  import typer
6
8
 
7
9
  from sweatstack_cli.api import APIClient
8
10
  from sweatstack_cli.auth import Authenticator
11
+ from sweatstack_cli.auth.jwt import decode_jwt_payload
9
12
  from sweatstack_cli.console import console
10
13
  from sweatstack_cli.exceptions import APIError, AuthenticationError
11
14
  from sweatstack_cli.version_check import check_for_update
@@ -22,30 +25,22 @@ def _display_name(user: dict[str, object]) -> str:
22
25
 
23
26
 
24
27
  def login(
28
+ # Kept so scripts that pass it keep working.
25
29
  force: bool = typer.Option(
26
30
  False,
27
31
  "--force",
28
32
  "-f",
29
- help="Force re-authentication even if already logged in.",
33
+ hidden=True,
34
+ help="No longer needed: login always opens the browser.",
30
35
  ),
31
36
  ) -> None:
32
- """Authenticate with SweatStack via browser."""
33
- auth = Authenticator()
37
+ """Authenticate with SweatStack via browser.
34
38
 
35
- # Check if already logged in
36
- if not force:
37
- existing = auth.get_valid_tokens()
38
- if existing:
39
- try:
40
- client = APIClient(authenticator=auth)
41
- user = client.get("/api/v1/oauth/userinfo")
42
- console.print(
43
- f"Already logged in as [bold]{_display_name(user)}[/bold]. "
44
- f"Use [cyan]--force[/cyan] to re-authenticate."
45
- )
46
- return
47
- except AuthenticationError:
48
- pass # Token invalid, proceed with login
39
+ Always opens the browser, as ``gh auth login`` does: signing in again is how a
40
+ passkey confirmation reaches the CLI's tokens (SweatStack plan 084). Other
41
+ commands never open a browser on their own.
42
+ """
43
+ auth = Authenticator()
49
44
 
50
45
  with console.status("[bold]Opening browser for authentication...[/bold]"):
51
46
  try:
@@ -64,6 +59,20 @@ def login(
64
59
  raise typer.Exit(2)
65
60
 
66
61
 
62
+ def _confirmation(access_token: str) -> str:
63
+ """Whether the login that issued these tokens confirmed a passkey (SweatStack plan 084):
64
+ the ``amr`` and ``auth_time`` claims the browser's confirmation put on them. Which actions
65
+ need a confirmation, and how recent, is the server's to decide: a refusal says what to do."""
66
+ try:
67
+ claims = decode_jwt_payload(access_token)
68
+ except ValueError:
69
+ return "unknown"
70
+ if "mfa" in (claims.get("amr") or []) and isinstance(claims.get("auth_time"), int):
71
+ confirmed_at = datetime.fromtimestamp(claims["auth_time"]).astimezone()
72
+ return f"confirmed at login {confirmed_at:%Y-%m-%d %H:%M}"
73
+ return "not confirmed at login"
74
+
75
+
67
76
  def logout() -> None:
68
77
  """Remove stored credentials."""
69
78
  auth = Authenticator()
@@ -86,11 +95,12 @@ def status() -> None:
86
95
  try:
87
96
  client = APIClient(authenticator=auth)
88
97
  user = client.get("/api/v1/oauth/userinfo")
89
- console.print(f" Name: {_display_name(user)}")
90
- console.print(f" Email: {user.get('email', 'unknown')}")
91
- console.print(f" ID: {user.get('sub', 'unknown')}")
98
+ console.print(f" Name: {_display_name(user)}")
99
+ console.print(f" Email: {user.get('email', 'unknown')}")
100
+ console.print(f" ID: {user.get('sub', 'unknown')}")
92
101
  except (AuthenticationError, APIError):
93
102
  pass # Silently skip user info on error
103
+ console.print(f" Passkey: {_confirmation(tokens.access_token)}")
94
104
 
95
105
  # Check version
96
106
  update_available, latest = check_for_update()
@@ -16,9 +16,9 @@ import typer
16
16
  from rich.progress import Progress, SpinnerColumn, TextColumn
17
17
 
18
18
  from sweatstack_cli.api import APIClient
19
- from sweatstack_cli.config import get_settings
20
19
  from sweatstack_cli.console import console
21
20
  from sweatstack_cli.exceptions import APIError, AuthenticationError
21
+ from sweatstack_cli.go_live import print_go_live
22
22
  from sweatstack_cli.project import CONFIG_FILENAME, ProjectConfig, update_config, write_config
23
23
  from sweatstack_cli.services.applications import (
24
24
  APPLICATION_HAS_PAGE_CODE,
@@ -196,16 +196,8 @@ def deploy(
196
196
  console.print(f" Files: {file_count}")
197
197
  console.print(f" URL: {result.get('url', 'N/A')}")
198
198
 
199
- # Nudge to publish if app is private
200
- application = result.get("application", {})
201
- if application.get("is_private"):
202
- app_id = application.get("id")
203
- if app_id:
204
- base_url = get_settings().api_url
205
- console.print()
206
- console.print("Your app is private. Ready to go public?")
207
- publish_url = f"{base_url}/applications/{app_id}/publish"
208
- console.print(f" {publish_url}")
199
+ # What the app still needs before anyone else can connect, as the server reports it.
200
+ print_go_live(result.get("application") or {}, on_pages=True)
209
201
 
210
202
 
211
203
  def _upload(
@@ -18,6 +18,27 @@ class AuthenticationError(CLIError):
18
18
  exit_code = 2
19
19
 
20
20
 
21
+ class SecondFactorRequired(AuthenticationError):
22
+ """The action needs a recent passkey confirmation (SweatStack plan 084).
23
+
24
+ The server answers RFC 9470's step-up challenge: a ``401`` whose ``WWW-Authenticate`` says
25
+ ``insufficient_user_authentication``. The browser confirms it at ``sweatstack login``; the CLI
26
+ never handles a passkey itself. Not an expired session, so it never says so."""
27
+
28
+ def __init__(self) -> None:
29
+ super().__init__(
30
+ "This needs your passkey. Run 'sweatstack login' to confirm in your browser, "
31
+ "then run this command again."
32
+ )
33
+
34
+
35
+ class SecondFactorEnrollmentRequired(AuthenticationError):
36
+ """The account has no passkey, and the action needs one (SweatStack plan 084)."""
37
+
38
+ def __init__(self, detail: str) -> None:
39
+ super().__init__(f"{detail} Then run 'sweatstack login' and this command again.")
40
+
41
+
21
42
  class APIError(CLIError):
22
43
  """API returned an error response.
23
44
 
@@ -0,0 +1,45 @@
1
+ """What an app still needs before anyone else can connect, as the CLI prints it.
2
+
3
+ The server decides: `go_live_missing` on the application in an API response is the same
4
+ checklist the web app's pages show (SweatStack plan 080). The CLI only prints it and links to
5
+ the page where each item is filled in, so a terminal, an agent and the browser agree.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+
12
+ from sweatstack_cli.config import get_settings
13
+ from sweatstack_cli.console import console
14
+
15
+
16
+ def app_url(application_id: str, tab: str = "") -> str:
17
+ """The application's page in the web app, or one of its tabs."""
18
+ return f"{get_settings().api_url}/applications/{application_id}{tab}"
19
+
20
+
21
+ def print_go_live(application: dict[str, Any], *, on_pages: bool = False) -> None:
22
+ """Print what stands between `application` and anyone else connecting, or nothing when the
23
+ app is ready. A server older than the checklist sends only `is_private`; then the CLI says
24
+ that much and links to the same page."""
25
+ application_id = application.get("id")
26
+ if not application_id:
27
+ return
28
+ missing = [item["label"] for item in application.get("go_live_missing") or []]
29
+ private = bool(application.get("is_private"))
30
+ if not missing and not private:
31
+ return
32
+
33
+ console.print()
34
+ if private:
35
+ console.print("Your app is private: only you can connect.")
36
+ else:
37
+ console.print("Your app is public, but anyone else is turned away until you add:")
38
+ if missing:
39
+ if private:
40
+ console.print("Before anyone else can, add:")
41
+ for label in missing:
42
+ console.print(f" - {label}")
43
+ if private and on_pages:
44
+ console.print("Runs entirely in the browser? The Pages fast track fills in most of it.")
45
+ console.print(f" {app_url(application_id, '/consent')}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sweatstack-cli
3
- Version: 0.12.1
3
+ Version: 0.14.0
4
4
  Summary: Command-line interface for SweatStack — the sports data platform for developers
5
5
  Project-URL: Homepage, https://sweatstack.no
6
6
  Project-URL: Documentation, https://docs.sweatstack.no
@@ -1,26 +1,27 @@
1
1
  sweatstack_cli/__init__.py,sha256=FalqkgMa69vADPpNY76Cztq5oiLgzRNVlhaR4itdZ78,465
2
2
  sweatstack_cli/config.py,sha256=cD4OXnVAKVagYazyk9Cw-WWx62tJPqcjQt1cknYyymM,706
3
3
  sweatstack_cli/console.py,sha256=69KWAM7ksnYRTONMYTXGXN4LWRAQhRxcLXO0LcWGLqo,300
4
- sweatstack_cli/exceptions.py,sha256=VKV6KVhztfGRmj5jLKnqY0PEBD1qJGEg1ePuKY9rn_o,1334
4
+ sweatstack_cli/exceptions.py,sha256=Qzc1tbchk3Zhfin4Z08hQ1xpTK-dKqjkde2CXDpAY4s,2227
5
+ sweatstack_cli/go_live.py,sha256=6-WjN9jyfLnbLXs0eAEX0NkwWeigf1A7BYVGG6W092w,1855
5
6
  sweatstack_cli/main.py,sha256=obcF1VGhwcE_pI1BwTJkY4J4BgIGac-y3yYGvY6ZOp8,2330
6
7
  sweatstack_cli/project.py,sha256=yUpkrEbPD2c0lu8IKw88aQrkFtksLHMjmgHlaqKVQUo,3660
7
8
  sweatstack_cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
9
  sweatstack_cli/version_check.py,sha256=yZ_qVe7tUBowUDAmMki-wyf5pSxlNDsoWKgTcSfesBA,2015
9
10
  sweatstack_cli/api/__init__.py,sha256=l9s6BzF6Wx17K_ElRUX-8aAwwIIzqmGF1PQ3Mbc07mw,107
10
- sweatstack_cli/api/client.py,sha256=Ukpq_rVc2tW1cKlTBF_UfInHVcaHoPHF9pASNRAAcsQ,6632
11
- sweatstack_cli/auth/__init__.py,sha256=J5WTFjaogP5lPTorWcW3VTwok-9kI_NxFLtXBYWQCI4,6926
11
+ sweatstack_cli/api/client.py,sha256=bfNfLdbFqoWA47qdi4JrSCdTIASaP9zavTDAIvoxFAQ,7071
12
+ sweatstack_cli/auth/__init__.py,sha256=ownkUS33uOvXu78C9ldc6v4I8Kirn987YLrwcHKi42g,7149
12
13
  sweatstack_cli/auth/callback_server.py,sha256=37aTX7smvmrn1azRzOPPDkuBwcunUt3KnNVZ5SCJRLM,6578
13
14
  sweatstack_cli/auth/jwt.py,sha256=Ja6ccFyRKtX5MPjFdHNavVYf8KTz0MYT86StbnF-cwg,1502
14
15
  sweatstack_cli/auth/pkce.py,sha256=sO_xUeN1UIvXKX0yEIGgMTIIzvfCOCUwlyNAveEd16k,1542
15
16
  sweatstack_cli/auth/tokens.py,sha256=kc8ytoO9PAyjLD6wUTIagVuP7_ia5ZjW5m_WjXIRIkA,4942
16
17
  sweatstack_cli/commands/__init__.py,sha256=YCO8wYVvdGeoEI0p_oUm8ANLneuET4SHsKDjitMjAgY,35
17
- sweatstack_cli/commands/app.py,sha256=6cW-e6UYXHuk6eXJCXx2R4Okxqx_SE7u2lJwZfU19ps,8801
18
- sweatstack_cli/commands/auth.py,sha256=kkSZoWFTUw9Mo30FA_bOJxduWC1nuvkl_m1qtrtSj4I,3905
19
- sweatstack_cli/commands/page.py,sha256=Kqq3JAGBzXRo3AExOGywOHoLiOH4CAtkce8UMGLTaRE,24900
18
+ sweatstack_cli/commands/app.py,sha256=90AwUm5RhagE5tZww77Fk9B0vpZFlC59OlylGXTxWC0,9055
19
+ sweatstack_cli/commands/auth.py,sha256=bVgxSeHdwPmu2lqmu4UQm4pPgVwvqd-FT2cneMq1rl0,4497
20
+ sweatstack_cli/commands/page.py,sha256=G58KEsiCeq4hD0Z5ot2g9W6vBH6iZu-lCvdA1kzep-U,24612
20
21
  sweatstack_cli/services/__init__.py,sha256=pFrcjumdHNRU8aa3bxplq4jhCivH2YGGqkGG8yIMv20,337
21
22
  sweatstack_cli/services/applications.py,sha256=VToXlk48kn2-39eTdDf_hSJUdZqkJjCFoDaqf6DpdGA,4428
22
23
  sweatstack_cli/templates/page/index.html,sha256=vOnZnIstf252XLiQ6GBznVp5dSy5SqpSwRUfJT43bbQ,17374
23
- sweatstack_cli-0.12.1.dist-info/METADATA,sha256=FETd856YsecXuz2TQVlV7PNX3HgIk1VoGXC0NSXy67A,5531
24
- sweatstack_cli-0.12.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
25
- sweatstack_cli-0.12.1.dist-info/entry_points.txt,sha256=rnH0EV1U9CQlmKQcJ7RmxGpNRTa9J-YdiIJZDYrAXb4,56
26
- sweatstack_cli-0.12.1.dist-info/RECORD,,
24
+ sweatstack_cli-0.14.0.dist-info/METADATA,sha256=a9iGhw2UyWD_1XUM8hG9vdwlXZQJrm_7U6v4zmkXfx4,5531
25
+ sweatstack_cli-0.14.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
26
+ sweatstack_cli-0.14.0.dist-info/entry_points.txt,sha256=rnH0EV1U9CQlmKQcJ7RmxGpNRTa9J-YdiIJZDYrAXb4,56
27
+ sweatstack_cli-0.14.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.4
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any