我使用 Azure 静态 Web 应用设置了一个站点。我有两个用例无法很好地解决,我认为相同的功能可以解决这两个问题:
- 当用户未经身份验证时,他们会被重定向到
<my-site>/.auth/login/<my-auth-provider>
。但是,这意味着当他们登录后返回时,他们会转到/index.html
,这并不理想。该站点的大部分流量将流向特定的叶页面。 我想重定向到<my-site>/.auth/login/<my-auth-provider>?fromUrl=<the-requested-url>
相反,如果可能的话。 - 当用户请求一个“漂亮”的 URL 地址时,例如
<my-site>/pretty-url
,我注意到 Azure SWA 没有以正常方式处理该问题,重写为<my-site>/pretty-url/index.html
。 我希望它至少尝试重写为<my-site>/pretty-url/index.html
.
最佳答案
现在可以通过在 staticwebapp.config.json
中配置响应覆盖进行身份验证后重定向回引荐来源网址。
{
"routes": [
{
"route": "/*",
"allowedRoles": [
"authenticated"
]
}
],
"responseOverrides": {
"401": {
"statusCode": 302,
"redirect": "/.auth/login/github?post_login_redirect_uri=.referrer"
}
}
}
您需要将 ?post_login_redirect_uri=.referrer
附加到 IDP 的身份验证 URL。
关于Azure SWA : redirect to modified version of requested route?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69260006/