- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 WIF 与 WS Federation 结合使用,以便我的 ASP.NET 应用程序可以针对 STS (Thinktecture IdentityServer) 进行身份验证。在我的 RP 中,我想根据用户的声明实用地设置 cookie 持久性。
观察 Fiddler 中的流量,我可以看到当 STS token 发布到 RP 时,首先设置 WIF FedAuth cookie。在设置 cookie 之前,我想拦截一些事件,并根据当前声明将 cookie 设置为持久(或不持久)。
我知道我可以在 web.config 中设置 cookie 持久性,但是此行为需要基于用户的条件。
<罢工>
<罢工><wsFederation ... persistentCookiesOnPassiveRedirects="true" />
<罢工>
我的第一个方法是尝试处理各种 SessionSecurityTokenCreated 事件,但这些事件似乎从未被触发。 我是否错误地添加了处理程序?或者有更好的方法吗?
protected void Application_Start()
{
...
FederatedAuthentication.SessionAuthenticationModule.SessionSecurityTokenCreated +=
new EventHandler<SessionSecurityTokenCreatedEventArgs>(SessionAuthenticationModule_SessionSecurityTokenCreated);
FederatedAuthentication.WSFederationAuthenticationModule.SessionSecurityTokenCreated +=
new EventHandler<SessionSecurityTokenCreatedEventArgs>(WSFederationAuthenticationModule_SessionSecurityTokenCreated);
}
//This never seems to fire...
void SessionAuthenticationModule_SessionSecurityTokenCreated(object sender,
SessionSecurityTokenCreatedEventArgs e)
{
if (e.SessionToken.ClaimsPrincipal.HasClaim("someClaim", "someValue"))
e.SessionToken.IsPersistent = true;
else
e.SessionToken.IsPersistent = false;
}
//This never seems to fire either...
void WSFederationAuthenticationModule_SessionSecurityTokenCreated(object sender,
SessionSecurityTokenCreatedEventArgs e)
{
if (e.SessionToken.ClaimsPrincipal.HasClaim("someClaim", "someValue"))
e.SessionToken.IsPersistent = true;
else
e.SessionToken.IsPersistent = false;
}
有趣的是:如果我为 SessionAuthenticationModule_SessionSecurityTokenReceived 添加处理程序,此事件似乎会触发。在这里,我可以重新发出 cookie 并设置 IsPersistent = true,但是直到首次设置 cookie 后才会触发此操作,我更愿意在首次发出 cookie 时执行此操作。
经过一番测试:如果我在 SessionAuthenticationModule_SessionSecurityTokenReceived 中重新发出 cookie,那么 SessionAuthenticationModule_SessionSecurityTokenCreated 将被触发。我似乎无法找出为什么当 token 首次发布到 RP 时,在 cookie 的初始创建时不会触发此操作。
最佳答案
我的问题的根源是: a) 我使用的是自定义 WSFederationAuthenticationModule。 b) 我没有使用自定义模块的名称连接 Global.asax 中的事件。
假设我的 web.config 中有这个:
<system.webServer>
// ...
<add name="MyCustomWSFederationAuthenticationModule"
type="MyLib.MyCustomWSFederationAuthenticationModule, Thinktecture.IdentityModel, Version=1.0.0.0, Culture=neutral"
preCondition="managedHandler" />
<add name="SessionAuthenticationModule"
type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
preCondition="managedHandler" />
// ...
</system.webServer>
假设“MyCustomWSFederationAuthenticationModule”是自定义 Fed-auth 模块的名称。然后我只需修复方法处理程序的名称(应用程序启动中没有任何内容)。
protected void Application_Start()
{
//Nothing here.
}
//This never seems to fire either...
void MyCustomWSFederationAuthenticationModule_SessionSecurityTokenCreated(object sender,
SessionSecurityTokenCreatedEventArgs e)
{
if (e.SessionToken.ClaimsPrincipal.HasClaim("someClaim", "someValue"))
e.SessionToken.IsPersistent = true;
else
e.SessionToken.IsPersistent = false;
}
关于asp.net - 如何在 SessionSecurityTokenCreated 时有条件地设置 FedAuth cookie SessionToken.IsPersistent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13293939/
我的移动混合应用程序使用expressJS服务器作为后端,通过REST API代理对parse.com的请求。我还使用 Express 与 SSO 提供商进行我自己的用户身份验证。我关注了this t
我在 iOS 上使用 Swift。 我的应用有一个帖子列表。您可以匿名阅读,但必须注册才能发帖。 当您打开应用程序时,您会得到一个匿名帐户。我将以下内容放入 AppDelegate PFUser.en
我有一个应用程序可以检查当前 session 是否有效。因此,如果您在另一部手机上更改密码,它会在您打开该应用程序时将您从其他手机上注销。因此,如果 [PFUser currentUser] 中缓存了
尝试一些应该很简单的事情,使用 Back4app 上的 Parse 服务器从管理仪表板创建一个新的用户帐户。 每次我尝试创建新用户,但我无法切换回原始用户... var sessionToken =
我将 WIF 与 WS Federation 结合使用,以便我的 ASP.NET 应用程序可以针对 STS (Thinktecture IdentityServer) 进行身份验证。在我的 RP 中,
假设我这样做: import os os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages "org.apache.hadoop:hadoop-aws:2.7.
我正在使用出色的 Thinktecture.IdentityModel 库在 ASP.NET Web API 项目中执行身份验证/授权,该项目将从移动设备和可能的 Web 客户端使用。我正在使用基本身
我能够使用用户名和密码获取 sessionToken。但是,之后我想在 AngularJS 中使用 POST 调用创建 session ,如下所示。 Angular(整个 Web 应用程序)托管在 A
我正在开发 iOS 应用程序,我需要将图像上传到 AWS S3Bucket。我从服务器获得了临时凭证(accessKey、secretKey、sessionToken 和 bucketName)来上传
我是一名优秀的程序员,十分优秀!