【问题标题】:azure authentication web app localhost reply url天蓝色身份验证 Web 应用程序 localhost 回复 url
【发布时间】:2018-04-30 21:10:07
【问题描述】:

我使用 Azure 身份验证创建了一个 Web 应用。 它在本地运行良好,但是在发布时,auth 回复 url 正在寻找本地主机。 我已将正确的回复 url 添加到 Azure 门户,如果我将 locahost 或 requireUrl 添加到列表顶部,我可以让它工作。

搜索修复程序说我需要使用 web.config 转换来设置本地主机或已部署应用程序的回复 url。

我无法让它工作。 我正在使用:

<Configuration>
  <system.identityModel.services>
    <federationConfiguration>
      <wsFederation reply="localhost" realm="localhost" issuer="https://login.microsoftonline.com/"/>
     </federationConfiguration>
</system.identityModel.services>
</configuration>

只是为了测试,我在 Azure 回复 url 的列表顶部设置了 deployURL,它在已部署的应用程序中运行良好,但本地开发版本在登录后重定向到 deployURL。

我认为上面的 web.config 代码会将本地开发版本重定向到本地。

我错过了什么?

【问题讨论】:

    标签: c# asp.net-mvc azure web


    【解决方案1】:

    对于发现问题的任何其他人,我对 OWIN 使用了错误的方法。 解决方案是将 replyUri 添加到 Start.Auth.cs

    private static string redirecturi = ConfigurationManager.AppSettings["ida:RedirectUrl"];

        public void ConfigureAuth(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
    
            app.UseCookieAuthentication(new CookieAuthenticationOptions());
    
            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = clientId,
                    Authority = authority,
                    PostLogoutRedirectUri = postLogoutRedirectUri,
                    RedirectUri = redirecturi
                });
        }
    

    然后将其添加到 web.config 中。

    <appSettings>
    <add key ="ida:RedirectUrl" value="https://localhost:44312/"/>
    </appSettings>
    

    并在 web.config.release 或任何其他类似的转换文件中进行转换;

    &lt;add key="ida:RedirectUrl" value="APP URL ADDED TO AZURE REPLY URLS" /&gt;

    【讨论】:

      【解决方案2】:

      感谢分享这个,帮助我解决了这个问题。您可以通过对 web.release.config 文件使用更精确的转换请求来概括解决方案。如果你使用这样的语句: &lt;add key="ida:RedirectUri" value="https://mytestwebsite.azurewebsites.net" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/&gt; 正确的键值对被修改,无需将其作为&lt;appSettings /&gt; 部分中的第一个键值对。您可以添加第二个转换以适应 PostLogoutRedirectUri:&lt;add key="ida:PostLogoutRedirectUri" value="https://mytestwebsite.azurewebsites.net" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/&gt;

      总结: 将这些行添加到 web.release.config 模板文件的 &lt;configuration /&gt; 部分以适应重定向 Uri:

      <appSettings> <add key="ida:PostLogoutRedirectUri" value="THE URL OF THE AZURE WEB SITE AS SHOWN IN THE PUBLISH PROFILE" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/> <add key="ida:RedirectUri" value="THE URL OF THE AZURE WEB SITE AS SHOWN IN THE PUBLISH PROFILE" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/> </appSettings>

      有关转换功能这方面的更多信息,请参阅 MSDN 文章:https://msdn.microsoft.com/library/dd465326.aspx#Locator%20Attribute%20Syntax

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-27
        • 2016-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-11
        • 2012-09-09
        • 1970-01-01
        相关资源
        最近更新 更多