You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Azure App Service Easy Auth自定义认证后重定向路径?

解决Azure App Service Easy Auth从Okta跳转后默认重定向到/.auth/aad/done的问题

问题场景

我在Azure App Services部署的应用使用Easy Auth实现Azure AD认证,直接通过回调URL登录时流程正常,认证后能正确重定向到应用。但从Okta Dashboard进入应用时,流程会走到/.auth/aad/login/callback → /.auth/aad/done,需要将最终重定向路径改为自定义的https://myapp.azurewebsites.net/home。

已尝试的配置:

  • 将Azure AD回调URL设置为{domain}.auth/login/aad/callback
  • Okta Dashboard配置中,用户重定向目标为Azure App Service URL并使用/sso/saml

解决方案

方法1:通过post_login_redirect_uri参数指定重定向路径

Easy Auth原生支持通过post_login_redirect_uri参数自定义登录后的重定向目标。调整Okta应用的跳转配置,将用户重定向的URL修改为:

https://myapp.azurewebsites.net/.auth/login/aad/callback?post_login_redirect_uri=https://myapp.azurewebsites.net/home

这样用户从Okta跳转过来时,Easy Auth完成认证后会直接跳转到指定的/home路径,绕过默认的/.auth/aad/done页面。

注意:确保Okta允许在跳转URL中携带自定义参数,若参数被截断,检查Okta应用的"Login redirect URIs"配置是否包含带参数的完整URL。

方法2:使用URL重写规则强制重定向

如果无法修改Okta的跳转参数,可以在Azure App Service中配置URL重写规则,将/.auth/aad/done的请求重定向到/home。

ASP.NET/ASP.NET Core(web.config)

在应用根目录的web.config中添加规则:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect AAD Done to Home" stopProcessing="true">
          <match url="^.auth/aad/done$" />
          <action type="Redirect" url="/home" redirectType="Found" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

其他语言(.htaccess)

在.htaccess中添加规则:

RewriteEngine On
RewriteRule ^\.auth/aad/done$ /home [R=302,L]

方法3:在应用代码中捕获并处理/.auth/aad/done路径

如果应用有自定义路由逻辑,可以直接在代码中捕获/.auth/aad/done的请求,然后重定向到目标路径。

以ASP.NET Core为例,在Program.cs中添加路由:

var app = builder.Build();

// 其他中间件配置...

app.MapGet("/.auth/aad/done", async context =>
{
    context.Response.Redirect("/home");
    await Task.CompletedTask;
});

app.Run();

关键说明

  • 优先使用方法1,这是Easy Auth的原生支持方式,无需额外修改应用或服务器配置。
  • 方法2和3作为兜底方案,适用于无法修改Okta配置的场景。
  • 测试时注意清除浏览器缓存,避免旧的重定向规则影响结果。

内容的提问来源于stack exchange,提问作者Ahsaan shuja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 05:42:33