sweatstack-cli 0.13.0__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.
- sweatstack_cli/api/client.py +11 -1
- sweatstack_cli/auth/__init__.py +3 -0
- sweatstack_cli/commands/auth.py +30 -20
- sweatstack_cli/exceptions.py +21 -0
- {sweatstack_cli-0.13.0.dist-info → sweatstack_cli-0.14.0.dist-info}/METADATA +1 -1
- {sweatstack_cli-0.13.0.dist-info → sweatstack_cli-0.14.0.dist-info}/RECORD +8 -8
- {sweatstack_cli-0.13.0.dist-info → sweatstack_cli-0.14.0.dist-info}/WHEEL +1 -1
- {sweatstack_cli-0.13.0.dist-info → sweatstack_cli-0.14.0.dist-info}/entry_points.txt +0 -0
sweatstack_cli/api/client.py
CHANGED
|
@@ -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
|
|
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,
|
sweatstack_cli/auth/__init__.py
CHANGED
|
@@ -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
|
|
sweatstack_cli/commands/auth.py
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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:
|
|
90
|
-
console.print(f" Email:
|
|
91
|
-
console.print(f" ID:
|
|
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()
|
sweatstack_cli/exceptions.py
CHANGED
|
@@ -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
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sweatstack-cli
|
|
3
|
-
Version: 0.
|
|
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,27 +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=
|
|
4
|
+
sweatstack_cli/exceptions.py,sha256=Qzc1tbchk3Zhfin4Z08hQ1xpTK-dKqjkde2CXDpAY4s,2227
|
|
5
5
|
sweatstack_cli/go_live.py,sha256=6-WjN9jyfLnbLXs0eAEX0NkwWeigf1A7BYVGG6W092w,1855
|
|
6
6
|
sweatstack_cli/main.py,sha256=obcF1VGhwcE_pI1BwTJkY4J4BgIGac-y3yYGvY6ZOp8,2330
|
|
7
7
|
sweatstack_cli/project.py,sha256=yUpkrEbPD2c0lu8IKw88aQrkFtksLHMjmgHlaqKVQUo,3660
|
|
8
8
|
sweatstack_cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
sweatstack_cli/version_check.py,sha256=yZ_qVe7tUBowUDAmMki-wyf5pSxlNDsoWKgTcSfesBA,2015
|
|
10
10
|
sweatstack_cli/api/__init__.py,sha256=l9s6BzF6Wx17K_ElRUX-8aAwwIIzqmGF1PQ3Mbc07mw,107
|
|
11
|
-
sweatstack_cli/api/client.py,sha256=
|
|
12
|
-
sweatstack_cli/auth/__init__.py,sha256=
|
|
11
|
+
sweatstack_cli/api/client.py,sha256=bfNfLdbFqoWA47qdi4JrSCdTIASaP9zavTDAIvoxFAQ,7071
|
|
12
|
+
sweatstack_cli/auth/__init__.py,sha256=ownkUS33uOvXu78C9ldc6v4I8Kirn987YLrwcHKi42g,7149
|
|
13
13
|
sweatstack_cli/auth/callback_server.py,sha256=37aTX7smvmrn1azRzOPPDkuBwcunUt3KnNVZ5SCJRLM,6578
|
|
14
14
|
sweatstack_cli/auth/jwt.py,sha256=Ja6ccFyRKtX5MPjFdHNavVYf8KTz0MYT86StbnF-cwg,1502
|
|
15
15
|
sweatstack_cli/auth/pkce.py,sha256=sO_xUeN1UIvXKX0yEIGgMTIIzvfCOCUwlyNAveEd16k,1542
|
|
16
16
|
sweatstack_cli/auth/tokens.py,sha256=kc8ytoO9PAyjLD6wUTIagVuP7_ia5ZjW5m_WjXIRIkA,4942
|
|
17
17
|
sweatstack_cli/commands/__init__.py,sha256=YCO8wYVvdGeoEI0p_oUm8ANLneuET4SHsKDjitMjAgY,35
|
|
18
18
|
sweatstack_cli/commands/app.py,sha256=90AwUm5RhagE5tZww77Fk9B0vpZFlC59OlylGXTxWC0,9055
|
|
19
|
-
sweatstack_cli/commands/auth.py,sha256=
|
|
19
|
+
sweatstack_cli/commands/auth.py,sha256=bVgxSeHdwPmu2lqmu4UQm4pPgVwvqd-FT2cneMq1rl0,4497
|
|
20
20
|
sweatstack_cli/commands/page.py,sha256=G58KEsiCeq4hD0Z5ot2g9W6vBH6iZu-lCvdA1kzep-U,24612
|
|
21
21
|
sweatstack_cli/services/__init__.py,sha256=pFrcjumdHNRU8aa3bxplq4jhCivH2YGGqkGG8yIMv20,337
|
|
22
22
|
sweatstack_cli/services/applications.py,sha256=VToXlk48kn2-39eTdDf_hSJUdZqkJjCFoDaqf6DpdGA,4428
|
|
23
23
|
sweatstack_cli/templates/page/index.html,sha256=vOnZnIstf252XLiQ6GBznVp5dSy5SqpSwRUfJT43bbQ,17374
|
|
24
|
-
sweatstack_cli-0.
|
|
25
|
-
sweatstack_cli-0.
|
|
26
|
-
sweatstack_cli-0.
|
|
27
|
-
sweatstack_cli-0.
|
|
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,,
|
|
File without changes
|