在对 ADFS 进行身份验证后,一直在努力尝试提取不记名令牌...
我有一个 API 将接受承载令牌并针对 ADFS 对其进行验证。
我有一个 Web 表单 (.net 4.5.1) 应用程序,我正在修改它以使用 ADFS 3.0 来实现 SSO 身份验证。到目前为止,它针对 ADFS 服务器进行了正确的身份验证(显示到 ADFS 登录页面并登录)。
我的问题是我现在希望 WebForms 应用程序使用不记名令牌调用我的 Web API,我希望不记名令牌出现在 ADFS 返回的响应中,但它在哪里以及如何检索它?
我尝试使用 SecurityTokenValidated 和 SecurityTokenReceived WsFederationAuthenticationNotifications 事件,如下所示:
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType, // "WS-Fed Auth (Primary)",
Wtrealm = realm,
MetadataAddress = metadata,
Notifications = new WsFederationAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("Home/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
},
SecurityTokenValidated = token =>
{
Token = token.AuthenticationTicket.ToString();
return Task.FromResult(0);
},
SecurityTokenReceived = token =>
{
Token = token.ToString();
return Task.FromResult(0);
}
}
});
}
但是我在事件返回的对象中的任何地方都找不到令牌......我错过了什么?
感谢所有帮助。