You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the FastAPI documentation, with the integrated search.
I already searched in Google "How to X in FastAPI" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to FastAPI but to Pydantic.
I already checked if it is not related to FastAPI but to Swagger UI (I know it is -> please see note below).
I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
I commit to help with one of those options 👆
Example Code
fromfastapiimportDepends, HTTPException, status, FastAPIfromfastapi.securityimportOAuth2fromjoseimportJWTError, ExpiredSignatureError, jwtapp=FastAPI()
# We're using OAuth2 for authentication with authorization code flowoauth2_scheme=OAuth2(
flows={
"authorizationCode": {
"authorizationUrl": "https://authserver.tld/oidc/auth",
"tokenUrl": "https://authserver.tld/oidc/token",
"scopes": {
"openid": "OpenID Connect",
"profile": "Profile infos",
"email": "Email"
}
}
}
)
jwk_set=something# dummy function that just return the decoded jwtdefget_jwt(token: str=Depends(oauth2_scheme)) ->dict:
try:
payload=jwt.decode(token, jwk_set, algorithms=["HS256"])
exceptJWTError:
raiseHTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
exceptExpiredSignatureError:
raiseHTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Token expired")
returnpayload# dummy endpoint to simply return the decoded jwt@app.get("/")asyncdefroot(jwt: dict=Depends(get_jwt)):
return {"payload": jwt}
Description
NOTE : This is kinda unrelated to FastAPI, it is an issue with SwaggerUI but there's a workaround decribed in the issue on GitHub, I would like to apply this workaround using FastAPI. Please, do not respond/close this due to it being unrelated.
Open /docs
Try to use the "Authorize" button
You're successfully redirected to your authentication provider
Login on you auth provider
You're redirected back to /docs/oauth2-redirect.html?someparams
You're on a blank page, with an error in the console
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
NOTE : This is kinda unrelated to FastAPI, it is an issue with SwaggerUI but there's a workaround decribed in the issue on GitHub, I would like to apply this workaround using FastAPI. Please, do not respond/close this due to it being unrelated.
Related issue on Swagger UI Github : swagger-api/swagger-ui#8030.
Is there a way to apply the workaround using FastAPI ?
Operating System
Linux, Windows
Operating System Details
No response
FastAPI Version
0.100.0
Python Version
3.11.1
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions