C# ADFS联合身份验证不返回令牌,也不保存cookie
我们对ADFS服务器使用WsFederation身份验证。我们编写的大多数应用程序都使用下面的代码(当然排除了调试代码),但我的应用程序就是不想工作 我重定向到广告服务器上的登录页面,可以输入用户ID和密码,没有任何问题,但返回时应该保存一个cookie,但没有。结果是在下一次往返时,重定向再次发生(不过这次没有登录表单) 调试代码只点击C# ADFS联合身份验证不返回令牌,也不保存cookie,c#,active-directory,ws-federation,C#,Active Directory,Ws Federation,我们对ADFS服务器使用WsFederation身份验证。我们编写的大多数应用程序都使用下面的代码(当然排除了调试代码),但我的应用程序就是不想工作 我重定向到广告服务器上的登录页面,可以输入用户ID和密码,没有任何问题,但返回时应该保存一个cookie,但没有。结果是在下一次往返时,重定向再次发生(不过这次没有登录表单) 调试代码只点击重定向到dentityprovider。其他的都不叫 代码位于OWIN的Startup.cs中 private static void ConfigureAut
重定向到dentityprovider
。其他的都不叫
代码位于OWIN的Startup.cs中
private static void ConfigureAuth(IAppBuilder app, ISettings settings)
{
app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);
// Work-around to fix Katana issue 197: https://katanaproject.codeplex.com/workitem/197
// https://github.com/KentorIT/owin-cookie-saver
app.UseKentorOwinCookieSaver();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType
});
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
Wtrealm = settings.WsFedRealm,
MetadataAddress = settings.WsFedMetadataUrl,
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = ClaimsExtensions.WurNameIdentifier,
SaveSigninToken = true,
// ValidIssuer = settings.ValidIssuer
},
Notifications = new WsFederationAuthenticationNotifications
{
MessageReceived = context =>
{
Log.Info($"Message received {context.ProtocolMessage}");
return Task.FromResult(0);
},
RedirectToIdentityProvider = context =>
{
Log.Info($"Redirect to identity provider {context?.Request?.Uri?.AbsolutePath}");
return Task.FromResult(0);
},
SecurityTokenValidated = context =>
{
Log.Info("Security token validated");
return Task.FromResult(0);
},
SecurityTokenReceived = context =>
{
Log.Info($"SecurityTokenReceived {context?.Response?.ReasonPhrase}");
return Task.FromResult(0);
},
AuthenticationFailed = context =>
{
Log.Error($"Authentication failed Uri:{context.Request?.Uri} User:{context.Request?.User?.Identity?.Name}");
context.HandleResponse();
context.Response.Redirect("~/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);
AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Name;
}
我认为,问题是,两个中间件都激活了AuthenticationMode 我推荐一个自定义控制器。如果用户访问此控制器,则必须手动触发WsFederationAuthenticationDefaults.AuthenticationType的OwinContext.Authentication上的身份验证,并返回401。这将触发WsFederationAuthenticationHandler中的ApplyResponseChallengeAsync 在WsFederationAuthenticationOptions.Notifications上的SecurityTokenValidated方法中,您可以使用CookieAuthenticationDefaults.AuthenticationType类型的标识颁发新的AuthTicket
现在,身份提供程序中的身份已通过cookieauth转换为本地身份。仍然没有找到解决方案。感谢您的帮助吗?在应用程序中,有两种身份验证活动OAuth WSEN Federation。这可能是问题的根本原因吗?我已经用几个库对web.config进行了广泛的增强,现在WSFederation正在工作。我无法测试OAuth是否仍在为Cordova应用程序工作。一旦部署再次工作,我将测试它并在这里报告。该组织正在使用SecureAuth进行身份验证,但我们从未将其用于此应用程序(其他几十项工作都很好)。