最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览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 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?

发布评论

评论列表(0)

  1. 暂无评论