dash-auth-async 1.3.1__tar.gz → 1.3.3__tar.gz
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.
- {dash_auth_async-1.3.1/dash_auth_async.egg-info → dash_auth_async-1.3.3}/PKG-INFO +63 -7
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/README.md +61 -5
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/auth.py +1 -1
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/basic_auth.py +7 -3
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/oidc_auth.py +9 -9
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/public_routes.py +14 -10
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/version.py +1 -1
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3/dash_auth_async.egg-info}/PKG-INFO +63 -7
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async.egg-info/requires.txt +1 -1
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/pyproject.toml +2 -9
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/LICENSE +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/MANIFEST.in +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/__init__.py +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/_optional.py +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/backends.py +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/group_protection.py +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/quart_client.py +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async/websocket_auth.py +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async.egg-info/SOURCES.txt +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async.egg-info/dependency_links.txt +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async.egg-info/top_level.txt +0 -0
- {dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dash-auth-async
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.3
|
|
4
4
|
Summary: Dash Authorization Package.
|
|
5
5
|
Author-email: Jonas Schrage <119843859+joschrag@users.noreply.github.com>
|
|
6
6
|
License: MIT
|
|
@@ -40,7 +40,7 @@ Provides-Extra: quart
|
|
|
40
40
|
Requires-Dist: dash[quart]>=4.2.0; extra == "quart"
|
|
41
41
|
Requires-Dist: httpx>=0.23.0; extra == "quart"
|
|
42
42
|
Provides-Extra: async
|
|
43
|
-
Requires-Dist: dash[async]>=
|
|
43
|
+
Requires-Dist: dash[async]>=3.1.0; extra == "async"
|
|
44
44
|
Dynamic: license-file
|
|
45
45
|
|
|
46
46
|
## Dash Authorization and Login
|
|
@@ -60,7 +60,7 @@ License: MIT
|
|
|
60
60
|
|
|
61
61
|
## Feature overview
|
|
62
62
|
|
|
63
|
-
How this fork compares to upstream [`dash-auth`](https://github.com/plotly/dash-auth). The headline difference is async: upstream is Flask-only, while `dash-auth-async` adds the Quart
|
|
63
|
+
How this fork compares to upstream [`dash-auth`](https://github.com/plotly/dash-auth). The headline difference is async: upstream is Flask-only, while `dash-auth-async` adds async callback support, the Quart and FastAPI backends, authenticated WebSocket callbacks, and a pluggable backend abstraction.
|
|
64
64
|
|
|
65
65
|
| Capability | `dash-auth` (upstream) | `dash-auth-async` |
|
|
66
66
|
| --- | :---: | :---: |
|
|
@@ -76,9 +76,9 @@ How this fork compares to upstream [`dash-auth`](https://github.com/plotly/dash-
|
|
|
76
76
|
|
|
77
77
|
<sup>1</sup> `detect_backend` resolves Flask/Quart/FastAPI automatically; any other server is supported by supplying your own `Backend` instance.
|
|
78
78
|
|
|
79
|
-
<sup>2</sup>
|
|
79
|
+
<sup>2</sup> Supported on **every** backend, Flask included — you don't need Quart or FastAPI, just the `async` extra (bundled as `dash-auth-async[async]`, which pulls in `dash[async]`).
|
|
80
80
|
|
|
81
|
-
<sup>3</sup> Provided by the Quart and FastAPI backends. WebSocket auth is a no-op on Flask, which has no WebSocket callback transport.
|
|
81
|
+
<sup>3</sup> Provided by the Quart and FastAPI backends only. WebSocket auth is a no-op on Flask, which has no WebSocket callback transport.
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
For local testing, install [uv](https://docs.astral.sh/uv/getting-started/installation/), then install the dev dependencies and run individual tests:
|
|
@@ -261,6 +261,62 @@ auth.register_provider(
|
|
|
261
261
|
|
|
262
262
|
Once this is done, connecting to your app will automatically redirect to the IDP login page.
|
|
263
263
|
|
|
264
|
+
#### Running behind a reverse proxy
|
|
265
|
+
|
|
266
|
+
> **Behavior change.** Earlier versions rewrote the OIDC callback host from the
|
|
267
|
+
> client-supplied `X-Forwarded-Host` header. That header trust was **removed** — an
|
|
268
|
+
> attacker could set it to steer the `redirect_uri` handed to your IDP (auth-code leak /
|
|
269
|
+
> open redirect). The `redirect_uri` is now built **only** from the host and scheme of
|
|
270
|
+
> the incoming request.
|
|
271
|
+
|
|
272
|
+
The consequence: behind a proxy that terminates TLS or rewrites the host, the
|
|
273
|
+
`redirect_uri` comes out as `http://localhost:8050/...` and your IDP rejects it. To get
|
|
274
|
+
the real public host and scheme back, **restore it at the transport layer** — where the
|
|
275
|
+
trust can be bounded to your actual proxy, instead of trusting any client.
|
|
276
|
+
|
|
277
|
+
Two separate things to restore: **scheme** (http→https) and **host**. Most app servers
|
|
278
|
+
forward the scheme but **not** the host — `--forwarded-allow-ips` / `--proxy-headers`
|
|
279
|
+
only governs `X-Forwarded-Proto`/`-For`, never the host. So:
|
|
280
|
+
|
|
281
|
+
* **Scheme:** set `force_https_callback=True` on `OIDCAuth` (or pass the name of an env
|
|
282
|
+
var that, when present, enables it). This covers the http→https half on every backend.
|
|
283
|
+
* **Host:** add proxy middleware that honours `X-Forwarded-Host`, sized to your real
|
|
284
|
+
proxy-chain length:
|
|
285
|
+
|
|
286
|
+
| Backend | Server(s) | How to restore the host |
|
|
287
|
+
|---|---|---|
|
|
288
|
+
| **Flask** | gunicorn, waitress, mod_wsgi, … | `werkzeug` `ProxyFix` on the WSGI app (server-independent — gunicorn alone won't do the host) |
|
|
289
|
+
| **Quart** | hypercorn | `ProxyFixMiddleware(mode="modern", trusted_hops=N)` — restores host and scheme |
|
|
290
|
+
| **Quart / FastAPI** | uvicorn | uvicorn `--proxy-headers` does scheme only; add an `X-Forwarded-Host` ASGI middleware or have the proxy rewrite the `Host` header |
|
|
291
|
+
|
|
292
|
+
**Flask** (WSGI — gunicorn, waitress, …):
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
296
|
+
|
|
297
|
+
# Counts MUST equal your real proxy-chain length — setting them higher than the
|
|
298
|
+
# actual chain (or enabling this with no proxy) re-opens the spoofing hole.
|
|
299
|
+
app.server.wsgi_app = ProxyFix(app.server.wsgi_app, x_for=1, x_proto=1, x_host=1)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**Quart** (served by hypercorn) — wrap the ASGI app:
|
|
303
|
+
|
|
304
|
+
```python
|
|
305
|
+
from hypercorn.middleware import ProxyFixMiddleware
|
|
306
|
+
|
|
307
|
+
# trusted_hops MUST equal your real proxy-chain length (see warning below).
|
|
308
|
+
app.server.asgi_app = ProxyFixMiddleware(app.server.asgi_app, mode="modern", trusted_hops=1)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**FastAPI / Quart on uvicorn:** uvicorn restores the scheme (`--proxy-headers
|
|
312
|
+
--forwarded-allow-ips=...`) but **not** the host. Either have your proxy overwrite the
|
|
313
|
+
`Host` header with the public host, or add a small trusted ASGI middleware that copies
|
|
314
|
+
`X-Forwarded-Host` onto the `host` header — same `trusted_hops` discipline as above.
|
|
315
|
+
|
|
316
|
+
> ⚠️ Only restore proxy-header trust when a real proxy sets those headers, and set the
|
|
317
|
+
> hop counts to the actual chain length. A trusted-host middleware in front of *no*
|
|
318
|
+
> proxy lets a client spoof the host again — which is exactly the trust that was removed.
|
|
319
|
+
|
|
264
320
|
#### Multiple OIDC Providers
|
|
265
321
|
|
|
266
322
|
For multiple OIDC providers, you can use `register_provider` to add new ones after the OIDCAuth has been instantiated.
|
|
@@ -477,7 +533,7 @@ The following utilities are defined:
|
|
|
477
533
|
* `protected_callback`: A callback that only runs if the user is authenticated
|
|
478
534
|
and with the right group permissions.
|
|
479
535
|
|
|
480
|
-
NOTE: user info is stored in the session so make sure you define a secret_key on the
|
|
536
|
+
NOTE: user info is stored in the session so make sure you define a secret_key on the server
|
|
481
537
|
to use this feature.
|
|
482
538
|
|
|
483
539
|
If you wish to use this feature with BasicAuth, you will need to define the groups for individual
|
|
@@ -494,7 +550,7 @@ USER_PWD = {
|
|
|
494
550
|
BasicAuth(
|
|
495
551
|
app,
|
|
496
552
|
USER_PWD,
|
|
497
|
-
user_groups={"
|
|
553
|
+
user_groups={"username": ["group1", "group2"], "user2": ["group2"]},
|
|
498
554
|
secret_key="Test!",
|
|
499
555
|
)
|
|
500
556
|
|
|
@@ -15,7 +15,7 @@ License: MIT
|
|
|
15
15
|
|
|
16
16
|
## Feature overview
|
|
17
17
|
|
|
18
|
-
How this fork compares to upstream [`dash-auth`](https://github.com/plotly/dash-auth). The headline difference is async: upstream is Flask-only, while `dash-auth-async` adds the Quart
|
|
18
|
+
How this fork compares to upstream [`dash-auth`](https://github.com/plotly/dash-auth). The headline difference is async: upstream is Flask-only, while `dash-auth-async` adds async callback support, the Quart and FastAPI backends, authenticated WebSocket callbacks, and a pluggable backend abstraction.
|
|
19
19
|
|
|
20
20
|
| Capability | `dash-auth` (upstream) | `dash-auth-async` |
|
|
21
21
|
| --- | :---: | :---: |
|
|
@@ -31,9 +31,9 @@ How this fork compares to upstream [`dash-auth`](https://github.com/plotly/dash-
|
|
|
31
31
|
|
|
32
32
|
<sup>1</sup> `detect_backend` resolves Flask/Quart/FastAPI automatically; any other server is supported by supplying your own `Backend` instance.
|
|
33
33
|
|
|
34
|
-
<sup>2</sup>
|
|
34
|
+
<sup>2</sup> Supported on **every** backend, Flask included — you don't need Quart or FastAPI, just the `async` extra (bundled as `dash-auth-async[async]`, which pulls in `dash[async]`).
|
|
35
35
|
|
|
36
|
-
<sup>3</sup> Provided by the Quart and FastAPI backends. WebSocket auth is a no-op on Flask, which has no WebSocket callback transport.
|
|
36
|
+
<sup>3</sup> Provided by the Quart and FastAPI backends only. WebSocket auth is a no-op on Flask, which has no WebSocket callback transport.
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
For local testing, install [uv](https://docs.astral.sh/uv/getting-started/installation/), then install the dev dependencies and run individual tests:
|
|
@@ -216,6 +216,62 @@ auth.register_provider(
|
|
|
216
216
|
|
|
217
217
|
Once this is done, connecting to your app will automatically redirect to the IDP login page.
|
|
218
218
|
|
|
219
|
+
#### Running behind a reverse proxy
|
|
220
|
+
|
|
221
|
+
> **Behavior change.** Earlier versions rewrote the OIDC callback host from the
|
|
222
|
+
> client-supplied `X-Forwarded-Host` header. That header trust was **removed** — an
|
|
223
|
+
> attacker could set it to steer the `redirect_uri` handed to your IDP (auth-code leak /
|
|
224
|
+
> open redirect). The `redirect_uri` is now built **only** from the host and scheme of
|
|
225
|
+
> the incoming request.
|
|
226
|
+
|
|
227
|
+
The consequence: behind a proxy that terminates TLS or rewrites the host, the
|
|
228
|
+
`redirect_uri` comes out as `http://localhost:8050/...` and your IDP rejects it. To get
|
|
229
|
+
the real public host and scheme back, **restore it at the transport layer** — where the
|
|
230
|
+
trust can be bounded to your actual proxy, instead of trusting any client.
|
|
231
|
+
|
|
232
|
+
Two separate things to restore: **scheme** (http→https) and **host**. Most app servers
|
|
233
|
+
forward the scheme but **not** the host — `--forwarded-allow-ips` / `--proxy-headers`
|
|
234
|
+
only governs `X-Forwarded-Proto`/`-For`, never the host. So:
|
|
235
|
+
|
|
236
|
+
* **Scheme:** set `force_https_callback=True` on `OIDCAuth` (or pass the name of an env
|
|
237
|
+
var that, when present, enables it). This covers the http→https half on every backend.
|
|
238
|
+
* **Host:** add proxy middleware that honours `X-Forwarded-Host`, sized to your real
|
|
239
|
+
proxy-chain length:
|
|
240
|
+
|
|
241
|
+
| Backend | Server(s) | How to restore the host |
|
|
242
|
+
|---|---|---|
|
|
243
|
+
| **Flask** | gunicorn, waitress, mod_wsgi, … | `werkzeug` `ProxyFix` on the WSGI app (server-independent — gunicorn alone won't do the host) |
|
|
244
|
+
| **Quart** | hypercorn | `ProxyFixMiddleware(mode="modern", trusted_hops=N)` — restores host and scheme |
|
|
245
|
+
| **Quart / FastAPI** | uvicorn | uvicorn `--proxy-headers` does scheme only; add an `X-Forwarded-Host` ASGI middleware or have the proxy rewrite the `Host` header |
|
|
246
|
+
|
|
247
|
+
**Flask** (WSGI — gunicorn, waitress, …):
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
251
|
+
|
|
252
|
+
# Counts MUST equal your real proxy-chain length — setting them higher than the
|
|
253
|
+
# actual chain (or enabling this with no proxy) re-opens the spoofing hole.
|
|
254
|
+
app.server.wsgi_app = ProxyFix(app.server.wsgi_app, x_for=1, x_proto=1, x_host=1)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**Quart** (served by hypercorn) — wrap the ASGI app:
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
from hypercorn.middleware import ProxyFixMiddleware
|
|
261
|
+
|
|
262
|
+
# trusted_hops MUST equal your real proxy-chain length (see warning below).
|
|
263
|
+
app.server.asgi_app = ProxyFixMiddleware(app.server.asgi_app, mode="modern", trusted_hops=1)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**FastAPI / Quart on uvicorn:** uvicorn restores the scheme (`--proxy-headers
|
|
267
|
+
--forwarded-allow-ips=...`) but **not** the host. Either have your proxy overwrite the
|
|
268
|
+
`Host` header with the public host, or add a small trusted ASGI middleware that copies
|
|
269
|
+
`X-Forwarded-Host` onto the `host` header — same `trusted_hops` discipline as above.
|
|
270
|
+
|
|
271
|
+
> ⚠️ Only restore proxy-header trust when a real proxy sets those headers, and set the
|
|
272
|
+
> hop counts to the actual chain length. A trusted-host middleware in front of *no*
|
|
273
|
+
> proxy lets a client spoof the host again — which is exactly the trust that was removed.
|
|
274
|
+
|
|
219
275
|
#### Multiple OIDC Providers
|
|
220
276
|
|
|
221
277
|
For multiple OIDC providers, you can use `register_provider` to add new ones after the OIDCAuth has been instantiated.
|
|
@@ -432,7 +488,7 @@ The following utilities are defined:
|
|
|
432
488
|
* `protected_callback`: A callback that only runs if the user is authenticated
|
|
433
489
|
and with the right group permissions.
|
|
434
490
|
|
|
435
|
-
NOTE: user info is stored in the session so make sure you define a secret_key on the
|
|
491
|
+
NOTE: user info is stored in the session so make sure you define a secret_key on the server
|
|
436
492
|
to use this feature.
|
|
437
493
|
|
|
438
494
|
If you wish to use this feature with BasicAuth, you will need to define the groups for individual
|
|
@@ -449,7 +505,7 @@ USER_PWD = {
|
|
|
449
505
|
BasicAuth(
|
|
450
506
|
app,
|
|
451
507
|
USER_PWD,
|
|
452
|
-
user_groups={"
|
|
508
|
+
user_groups={"username": ["group1", "group2"], "user2": ["group2"]},
|
|
453
509
|
secret_key="Test!",
|
|
454
510
|
)
|
|
455
511
|
|
|
@@ -119,9 +119,13 @@ class BasicAuth(Auth):
|
|
|
119
119
|
return False
|
|
120
120
|
else:
|
|
121
121
|
stored_password = self._users.get(username)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
# Run a constant-time comparison even when the username is unknown
|
|
123
|
+
# (compare `password` against itself, then discard the result) so
|
|
124
|
+
# response timing doesn't reveal which usernames exist.
|
|
125
|
+
reference = stored_password if stored_password is not None else password
|
|
126
|
+
authorized = hmac.compare_digest(reference, password) and (
|
|
127
|
+
stored_password is not None
|
|
128
|
+
)
|
|
125
129
|
if authorized:
|
|
126
130
|
try:
|
|
127
131
|
self.session["user"] = {"email": username, "groups": []}
|
|
@@ -249,21 +249,21 @@ class OIDCAuth(Auth):
|
|
|
249
249
|
def _create_redirect_uri(self, idp: str):
|
|
250
250
|
"""Create the redirect uri based on callback endpoint and idp.
|
|
251
251
|
|
|
252
|
+
Host and scheme come from the request scope only. Behind a proxy,
|
|
253
|
+
configure the WSGI/ASGI server to populate them from forwarded headers
|
|
254
|
+
(werkzeug ``ProxyFix`` / hypercorn ``--forwarded-allow-ips``) — the
|
|
255
|
+
library must never trust a client-supplied ``X-Forwarded-Host`` to
|
|
256
|
+
build the IdP ``redirect_uri`` (auth-code leak / open redirect).
|
|
257
|
+
``force_https_callback`` covers the scheme half of dash-auth#154.
|
|
258
|
+
|
|
252
259
|
Returns:
|
|
253
260
|
The fully-qualified OIDC callback redirect URI.
|
|
254
261
|
"""
|
|
255
262
|
if self.force_https_callback:
|
|
256
|
-
|
|
263
|
+
return self.backend.url_for(
|
|
257
264
|
"oidc_callback", idp=idp, _external=True, _scheme="https"
|
|
258
265
|
)
|
|
259
|
-
|
|
260
|
-
redirect_uri = self.backend.url_for(
|
|
261
|
-
"oidc_callback", idp=idp, _external=True
|
|
262
|
-
)
|
|
263
|
-
host = self.request.headers.get("X-Forwarded-Host")
|
|
264
|
-
if host:
|
|
265
|
-
redirect_uri = redirect_uri.replace(self.backend.current_host(), host, 1)
|
|
266
|
-
return redirect_uri
|
|
266
|
+
return self.backend.url_for("oidc_callback", idp=idp, _external=True)
|
|
267
267
|
|
|
268
268
|
def login_request(self, idp: str | None = None):
|
|
269
269
|
"""Start the login process.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"""Public route and callback registration for unauthenticated access."""
|
|
2
2
|
|
|
3
|
-
import inspect
|
|
4
3
|
import os
|
|
5
4
|
|
|
6
5
|
from dash import Dash, callback, get_app
|
|
7
6
|
|
|
8
|
-
#
|
|
9
|
-
|
|
7
|
+
# create_callback_id is the same helper Dash uses internally to key its
|
|
8
|
+
# callback map; no public API equivalent exists.
|
|
9
|
+
from dash._utils import create_callback_id # noqa: PLC2701
|
|
10
|
+
from dash.dependencies import handle_callback_args
|
|
10
11
|
from werkzeug.routing import Map, MapAdapter, Rule
|
|
11
12
|
|
|
12
13
|
from .backends import detect_backend
|
|
@@ -99,14 +100,17 @@ def public_callback(*callback_args, **callback_kwargs):
|
|
|
99
100
|
|
|
100
101
|
def decorator(func):
|
|
101
102
|
wrapped_func = callback(*callback_args, **callback_kwargs)(func)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
# Derive the callback id straight from the output specs, exactly as
|
|
104
|
+
# Dash does internally (create_callback_id). This is deterministic and
|
|
105
|
+
# independent of GLOBAL_CALLBACK_MAP state -- unlike diffing the map,
|
|
106
|
+
# which yields no new key when the same output id was already
|
|
107
|
+
# registered (re-runs, or several apps sharing one process), and unlike
|
|
108
|
+
# source-text comparison, which mis-whitelists callbacks sharing a body
|
|
109
|
+
# and raises on lambdas/REPL-defined functions.
|
|
110
|
+
output, inputs, _state, _prevent = handle_callback_args(
|
|
111
|
+
callback_args, callback_kwargs
|
|
109
112
|
)
|
|
113
|
+
callback_id = create_callback_id(output, inputs, no_output=not output)
|
|
110
114
|
try:
|
|
111
115
|
app = get_app()
|
|
112
116
|
backend = detect_backend(app.server)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dash-auth-async
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.3
|
|
4
4
|
Summary: Dash Authorization Package.
|
|
5
5
|
Author-email: Jonas Schrage <119843859+joschrag@users.noreply.github.com>
|
|
6
6
|
License: MIT
|
|
@@ -40,7 +40,7 @@ Provides-Extra: quart
|
|
|
40
40
|
Requires-Dist: dash[quart]>=4.2.0; extra == "quart"
|
|
41
41
|
Requires-Dist: httpx>=0.23.0; extra == "quart"
|
|
42
42
|
Provides-Extra: async
|
|
43
|
-
Requires-Dist: dash[async]>=
|
|
43
|
+
Requires-Dist: dash[async]>=3.1.0; extra == "async"
|
|
44
44
|
Dynamic: license-file
|
|
45
45
|
|
|
46
46
|
## Dash Authorization and Login
|
|
@@ -60,7 +60,7 @@ License: MIT
|
|
|
60
60
|
|
|
61
61
|
## Feature overview
|
|
62
62
|
|
|
63
|
-
How this fork compares to upstream [`dash-auth`](https://github.com/plotly/dash-auth). The headline difference is async: upstream is Flask-only, while `dash-auth-async` adds the Quart
|
|
63
|
+
How this fork compares to upstream [`dash-auth`](https://github.com/plotly/dash-auth). The headline difference is async: upstream is Flask-only, while `dash-auth-async` adds async callback support, the Quart and FastAPI backends, authenticated WebSocket callbacks, and a pluggable backend abstraction.
|
|
64
64
|
|
|
65
65
|
| Capability | `dash-auth` (upstream) | `dash-auth-async` |
|
|
66
66
|
| --- | :---: | :---: |
|
|
@@ -76,9 +76,9 @@ How this fork compares to upstream [`dash-auth`](https://github.com/plotly/dash-
|
|
|
76
76
|
|
|
77
77
|
<sup>1</sup> `detect_backend` resolves Flask/Quart/FastAPI automatically; any other server is supported by supplying your own `Backend` instance.
|
|
78
78
|
|
|
79
|
-
<sup>2</sup>
|
|
79
|
+
<sup>2</sup> Supported on **every** backend, Flask included — you don't need Quart or FastAPI, just the `async` extra (bundled as `dash-auth-async[async]`, which pulls in `dash[async]`).
|
|
80
80
|
|
|
81
|
-
<sup>3</sup> Provided by the Quart and FastAPI backends. WebSocket auth is a no-op on Flask, which has no WebSocket callback transport.
|
|
81
|
+
<sup>3</sup> Provided by the Quart and FastAPI backends only. WebSocket auth is a no-op on Flask, which has no WebSocket callback transport.
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
For local testing, install [uv](https://docs.astral.sh/uv/getting-started/installation/), then install the dev dependencies and run individual tests:
|
|
@@ -261,6 +261,62 @@ auth.register_provider(
|
|
|
261
261
|
|
|
262
262
|
Once this is done, connecting to your app will automatically redirect to the IDP login page.
|
|
263
263
|
|
|
264
|
+
#### Running behind a reverse proxy
|
|
265
|
+
|
|
266
|
+
> **Behavior change.** Earlier versions rewrote the OIDC callback host from the
|
|
267
|
+
> client-supplied `X-Forwarded-Host` header. That header trust was **removed** — an
|
|
268
|
+
> attacker could set it to steer the `redirect_uri` handed to your IDP (auth-code leak /
|
|
269
|
+
> open redirect). The `redirect_uri` is now built **only** from the host and scheme of
|
|
270
|
+
> the incoming request.
|
|
271
|
+
|
|
272
|
+
The consequence: behind a proxy that terminates TLS or rewrites the host, the
|
|
273
|
+
`redirect_uri` comes out as `http://localhost:8050/...` and your IDP rejects it. To get
|
|
274
|
+
the real public host and scheme back, **restore it at the transport layer** — where the
|
|
275
|
+
trust can be bounded to your actual proxy, instead of trusting any client.
|
|
276
|
+
|
|
277
|
+
Two separate things to restore: **scheme** (http→https) and **host**. Most app servers
|
|
278
|
+
forward the scheme but **not** the host — `--forwarded-allow-ips` / `--proxy-headers`
|
|
279
|
+
only governs `X-Forwarded-Proto`/`-For`, never the host. So:
|
|
280
|
+
|
|
281
|
+
* **Scheme:** set `force_https_callback=True` on `OIDCAuth` (or pass the name of an env
|
|
282
|
+
var that, when present, enables it). This covers the http→https half on every backend.
|
|
283
|
+
* **Host:** add proxy middleware that honours `X-Forwarded-Host`, sized to your real
|
|
284
|
+
proxy-chain length:
|
|
285
|
+
|
|
286
|
+
| Backend | Server(s) | How to restore the host |
|
|
287
|
+
|---|---|---|
|
|
288
|
+
| **Flask** | gunicorn, waitress, mod_wsgi, … | `werkzeug` `ProxyFix` on the WSGI app (server-independent — gunicorn alone won't do the host) |
|
|
289
|
+
| **Quart** | hypercorn | `ProxyFixMiddleware(mode="modern", trusted_hops=N)` — restores host and scheme |
|
|
290
|
+
| **Quart / FastAPI** | uvicorn | uvicorn `--proxy-headers` does scheme only; add an `X-Forwarded-Host` ASGI middleware or have the proxy rewrite the `Host` header |
|
|
291
|
+
|
|
292
|
+
**Flask** (WSGI — gunicorn, waitress, …):
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
296
|
+
|
|
297
|
+
# Counts MUST equal your real proxy-chain length — setting them higher than the
|
|
298
|
+
# actual chain (or enabling this with no proxy) re-opens the spoofing hole.
|
|
299
|
+
app.server.wsgi_app = ProxyFix(app.server.wsgi_app, x_for=1, x_proto=1, x_host=1)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**Quart** (served by hypercorn) — wrap the ASGI app:
|
|
303
|
+
|
|
304
|
+
```python
|
|
305
|
+
from hypercorn.middleware import ProxyFixMiddleware
|
|
306
|
+
|
|
307
|
+
# trusted_hops MUST equal your real proxy-chain length (see warning below).
|
|
308
|
+
app.server.asgi_app = ProxyFixMiddleware(app.server.asgi_app, mode="modern", trusted_hops=1)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**FastAPI / Quart on uvicorn:** uvicorn restores the scheme (`--proxy-headers
|
|
312
|
+
--forwarded-allow-ips=...`) but **not** the host. Either have your proxy overwrite the
|
|
313
|
+
`Host` header with the public host, or add a small trusted ASGI middleware that copies
|
|
314
|
+
`X-Forwarded-Host` onto the `host` header — same `trusted_hops` discipline as above.
|
|
315
|
+
|
|
316
|
+
> ⚠️ Only restore proxy-header trust when a real proxy sets those headers, and set the
|
|
317
|
+
> hop counts to the actual chain length. A trusted-host middleware in front of *no*
|
|
318
|
+
> proxy lets a client spoof the host again — which is exactly the trust that was removed.
|
|
319
|
+
|
|
264
320
|
#### Multiple OIDC Providers
|
|
265
321
|
|
|
266
322
|
For multiple OIDC providers, you can use `register_provider` to add new ones after the OIDCAuth has been instantiated.
|
|
@@ -477,7 +533,7 @@ The following utilities are defined:
|
|
|
477
533
|
* `protected_callback`: A callback that only runs if the user is authenticated
|
|
478
534
|
and with the right group permissions.
|
|
479
535
|
|
|
480
|
-
NOTE: user info is stored in the session so make sure you define a secret_key on the
|
|
536
|
+
NOTE: user info is stored in the session so make sure you define a secret_key on the server
|
|
481
537
|
to use this feature.
|
|
482
538
|
|
|
483
539
|
If you wish to use this feature with BasicAuth, you will need to define the groups for individual
|
|
@@ -494,7 +550,7 @@ USER_PWD = {
|
|
|
494
550
|
BasicAuth(
|
|
495
551
|
app,
|
|
496
552
|
USER_PWD,
|
|
497
|
-
user_groups={"
|
|
553
|
+
user_groups={"username": ["group1", "group2"], "user2": ["group2"]},
|
|
498
554
|
secret_key="Test!",
|
|
499
555
|
)
|
|
500
556
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "dash-auth-async"
|
|
7
|
-
version = "1.3.
|
|
7
|
+
version = "1.3.3"
|
|
8
8
|
description = "Dash Authorization Package."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -45,7 +45,7 @@ dependencies = [
|
|
|
45
45
|
[project.optional-dependencies]
|
|
46
46
|
fastapi = ["dash[fastapi]>=4.2.0"]
|
|
47
47
|
quart = ["dash[quart]>=4.2.0","httpx>=0.23.0"]
|
|
48
|
-
async = ["dash[async]>=
|
|
48
|
+
async = ["dash[async]>=3.1.0"]
|
|
49
49
|
|
|
50
50
|
[project.urls]
|
|
51
51
|
Homepage = "https://github.com/joschrag/dash-auth-async"
|
|
@@ -102,13 +102,6 @@ preview = true
|
|
|
102
102
|
select = ["FAST","I","D","DOC","PL","UP","PERF","RUF"]
|
|
103
103
|
|
|
104
104
|
[tool.ruff.lint.per-file-ignores]
|
|
105
|
-
# Examples are runnable demos, not shipped library code (setuptools only
|
|
106
|
-
# packages dash_auth_async*). Like tests, they read better without forced
|
|
107
|
-
# docstring coverage on every demo page/callback.
|
|
108
|
-
"examples/**" = [
|
|
109
|
-
"D", # demo scripts don't need module/function docstrings
|
|
110
|
-
"DOC", # ...nor docstring sections (Returns, etc.)
|
|
111
|
-
]
|
|
112
105
|
# Tests are self-describing and have different idioms than library code:
|
|
113
106
|
"tests/**" = [
|
|
114
107
|
"D", # don't require docstrings on every test/fixture/module
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dash_auth_async-1.3.1 → dash_auth_async-1.3.3}/dash_auth_async.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|