Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastAPI service example - Authorization header not sent in subsequent requests #4656

Open
aktech opened this issue Dec 8, 2023 · 2 comments

Comments

@aktech
Copy link
Contributor

aktech commented Dec 8, 2023

Bug description

The FastAPI service example doesn't works as expected. After you authorize the service by OAuth2 using the Authorize button in swagger, http://127.0.0.1:8000/services/fastapi/docs the endpoints works, but when you refresh the page the endpoint doesn't works.

The problem I am more interested in is the Authorization header is not sent in the subsequent requests (after you refresh the page once) when you have authorized the app via Authorize button in swagger.

There is another problem in the User model here (for authorized requests obv) isn't correct for the response type. This can be fixed by simply setting default values for some of the required fields.

I have attached a video walkthrough:

jupyterhub-fastapi.mp4

How to reproduce

  1. Go to http://127.0.0.1:8000/services/fastapi/docs
  2. Click on Authorize
  3. Refresh Page
  4. Try any APIs, example: http://127.0.0.1:8000/services/fastapi/me
  5. See error:
{"detail": "Must login with token parameter or Authorization bearer header"}

Expected behaviour

I would expect the subsequent requests to be authorized and return the valid response instead of 400.

Actual behaviour

Your personal set up

  • OS: macOS 12.3
  • Version(s): 4.0.2
Full environment
# packages in environment at /Users/aktech/miniconda3/envs/jhub-apps-dev:
#
# Name                    Version                   Build  Channel
aiofiles                  23.2.1                   pypi_0    pypi
aiohttp                   3.8.5           py311h80987f9_0  
aiosignal                 1.2.0              pyhd3eb1b0_0  
alembic                   1.8.1           py311hca03da5_0  
altair                    5.1.2              pyhd8ed1ab_0    conda-forge
annotated-types           0.6.0                    pypi_0    pypi
ansi2html                 1.8.0           py311hca03da5_0  
anyio                     3.7.1                    pypi_0    pypi
appnope                   0.1.2           py311hca03da5_1001  
argon2-cffi               21.3.0             pyhd3eb1b0_0  
argon2-cffi-bindings      21.2.0          py311h80987f9_0  
asttokens                 2.0.5              pyhd3eb1b0_0  
async-lru                 2.0.4              pyhd8ed1ab_0    conda-forge
async-timeout             4.0.2           py311hca03da5_0  
async_generator           1.10               pyhd3eb1b0_0  
attrs                     23.1.0          py311hca03da5_0  
aws-c-auth                0.7.4                h3e84773_2    conda-forge
aws-c-cal                 0.6.2                h12c43c8_2    conda-forge
aws-c-common              0.9.3                hb547adb_0    conda-forge
aws-c-compression         0.2.17               h12c43c8_3    conda-forge
aws-c-event-stream        0.3.2                h8f67f9a_2    conda-forge
aws-c-http                0.7.13               h7dae168_2    conda-forge
aws-c-io                  0.13.33              h5bd1e48_0    conda-forge
aws-c-mqtt                0.9.7                h9e52e49_0    conda-forge
aws-c-s3                  0.3.17               h29c26b6_4    conda-forge
aws-c-sdkutils            0.1.12               h12c43c8_2    conda-forge
aws-checksums             0.1.17               h12c43c8_2    conda-forge
aws-crt-cpp               0.24.2               hbe5f050_2    conda-forge
aws-sdk-cpp               1.11.156             ha282cf0_4    conda-forge
babel                     2.11.0          py311hca03da5_0  
backcall                  0.2.0              pyhd3eb1b0_0  
beautifulsoup4            4.12.2          py311hca03da5_0  
black                     23.10.1         py311h267d04e_0    conda-forge
bleach                    4.1.0              pyhd3eb1b0_0  
blinker                   1.6.2           py311hca03da5_0  
bokeh                     3.3.0              pyhd8ed1ab_0    conda-forge
bokeh-root-cmd            0.1.2              pyhd8ed1ab_0    conda-forge
bottleneck                1.3.5           py311ha0d4635_0  
brotli-python             1.0.9           py311h313beb8_7  
bzip2                     1.0.8                h620ffc9_4  
c-ares                    1.19.1               h80987f9_0  
ca-certificates           2023.11.17           hf0a4a13_0    conda-forge
cachetools                5.3.2              pyhd8ed1ab_0    conda-forge
certifi                   2023.11.17         pyhd8ed1ab_0    conda-forge
certipy                   0.1.3              pyhd3eb1b0_0  
cffi                      1.15.1          py311h80987f9_3  
charset-normalizer        2.0.4              pyhd3eb1b0_0  
click                     8.1.7           py311hca03da5_0  
colorama                  0.4.6           py311hca03da5_0  
comm                      0.1.2           py311hca03da5_0  
configurable-http-proxy   4.6.0                hb67532b_0    conda-forge
contourpy                 1.0.5           py311h48ca7d4_0  
cryptography              41.0.3          py311hd4332d6_0  
cycler                    0.12.1                   pypi_0    pypi
dash                      2.14.1             pyhd8ed1ab_0    conda-forge
debugpy                   1.6.7           py311h313beb8_0  
decorator                 5.1.1              pyhd3eb1b0_0  
defusedxml                0.7.1              pyhd3eb1b0_0  
distlib                   0.3.7                    pypi_0    pypi
editables                 0.5                      pypi_0    pypi
entrypoints               0.4             py311hca03da5_0  
escapism                  1.0.1                    pypi_0    pypi
exceptiongroup            1.0.4           py311hca03da5_0  
executing                 0.8.3              pyhd3eb1b0_0  
fastapi                   0.104.1                  pypi_0    pypi
ffmpy                     0.3.1                    pypi_0    pypi
filelock                  3.13.0                   pypi_0    pypi
flask                     3.0.0              pyhd8ed1ab_0    conda-forge
fonttools                 4.43.1                   pypi_0    pypi
freetype                  2.12.1               h1192e45_0  
frozenlist                1.3.3           py311h80987f9_0  
fsspec                    2023.10.0                pypi_0    pypi
gflags                    2.2.2             hc88da5d_1004    conda-forge
giflib                    5.2.1                h80987f9_3  
gitdb                     4.0.11             pyhd8ed1ab_0    conda-forge
gitpython                 3.1.40             pyhd8ed1ab_0    conda-forge
glog                      0.6.0                h6da1cb0_0    conda-forge
gradio                    3.50.2                   pypi_0    pypi
gradio-client             0.6.1                    pypi_0    pypi
greenlet                  3.0.1           py311hbaf5611_0    conda-forge
h11                       0.14.0                   pypi_0    pypi
hatch                     1.7.0                    pypi_0    pypi
hatchling                 1.18.0                   pypi_0    pypi
httpcore                  0.18.0                   pypi_0    pypi
httpx                     0.25.0                   pypi_0    pypi
huggingface-hub           0.18.0                   pypi_0    pypi
hyperlink                 21.0.0                   pypi_0    pypi
icu                       73.2                 hc8870d7_0    conda-forge
idna                      3.4             py311hca03da5_0  
importlib-metadata        6.0.0           py311hca03da5_0  
importlib_metadata        6.0.0                hd3eb1b0_0  
importlib_resources       6.1.0           py311hca03da5_0  
iniconfig                 1.1.1              pyhd3eb1b0_0  
ipdb                      0.13.13                  pypi_0    pypi
ipykernel                 6.25.0          py311hb6e6a13_0  
ipython                   8.15.0          py311hca03da5_0  
ipython-genutils          0.2.0                    pypi_0    pypi
ipywidgets                8.0.4           py311hca03da5_0  
itsdangerous              2.1.2              pyhd8ed1ab_0    conda-forge
jaraco-classes            3.3.0                    pypi_0    pypi
jedi                      0.18.1          py311hca03da5_1  
jhsingle-native-proxy     0.8.1              pyhd8ed1ab_0    conda-forge
jhub-apps                 0.1                      pypi_0    pypi
jinja2                    3.1.2           py311hca03da5_0  
jpeg                      9e                   h80987f9_1  
json5                     0.9.6              pyhd3eb1b0_0  
jsonschema                4.19.1             pyhd8ed1ab_0    conda-forge
jsonschema-specifications 2023.7.1           pyhd8ed1ab_0    conda-forge
jupyter                   1.0.0           py311h267d04e_9    conda-forge
jupyter-lsp               2.2.0              pyhd8ed1ab_0    conda-forge
jupyter_client            8.1.0           py311hca03da5_0  
jupyter_console           6.6.3           py311hca03da5_0  
jupyter_core              5.3.0           py311hca03da5_0  
jupyter_events            0.6.3           py311hca03da5_0  
jupyter_server            2.5.0           py311hca03da5_0  
jupyter_server_terminals  0.4.4           py311hca03da5_1  
jupyter_telemetry         0.1.0                      py_0  
jupyterhub                4.0.2              pyh31011fe_0    conda-forge
jupyterhub-base           4.0.2              pyh31011fe_0    conda-forge
jupyterhub-kubespawner    6.1.0                    pypi_0    pypi
jupyterlab                4.0.7              pyhd8ed1ab_0    conda-forge
jupyterlab_pygments       0.1.2                      py_0  
jupyterlab_server         2.25.0             pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        3.0.9              pyhd8ed1ab_0    conda-forge
keyring                   24.2.0                   pypi_0    pypi
kiwisolver                1.4.5                    pypi_0    pypi
krb5                      1.20.1               hf3e1bf2_1  
kubernetes-asyncio        28.2.1                   pypi_0    pypi
lcms2                     2.12                 hba8e193_0  
lerc                      3.0                  hc377ac9_0  
libabseil                 20230802.1      cxx17_h13dd4ca_0    conda-forge
libarrow                  13.0.0           h5325880_8_cpu    conda-forge
libblas                   3.9.0           19_osxarm64_openblas    conda-forge
libbrotlicommon           1.1.0                hb547adb_1    conda-forge
libbrotlidec              1.1.0                hb547adb_1    conda-forge
libbrotlienc              1.1.0                hb547adb_1    conda-forge
libcblas                  3.9.0           19_osxarm64_openblas    conda-forge
libcrc32c                 1.1.2                hbdafb3b_0    conda-forge
libcurl                   8.4.0                h3e2b118_0  
libcxx                    16.0.6               h4653b0c_0    conda-forge
libdeflate                1.17                 h80987f9_1  
libedit                   3.1.20221030         h80987f9_0  
libev                     4.33                 h1a28f6b_1  
libevent                  2.1.12               h2757513_1    conda-forge
libexpat                  2.5.0                hb7217d7_1    conda-forge
libffi                    3.4.4                hca03da5_0  
libgfortran               5.0.0           13_2_0_hd922786_1    conda-forge
libgfortran5              13.2.0               hf226fd6_1    conda-forge
libgoogle-cloud           2.12.0               h5a37b55_3    conda-forge
libgrpc                   1.58.1               h941e00e_0    conda-forge
libiconv                  1.16                 h1a28f6b_2  
liblapack                 3.9.0           19_osxarm64_openblas    conda-forge
libnghttp2                1.57.0               h62f6fdd_0  
libopenblas               0.3.24          openmp_hd76b1f2_0    conda-forge
libpng                    1.6.39               h80987f9_0  
libprotobuf               4.24.3               hf590ac1_1    conda-forge
libsodium                 1.0.18               h1a28f6b_0  
libsqlite                 3.43.2               h091b4b1_0    conda-forge
libssh2                   1.10.0               h02f6b3c_2  
libthrift                 0.19.0               h026a170_1    conda-forge
libtiff                   4.5.1                h313beb8_0  
libutf8proc               2.8.0                h1a8c8d9_0    conda-forge
libuv                     1.46.0               hb547adb_0    conda-forge
libwebp                   1.3.2                ha3663a8_0  
libwebp-base              1.3.2                h80987f9_0  
libxml2                   2.10.4               h0dcf63f_1  
libxslt                   1.1.37               h80987f9_1  
libzlib                   1.2.13               h53f4e23_5    conda-forge
linkify-it-py             2.0.0           py311hca03da5_0  
llvm-openmp               17.0.3               hcd81f8e_0    conda-forge
lxml                      4.9.3           py311h50ffb84_0  
lz4-c                     1.9.4                h313beb8_0  
mako                      1.2.3           py311hca03da5_0  
markdown                  3.4.1           py311hca03da5_0  
markdown-it-py            2.2.0           py311hca03da5_1  
markupsafe                2.1.1           py311h80987f9_0  
matplotlib                3.8.0                    pypi_0    pypi
matplotlib-inline         0.1.6           py311hca03da5_0  
mdit-py-plugins           0.3.0           py311hca03da5_0  
mdurl                     0.1.0           py311hca03da5_0  
mistune                   0.8.4           py311h80987f9_1000  
more-itertools            10.1.0                   pypi_0    pypi
multidict                 6.0.2           py311h80987f9_0  
mypy_extensions           1.0.0           py311hca03da5_0  
nbclient                  0.5.13          py311hca03da5_0  
nbconvert                 6.5.4           py311hca03da5_0  
nbformat                  5.9.2           py311hca03da5_0  
ncurses                   6.4                  h313beb8_0  
nest-asyncio              1.5.6           py311hca03da5_0  
nodejs                    20.8.1               h0950e01_0    conda-forge
notebook                  7.0.6              pyhd8ed1ab_0    conda-forge
notebook-shim             0.2.2           py311hca03da5_0  
numexpr                   2.8.7           py311h6dc990b_0  
numpy                     1.26.0          py311hb8f3215_0    conda-forge
oauthlib                  3.2.2           py311hca03da5_0  
openjpeg                  2.3.0                h7a6adac_2  
openssl                   3.2.0                h0d3ecfb_1    conda-forge
orc                       1.9.0                hcd02cb2_3    conda-forge
orjson                    3.9.10                   pypi_0    pypi
packaging                 23.1            py311hca03da5_0  
pamela                    1.0.0              pyhd3eb1b0_0  
pandas                    2.1.1           py311h7aedaa7_0  
pandocfilters             1.5.0              pyhd3eb1b0_0  
panel                     1.3.0              pyhd8ed1ab_0    conda-forge
param                     2.0.0           py311hca03da5_0  
parso                     0.8.3              pyhd3eb1b0_0  
pathspec                  0.10.3          py311hca03da5_0  
pexpect                   4.8.0              pyhd3eb1b0_3  
pickleshare               0.7.5           pyhd3eb1b0_1003  
pillow                    10.0.1          py311h3b245a6_0  
pip                       23.3.1             pyhd8ed1ab_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_1    conda-forge
platformdirs              3.10.0          py311hca03da5_0  
playwright                1.40.0                   pypi_0    pypi
plotly                    5.9.0           py311hca03da5_0  
plotlydash-tornado-cmd    0.0.6              pyhd8ed1ab_0    conda-forge
pluggy                    1.0.0           py311hca03da5_1  
prometheus_client         0.14.1          py311hca03da5_0  
prompt-toolkit            3.0.36          py311hca03da5_0  
prompt_toolkit            3.0.36               hd3eb1b0_0  
protobuf                  4.24.3          py311h4d1eceb_1    conda-forge
psutil                    5.9.0           py311h80987f9_0  
ptyprocess                0.7.0              pyhd3eb1b0_2  
pure_eval                 0.2.2              pyhd3eb1b0_0  
pyarrow                   13.0.0          py311hd7bc329_8_cpu    conda-forge
pycparser                 2.21               pyhd3eb1b0_0  
pycurl                    7.45.2          py311h02f6b3c_1  
pydantic                  2.4.2                    pypi_0    pypi
pydantic-core             2.10.1                   pypi_0    pypi
pydeck                    0.8.0              pyhd8ed1ab_0    conda-forge
pydub                     0.25.1                   pypi_0    pypi
pyee                      11.0.1                   pypi_0    pypi
pygments                  2.15.1          py311hca03da5_1  
pyjwt                     2.4.0           py311hca03da5_0  
pyopenssl                 23.2.0          py311hca03da5_0  
pyparsing                 3.1.1                    pypi_0    pypi
pyperclip                 1.8.2                    pypi_0    pypi
pysocks                   1.7.1           py311hca03da5_0  
pytest                    7.4.3              pyhd8ed1ab_0    conda-forge
pytest-base-url           2.0.0                    pypi_0    pypi
pytest-playwright         0.4.3                    pypi_0    pypi
python                    3.11.6          h47c9636_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd3eb1b0_0  
python-fastjsonschema     2.16.2          py311hca03da5_0  
python-json-logger        2.0.7           py311hca03da5_0  
python-multipart          0.0.6                    pypi_0    pypi
python-slugify            8.0.1                    pypi_0    pypi
python-tzdata             2023.3             pyhd3eb1b0_0  
python_abi                3.11                    4_cp311    conda-forge
pytz                      2023.3.post1    py311hca03da5_0  
pyviz_comms               2.3.0           py311hca03da5_0  
pyyaml                    6.0.1           py311h80987f9_0  
pyzmq                     25.1.0          py311h313beb8_0  
qtconsole                 5.4.4                    pypi_0    pypi
qtpy                      2.4.1                    pypi_0    pypi
re2                       2023.03.02           hc5e2d97_0    conda-forge
readline                  8.2                  h1a28f6b_0  
referencing               0.30.2             pyhd8ed1ab_0    conda-forge
requests                  2.31.0          py311hca03da5_0  
retrying                  1.3.3              pyhd3eb1b0_2  
rfc3339-validator         0.1.4           py311hca03da5_0  
rfc3986-validator         0.1.1           py311hca03da5_0  
rich                      13.6.0             pyhd8ed1ab_0    conda-forge
rpds-py                   0.10.6          py311h94f323b_0    conda-forge
ruamel.yaml               0.17.21         py311h80987f9_0  
ruff                      0.1.3                    pypi_0    pypi
semantic-version          2.10.0                   pypi_0    pypi
send2trash                1.8.0              pyhd3eb1b0_1  
setuptools                68.0.0          py311hca03da5_0  
shellingham               1.5.4                    pypi_0    pypi
simpervisor               0.4             py311hca03da5_0  
six                       1.16.0             pyhd3eb1b0_1  
smmap                     5.0.0              pyhd8ed1ab_0    conda-forge
snappy                    1.1.10               h17c5cce_0    conda-forge
sniffio                   1.2.0           py311hca03da5_1  
soupsieve                 2.5             py311hca03da5_0  
sqlalchemy                2.0.21          py311h80987f9_0  
stack_data                0.2.0              pyhd3eb1b0_0  
starlette                 0.27.0                   pypi_0    pypi
streamlit                 1.27.2             pyhd8ed1ab_1    conda-forge
tenacity                  8.2.2           py311hca03da5_0  
terminado                 0.17.1          py311hca03da5_0  
text-unidecode            1.3                      pypi_0    pypi
tinycss2                  1.2.1           py311hca03da5_0  
tk                        8.6.13               hb31c410_0    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     2.0.1           py311hca03da5_0  
tomli-w                   1.0.0                    pypi_0    pypi
tomlkit                   0.12.1                   pypi_0    pypi
toolz                     0.12.0             pyhd8ed1ab_0    conda-forge
tornado                   6.3.3           py311h80987f9_0  
tqdm                      4.65.0          py311hb6e6a13_0  
traitlets                 5.12.0             pyhd8ed1ab_0    conda-forge
trove-classifiers         2023.10.18               pypi_0    pypi
typing-extensions         4.8.0                hd8ed1ab_0    conda-forge
typing_extensions         4.8.0              pyha770c72_0    conda-forge
tzdata                    2023c                h04d1e81_0  
tzlocal                   5.2             py311h267d04e_0    conda-forge
uc-micro-py               1.0.1           py311hca03da5_0  
urllib3                   1.26.18         py311hca03da5_0  
userpath                  1.9.1                    pypi_0    pypi
uvicorn                   0.23.2                   pypi_0    pypi
validators                0.22.0             pyhd8ed1ab_0    conda-forge
virtualenv                20.24.6                  pypi_0    pypi
voila                     0.5.4              pyhd8ed1ab_0    conda-forge
watchdog                  3.0.0           py311heffc1b2_1    conda-forge
wcwidth                   0.2.5              pyhd3eb1b0_0  
webencodings              0.5.1           py311hca03da5_1  
websocket-client          0.58.0          py311hca03da5_4  
websockets                11.0.3                   pypi_0    pypi
werkzeug                  3.0.1              pyhd8ed1ab_0    conda-forge
wheel                     0.41.2          py311hca03da5_0  
widgetsnbextension        4.0.5           py311hca03da5_0  
xyzservices               2022.9.0        py311hca03da5_1  
xz                        5.4.2                h80987f9_0  
yaml                      0.2.5                h1a28f6b_0  
yarl                      1.8.1           py311h80987f9_0  
zeromq                    4.3.4                hc377ac9_0  
zipp                      3.11.0          py311hca03da5_0  
zlib                      1.2.13               h53f4e23_5    conda-forge
zstd                      1.5.5                hd90d995_0  

Configuration

Same as mentioned in the example here.

Logs
$ jupyterhub -f jupyterhub_config.py
/Users/aktech/quansight/jupyterhub/examples/service-fastapi/jupyterhub_config.py:15: UserWarning: env PUBLIC_HOST is not set, defaulting to http://127.0.0.1:8000.  This can cause problems with OAuth.  Set PUBLIC_HOST to your public (browser accessible) host.
  warnings.warn(msg)
[I 2023-12-08 10:52:37.540 JupyterHub app:2859] Running JupyterHub version 4.0.2
[I 2023-12-08 10:52:37.540 JupyterHub app:2889] Using Authenticator: jupyterhub.auth.DummyAuthenticator-4.0.2
[I 2023-12-08 10:52:37.540 JupyterHub app:2889] Using Spawner: jupyterhub.spawner.SimpleLocalProcessSpawner-4.0.2
[I 2023-12-08 10:52:37.540 JupyterHub app:2889] Using Proxy: jupyterhub.proxy.ConfigurableHTTPProxy-4.0.2
[I 2023-12-08 10:52:37.551 JupyterHub app:1664] Loading cookie_secret from /Users/aktech/quansight/jupyterhub/examples/service-fastapi/jupyterhub_cookie_secret
[I 2023-12-08 10:52:37.579 JupyterHub proxy:556] Generating new CONFIGPROXY_AUTH_TOKEN
[I 2023-12-08 10:52:37.590 JupyterHub provider:661] Updating oauth client service-fastapi
[I 2023-12-08 10:52:37.620 JupyterHub app:2928] Initialized 0 spawners in 0.001 seconds
[I 2023-12-08 10:52:37.622 JupyterHub metrics:278] Found 1 active users in the last ActiveUserPeriods.twenty_four_hours
[I 2023-12-08 10:52:37.622 JupyterHub metrics:278] Found 1 active users in the last ActiveUserPeriods.seven_days
[I 2023-12-08 10:52:37.622 JupyterHub metrics:278] Found 1 active users in the last ActiveUserPeriods.thirty_days
[W 2023-12-08 10:52:37.622 JupyterHub proxy:746] Running JupyterHub without SSL.  I hope there is SSL termination happening somewhere else...
[I 2023-12-08 10:52:37.622 JupyterHub proxy:750] Starting proxy @ http://:8000
10:52:37.727 [ConfigProxy] info: Proxying http://*:8000 to (no default)
10:52:37.728 [ConfigProxy] info: Proxy API at http://127.0.0.1:8001/api/routes
10:52:37.871 [ConfigProxy] info: 200 GET /api/routes
[I 2023-12-08 10:52:37.871 JupyterHub app:3178] Hub API listening on http://127.0.0.1:8081/hub/
[I 2023-12-08 10:52:37.871 JupyterHub app:3189] Starting managed service fastapi at http://127.0.0.1:10202
[I 2023-12-08 10:52:37.872 JupyterHub service:385] Starting service 'fastapi': ['uvicorn', 'app:app', '--port', '10202']
[I 2023-12-08 10:52:37.875 JupyterHub service:133] Spawning uvicorn app:app --port 10202
INFO:     Started server process [76111]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:10202 (Press CTRL+C to quit)
INFO:     127.0.0.1:62468 - "GET /services/fastapi/ HTTP/1.1" 200 OK
10:52:38.329 [ConfigProxy] info: 200 GET /api/routes
[I 2023-12-08 10:52:38.329 JupyterHub proxy:477] Adding route for Hub: / => http://127.0.0.1:8081
[W 2023-12-08 10:52:38.330 JupyterHub proxy:445] Adding missing route for fastapi (Server(url=http://127.0.0.1:10202/services/fastapi/, bind_url=http://127.0.0.1:10202/services/fastapi/))
[I 2023-12-08 10:52:38.330 JupyterHub proxy:311] Adding service fastapi to proxy /services/fastapi/ => http://127.0.0.1:10202
10:52:38.331 [ConfigProxy] info: Adding route / -> http://127.0.0.1:8081
10:52:38.331 [ConfigProxy] info: Route added / -> http://127.0.0.1:8081
10:52:38.331 [ConfigProxy] info: 201 POST /api/routes/
10:52:38.332 [ConfigProxy] info: Adding route /services/fastapi -> http://127.0.0.1:10202
10:52:38.332 [ConfigProxy] info: Route added /services/fastapi -> http://127.0.0.1:10202
10:52:38.333 [ConfigProxy] info: 201 POST /api/routes/services/fastapi
[I 2023-12-08 10:52:38.333 JupyterHub app:3245] JupyterHub is now running at http://:8000
INFO:     ::ffff:127.0.0.1:0 - "GET /services/fastapi/docs HTTP/1.1" 200 OK
INFO:     ::ffff:127.0.0.1:0 - "GET /services/fastapi/openapi.json HTTP/1.1" 200 OK
INFO:     ::ffff:127.0.0.1:0 - "GET /services/fastapi/docs HTTP/1.1" 200 OK
INFO:     ::ffff:127.0.0.1:0 - "GET /services/fastapi/openapi.json HTTP/1.1" 200 OK
INFO:     ::ffff:127.0.0.1:0 - "GET /services/fastapi/me HTTP/1.1" 401 Unauthorized
[I 2023-12-08 10:53:00.537 JupyterHub log:191] 302 GET /hub/api/oauth2/authorize?response_type=code&client_id=service-fastapi&redirect_uri=http%3A%2F%2F127.0.0.1%3A8000%2Fservices%2Ffastapi%2Foauth_callback&state=[secret] -> http://127.0.0.1:8000/services/fastapi/oauth_callback?code=[secret]&state=[secret] (test-user@::ffff:127.0.0.1) 37.13ms
INFO:     ::ffff:127.0.0.1:0 - "GET /services/fastapi/oauth_callback?code=6qxyAAoI5oB9HAt55EOZoiIlET1mEK&state=RnJpIERlYyAwOCAyMDIzIDEwOjUzOjAwIEdNVCswMDAwIChHcmVlbndpY2ggTWVhbiBUaW1lKQ%3D%3D HTTP/1.1" 200 OK
[I 2023-12-08 10:53:00.600 JupyterHub log:191] 200 POST /hub/api/oauth2/token (fastapi@127.0.0.1) 12.46ms
INFO:     ::ffff:127.0.0.1:0 - "POST /services/fastapi/get_token HTTP/1.1" 200 OK
INFO:     127.0.0.1:62490 - "GET /services/fastapi/ HTTP/1.1" 200 OK
INFO:     ::ffff:127.0.0.1:0 - "GET /services/fastapi/docs HTTP/1.1" 200 OK
INFO:     ::ffff:127.0.0.1:0 - "GET /services/fastapi/openapi.json HTTP/1.1" 200 OK
INFO:     ::ffff:127.0.0.1:0 - "GET /services/fastapi/me HTTP/1.1" 401 Unauthorized
@aktech aktech added the bug label Dec 8, 2023
Copy link

welcome bot commented Dec 8, 2023

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@minrk minrk added documentation and removed bug labels Dec 8, 2023
@minrk
Copy link
Member

minrk commented Dec 8, 2023

I would expect the subsequent requests to be authorized and return the valid response instead of 400.

I wouldn't typically expect an oauth token requested via the swagger-ui to be persisted. Have you seen examples where that's the case?

Judging by here and here, it looks like we should be able to set:

app = FastAPI(swagger_ui_parameters={"persistAuthorization": True})

Would you like to try a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants