admin管理员组

文章数量:1405736

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 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?

本文标签: single sign onFastAPI application redirect to HTTP and not HTTPSStack Overflow