使用TicketDataFormat获取.NET Core,WS Federation,Identity Core问题

时间:2018-07-19 13:41:37

标签: cookies .net-core ws-federation asp.net-core-identity

我有两个使用WS Federation的应用程序,并且正在努力将其中一个应用程序迁移到.NET Core。这两个应用程序必须能够共享cookie,而这正是我在.NET Core方面遇到的问题。

这是我的Startup.cs的一部分

services.AddIdentity<ApplicationUser, ApplicationRole>()
    .AddEntityFrameworkStores<Context>()
    .AddDefaultTokenProviders();

services.ConfigureApplicationCookie(options =>
{
    options.LoginPath = new PathString("/Account/Login");
    //LOGIN WORKS CORRECTLY WITH THE BELOW LINE COMMENTED
    options.TicketDataFormat = new AuthTicketDataFormat();
    options.Cookie.Name = "cookiename";
    options.Cookie.Path = "/";
    options.Cookie.Domain = "";
});

services.ConfigureExternalCookie(options => {
    options.LoginPath = new PathString("/Account/Login");
    //LOGIN WORKS CORRECTLY WITH THE BELOW LINE COMMENTED
    options.TicketDataFormat = new AuthTicketDataFormat();
    options.Cookie.Name = "cookiename";
    options.Cookie.Path = "/";
    options.Cookie.Domain = "";
});

services.AddAuthentication()
    .AddWsFederation(options => {
        // MetadataAddress represents the Active Directory instance used to authenticate users.
        options.MetadataAddress = authentication.GetValue<string>("AdfsWsFedMetadataUri");
        // Wtrealm is the app's identifier in the Active Directory instance.
        // For ADFS, use the relying party's identifier, its WS-Federation Passive protocol URL:
        options.Wtrealm = authentication.GetValue<string>("AdfsRelyingPartyIdentifier");
    });

我能够看到在“网络”选项卡中确实收到一个cookie,但是我遇到的问题是我陷入了无限循环,因为在我的匿名回叫端点上,我有以下内容:

var loginInfo = await this._signInManager.GetExternalLoginInfoAsync();
//loginInfo is always coming back as null
if (loginInfo == null) {
    return RedirectToAction("Login");
}

问题似乎是由options.TicketDataFormat和cookie的自定义格式引起的。 Cookie似乎是使用ticketDataFormat正确创建的,但是signInManager上的getExternalLoginInfoAsync始终返回null。

任何帮助或指导都将不胜感激,因为我一直将头撞在墙上,试图弄清楚这一点。

0 个答案:

没有答案