Problem:
I am experiencing an issue with the fastapi-sso library when defining the redirect_uri within the get_login_redirect method instead of during the initialization of the GoogleSSO instance.
- When the
redirect_uri is set during the initialization of GoogleSSO, everything works correctly under both HTTPS (with Nginx) and localhost.
- When the
redirect_uri is moved to the get_login_redirect method, it works on localhost but fails with HTTPS behind Nginx.
Error:
The following error is encountered when attempting to log in with Google under HTTPS using Nginx:
oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request)
You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy for keeping apps secure.
You can let the app developer know that this app doesn't comply with one or more Google validation rules.
Reproduction Steps:
- Define the redirect_uri within the get_login_redirect method:
@app.get("/auth/google/login")
async def auth_init():
async with sso:
return await sso.get_login_redirect(
redirect_uri="https://preprodxin.ddns.net/auth/google/callback",
params={"prompt": "consent", "access_type": "offline"},
)
- Configure Nginx to serve the FastAPI application over HTTPS.
- Attempt to sign in with Google OAuth.
Observed Behavior:
Works correctly on localhost.
It fails with HTTPS (Nginx) and returns the above error.
Expected Behavior:
Defining the redirect_uri dynamically within get_login_redirect should work consistently across environments, including HTTPS.
Environment:
fastapi==0.115.5
fastapi-sso==0.17.0
Python: docker image 3.11-slim
Nginx: docker image latest (1.27)
Running in a Docker container.
code example: https://github.com/nimaxin/fastapi-sso-nginx.git
Problem:
I am experiencing an issue with the
fastapi-ssolibrary when defining theredirect_uriwithin theget_login_redirectmethod instead of during the initialization of theGoogleSSOinstance.redirect_uriis set during the initialization ofGoogleSSO, everything works correctly under both HTTPS (with Nginx) and localhost.redirect_uriis moved to theget_login_redirectmethod, it works on localhost but fails with HTTPS behind Nginx.Error:
The following error is encountered when attempting to log in with Google under HTTPS using Nginx:
Reproduction Steps:
Observed Behavior:
Works correctly on localhost.
It fails with HTTPS (Nginx) and returns the above error.
Expected Behavior:
Defining the
redirect_uridynamically within get_login_redirect should work consistently across environments, including HTTPS.Environment:
fastapi==0.115.5
fastapi-sso==0.17.0
Python: docker image 3.11-slim
Nginx: docker image latest (1.27)
Running in a Docker container.
code example: https://github.com/nimaxin/fastapi-sso-nginx.git