【问题标题】:Azure AD with multiple Reply URLs redirects to the wrong one具有多个回复 URL 的 Azure AD 重定向到错误的 URL
【发布时间】:2015-06-02 06:50:12
【问题描述】:

我有一个将 AAD 与 WS Federation 结合使用的应用程序。我在 AAD 的应用程序中配置了多个回复 URL。我的应用程序之前强制所有用户登录,并且重定向在所有环境中都能正常工作。我必须允许未经身份验证的用户访问我的网站,在我进行必要的更改后,应用程序开始在登录后将我重定向到随机回复 URL。

以下是代码更改:

Web.config

<system.web>
    <authorization>
      <allow users="*" />
    </authorization>
    ...
</system.web>

AccountController.cs

public ActionResult SignIn()
{
    WsFederationConfiguration config = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration;

    string callbackUrl = Url.Action("Index", "Home", routeValues: null, protocol: Request.Url.Scheme);
    SignInRequestMessage signinMessage = new SignInRequestMessage(new Uri(config.Issuer), callbackUrl);
    signinMessage.SetParameter("wtrealm", IdentityConfig.Realm ?? config.Realm);

    return new RedirectResult(signinMessage.WriteQueryString());
}

我还在我的 Web.config 转换中在两个地方指定了回复 URL:

在 appSettings &lt;add key="ida:RedirectURI" value="..." /&gt; 中,它在我的 Global.asax.cs 中使用 WSFederationAuthenticationModule_RedirectingToIdentityProvider 方法来设置 e.SignInRequestMessage.Reply

<system.identityModel.services>
    <federationConfiguration>
      <wsFederation 
              passiveRedirectEnabled="true" 
              reply="..." />
    </federationConfiguration>
</system.identityModel.services>

请注意,有一个相关的 SO 问题没有那么详细并且没有答案Azure Active Directory Reply URL not working as expected

【问题讨论】:

    标签: azure-active-directory ws-federation


    【解决方案1】:

    我的问题出在 SignIn 方法中,即在这一行中:

    return new RedirectResult(signinMessage.WriteQueryString());
    

    需要改成这个:

    return new RedirectResult(signInRequest.RequestUrl.ToString());
    

    请参阅我的博客文章以及完整的代码示例:

    Partial authentication in Azure AD using WS Federation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      • 2020-06-22
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      相关资源
      最近更新 更多