0

Im using FastAPI via Uvicorn, and deploying my application to an Azure App Service. Its being deployed to

# Start
if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8080, forwarded_allow_ips="*", proxy_headers=True)

And I am integrating a SSO Login via SAML, and when logging in to the IdP's AD FS page it works fine, but when calling my callback function, the login first redirects to my correct address https://appservice.com/api/auth/callback with a POST request, and a 307 Temporary Redirect code, and after a page that asks if I want to proceed,

Middle Screen

It then rejects my callback because it calls /api/auth/callback using a POST to http instead of https, which calls a GET to https, which doesnt work for callback. Here are my login and callback functions:

@auth_router.get(API_PREFIX + "/auth/login")
async def sso_login(request: Request):
    try:
        auth = await init_saml_auth(request)
        redirect_url = auth.login()
        return RedirectResponse(url=redirect_url)
    except Exception as e:
        return JSONResponse({"error": str(e)}, status_code=500)


@auth_router.post(API_PREFIX + "/auth/callback/")
async def sso_callback(request: Request):
    logging.info(request)

    auth = await init_saml_auth(request)
    auth.process_response()

    if len(auth.get_errors()) != 0:
        return JSONResponse({"error": auth.get_last_error_reason()}, status_code=400)

    if not auth.is_authenticated():
        return JSONResponse({"error": "Authentication failed"}, status_code=403)

    user_data = auth.get_attributes()
    return JSONResponse({"message": "SSO Login Successful", "user": user_data})

Why is this happening?

1
  • difficult to tell what's going on with what you've posted… but you need to make sure that the POST request starts by going to https—redirecting will cause the posted data to get lost. I think you need to look at the client code and make sure that it's hitting the https endpoint Commented Mar 7 at 13:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.