{"meta":{"title":"关于用户授权回调 URL","intro":"可以指定用户可以在授权 GitHub App后重定向到的 URL。","product":"应用","breadcrumbs":[{"href":"/zh/apps","title":"应用"},{"href":"/zh/apps/creating-github-apps","title":"创建GitHub应用"},{"href":"/zh/apps/creating-github-apps/registering-a-github-app","title":"注册 GitHub App"},{"href":"/zh/apps/creating-github-apps/registering-a-github-app/about-the-user-authorization-callback-url","title":"回调网址"}],"documentType":"article"},"body":"# 关于用户授权回调 URL\n\n可以指定用户可以在授权 GitHub App后重定向到的 URL。\n\n注册 GitHub App 时，您可以指定回调 URL。 当您使用 Web 应用流程生成用户访问令牌以便代表用户执行操作时，用户在授权 GitHub App 后将被重定向到回调 URL。\n\n最多可以指定 10 个回调 URL。 如果指定了多个回调 URL，则在提示用户授权您的 `redirect_uri` 时，应使用 GitHub App 参数，以指明应将用户重定向到哪个回调 URL。 如果未指定 `redirect_uri`，则将使用第一个回调 URL。 如需详细了解如何使用 `redirect_uri` 参数，请参阅“[为 GitHub 应用生成用户访问令牌](/zh/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app)”。\n\n回叫 URL 与设置 URL 不同。 用户安装 GitHub App 后，将被重定向到设置 URL。 当用户通过 Web 应用流程授权 GitHub App 时，将被重定向至回调 URL。 有关详细信息，请参阅“[关于设置 URL](/zh/apps/creating-github-apps/registering-a-github-app/about-the-setup-url)”。\n\n有关生成用户访问令牌的详细信息，请参阅“[为 GitHub 应用生成用户访问令牌](/zh/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app)”。 有关如何注册GitHub App的详细信息，请参阅[注册GitHub应用](/zh/apps/creating-github-apps/registering-a-github-app/registering-a-github-app)。 有关修改 GitHub App 注册的详细信息，请参阅 [修改GitHub应用注册](/zh/apps/maintaining-github-apps/modifying-a-github-app-registration)。\n\n## 回调 URL 的通配符匹配\n\n如果需要，可以为回调 URL 启用通配符匹配。 启用通配符匹配后，重定向 URL 的主机（不包括子域）和端口必须与回调 URL 完全匹配，重定向 URL 的路径必须引用回调 URL 的子目录。 这意味着回调 URL 的任何子域或子目录都将匹配，并作为回调 URL 允许。 例如，如果对回调 URL `https://example.com/path` 启用了通配符匹配：\n\n```\nCALLBACK: https://example.com/path\n\nMATCH: https://example.com/path\nMATCH: https://example.com/path/subdir/other\nMATCH: https://oauth.example.com/path\nMATCH: https://oauth.example.com/path/subdir/other\nFAIL:  https://example.com/bar\nFAIL:  https://example.com/\nFAIL:  https://example.com:8080/path\nFAIL:  https://oauth.example.com:8080/path\nFAIL:  https://example.org\n```\n\n禁用通配符匹配后，重定向 URL 必须与回调 URL 完全匹配。 您可以在应用设置中为每个回调 URL 启用或禁用通配符匹配。\n\n> \\[!WARNING]\n> 启用通配符匹配可能会使应用面临安全风险，因为它允许攻击者将授权代码发送到回调 URL 的任何子域或子目录。 仅当您绝对需要启用通配符匹配，并且完全确定自己能够控制回调 URL 的所有可能子域和路径时，才启用该功能。 有关详细信息，请参阅 [OAuth 2.0 安全最佳做法](https://www.rfc-editor.org/info/rfc9700/#section-4.1.1-11)。\n\n在2026 年 8 月 3 日 之前已启用单个回调 URL 的应用，其回调 URL 已启用通配符匹配。 这保留了在通配符匹配成为可配置设置之前就已存在的重定向行为，这也就是为什么在该日期之前创建的所有 OAuth apps 和部分 GitHub Apps 都启用了通配符匹配。 如果你的应用不需要通配符匹配，我们建议你禁用它。"}