Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Wrong redirect when using self-hosted Kratos

未关闭
#565 4 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
nextjs, typescript

调研方向

从 packages/nextjs/src/utils/rewrite.ts 中链接的 matching 逻辑开始,然后使用 self-hosted Kratos 配置以及不同的 auth 和 application 域名复现一个流程。确定已配置 UI URL 的预期重定向行为;如果 repository 提供了相应机制,则添加或更新针对性的 coverage,并验证该流程不再错误地回退到 backend URL。

由索引模型根据 Issue 内容生成。

描述

Needs Triage

Hello!

I'm not sure if I am doing something wrong, but it seems there is an assumption here that may not be correct in cases of self-hosted Kratos:
https://github.com/ory/elements/blob/fdabadf8cb2e0ec4fd9286a5277516f8fd69aa0c/packages/nextjs/src/utils/rewrite.ts#L32C1-L32C62

In my Kratos config, I have:

kratos:
  kratos:
    config:
      serve:
        public:
          base_url: https://auth.example.com
          cors:
            allowed_origins:
              - http://localhost:3042
              - https://auth.example.com

      selfservice:
        default_browser_return_url: https://example.com
        allowed_return_urls:
          - http://localhost:3042/*
          - https://example.com/*

        methods:
          webauthn:
            config:
              rp:
                id: example.com
                origin: https://example.com:443/auth/login

        flows:
          error:
            ui_url: https://example.com/error
          
          settings:
            ui_url: https://example.com/settings

          recovery:
            ui_url: https://example.com/auth/recovery
          
          verification:
            ui_url: https://example.com/auth/verification
            after:
              default_browser_return_url: https://example.com
          
          logout:
            after:
              default_browser_return_url: https://example.com
          
          login:
            ui_url: https://example.com/auth/login

          registration:
            ui_url: https://example.com/auth/registration

Every time I start a flow, I get redirected to the UI URLs specified in the config, as-is.
In the linked code above, we can see it tries to match the base URL (let's say https://auth.example.com with the redirect https://example.com/auth/login). Of course, this do not match, it gives up and returns the URL as-is from the backend. It seems a bit weird to me that Ory HAS to be hosted on the same domain as the actual app handling the flows. I suppose this is something specific to the hosted version of Kratos/Ory services, and I also suppose the headers passed are supposed to mitigate this issue, but they do not have any effects in the self-hosted version, it seems.

I'm absolutely open to making a PR if required; I just want to make sure there was no oversight on my side first!

Thanks a lot.

主要语言
TypeScript
星标
187
派生
80
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ory/elements 的其他 Issue

查看 ory/elements 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。