Azure SWA : redirect to modified version of requested route?

标签 azure authentication redirect routes azure-static-web-app

我使用 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/

相关文章:

azure - 在 Azure 中,cscfg 文件来自哪里?

azure - 多个 Azure 队列

c# - asp C# 应用程序默认凭据不可用

c# - 将输出重定向到文本文件 c#

java - 在带有azure函数@ServiceBusQueueTrigger的java中,如何获取Label,Custom Properties和Broker Properties?

node.js - 如何通过 SSH 连接到 Node 容器应用程序?

django - 使用 message_set 的替代方案(尤其是 AnonymousUser)

c++ - CBC MAC : message length and length prepending

Javascript -> 通过选择重定向并选择选定的值

php - 可点击获取的数据: Website Redirect