single sign on - FastAPI application redirect to HTTP and not HTTPS - Stack Overflow

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

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744933422a4601874.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信