Вход в OWIN / IdentityServer застрял в бесконечном цикле

У меня есть рабочий сервер аутентификации IdentityServer2, который работает нормально. Я создаю новое приложение.NET MVC и после этой статьи ( http://www.cloudidentity.com/blog/2014/02/20/ws-federation-in-microsoft-owin-componentsa-quick-start/) настроить MS OWIN с IDS2. Я могу добраться до экрана входа в систему, но после входа пользователь отправляется обратно на вызывающий веб-сайт и застревает в бесконечном цикле.

Startup.Auth.cs

using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.WsFederation;
using Owin;

namespace AZBarMail
{
    public partial class Startup
    {
        public void ConfigureAuth(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(
                new CookieAuthenticationOptions
                {
                    AuthenticationType =
                       WsFederationAuthenticationDefaults.AuthenticationType
                });
            app.UseWsFederationAuthentication(
                new WsFederationAuthenticationOptions
                {
                    MetadataAddress = "https://auth.azbar.org/federationmetadata/2007-06/federationmetadata.xml",
                    Wtrealm = "https://localhost:44310/",
                });
        }
    }
}

Часть web.config

<system.web>
  <authentication mode="None" />
  <compilation debug="true" targetFramework="4.6.1" />
  <httpRuntime targetFramework="4.6.1" />
</system.web>

Startup.cs

using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(AZBarMail.Startup))]
namespace AZBarMail
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

URL перенаправления в IDS2

https://localhost:44310/

2 ответа

Решение

Проблема окончательно решена. Кажется, была проблема с типом / настройками куки.

Перенаправьте вашего пользователя в /account/login.

app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/account/Login"),
                CookieName = CookieAuthenticationDefaults.CookiePrefix + "SampleClient",
                ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter,
                LogoutPath = new PathString("/account/Logout")
            });

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

Из /account/login, перенаправить на внешнего провайдера.

Внешний провайдер создаст cookie на своем домене, а вы получите cookie на своем домене после получения ответа от внешнего провайдера.

Другие вопросы по тегам