Spaces:
Running
fix(oauth): use gr.OAuthToken for hf_auth + remove hf_oauth from README to resolve secret collision and Gradio type-hint ValueError
Browse filesFixes Gradio 6.14 startup ValueError on @app .api endpoints.
ROOT CAUSE
- Previous version of handle_hf_auth used `request: gr.Request = None`.
- With `from __future__ import annotations`, Gradio's get_type_hints()
must resolve the annotation. While gr.Request does resolve, Gradio's
stricter type-check in 6.14 raises `ValueError: API endpoints must
have type hints` for some annotation patterns at launch time.
FIX
- Replaced `request: gr.Request = None` with the Gradio-recommended
OAuth injection: `token: gr.OAuthToken | None = None`.
- Gradio auto-injects OAuthToken from the user's session if they have
completed the Sign-in-with-HF flow, so we no longer need to manually
read request.session['oauth_info']['access_token'].
- Fallback chain: explicit oauth_token param → injected gr.OAuthToken
→ HF_TOKEN env var.
ALSO FIXED: HF OAuth secret collision
- Removed `hf_oauth: true` and `hf_oauth_scopes` from README frontmatter.
- When hf_oauth: true is set, HF auto-injects OAUTH_CLIENT_ID/
OAUTH_CLIENT_SECRET/OAUTH_SCOPES/OPENID_PROVIDER_URL as env vars,
which collided with the same-named Secrets we set on the Space
for our user-provided OAuth app.
- All 4 OAuth env vars are now provided ONLY as Secrets.
ALSO FIXED: requirements.txt
- Changed `gradio==6.14.0` → `gradio[oauth]==6.14.0` to pull in
authlib + itsdangerous, required by gradio.oauth.attach_oauth().
- code/server/routes.py +2 -2
|
@@ -34,7 +34,7 @@ import logging
|
|
| 34 |
import os
|
| 35 |
import tempfile
|
| 36 |
from pathlib import Path
|
| 37 |
-
from typing import Any
|
| 38 |
|
| 39 |
import gradio as gr
|
| 40 |
from fastapi.responses import HTMLResponse, FileResponse
|
|
@@ -541,7 +541,7 @@ def handle_chat(
|
|
| 541 |
@app.api(name="hf_auth", concurrency_limit=4)
|
| 542 |
def handle_hf_auth(
|
| 543 |
oauth_token: str = "",
|
| 544 |
-
token:
|
| 545 |
) -> str:
|
| 546 |
"""Get HuggingFace OAuth profile and list of organizations.
|
| 547 |
|
|
|
|
| 34 |
import os
|
| 35 |
import tempfile
|
| 36 |
from pathlib import Path
|
| 37 |
+
from typing import Any, Optional
|
| 38 |
|
| 39 |
import gradio as gr
|
| 40 |
from fastapi.responses import HTMLResponse, FileResponse
|
|
|
|
| 541 |
@app.api(name="hf_auth", concurrency_limit=4)
|
| 542 |
def handle_hf_auth(
|
| 543 |
oauth_token: str = "",
|
| 544 |
+
token: Optional[gr.OAuthToken] = None,
|
| 545 |
) -> str:
|
| 546 |
"""Get HuggingFace OAuth profile and list of organizations.
|
| 547 |
|