WIF,ADFS 2.0,wsignoutcleanup1.0和wreply

时间:2013-09-19 21:23:28

标签: asp.net single-sign-on wif adfs2.0 ws-federation

我已经设置了一个WIF Web应用程序,一个自定义STS和一个ADFS 2.0实例。我很难理解申请的退出流程。目前,当我的用户点击退出按钮时,我正在调用此代码:

WSFederationAuthenticationModule.FederatedSignOut(null, new Uri("https://myrelyingpartyapp.com/?wa=wsignoutcleanup1.0"));

如果我使用此代码,它可以正常工作。所有cookie和会话都被正确处理。唯一的问题是浏览器在过程结束后只显示一点绿色检查。显然,我希望被重定向回STS的登录页面。为此,我尝试了以下代码:

WSFederationAuthenticationModule.FederatedSignOut(null, new Uri("https://myrelyingpartyapp.com/?wa=wsignoutcleanup1.0&wreply=" + HttpUtility.UrlEncode("https://myrelyingpartyapp.com/Default.aspx")));

我的信念是,wreply会导致用户被重定向回我的依赖方应用程序,在那里他们将被授权,因此被重定向回STS登录页面。相反,这会导致ADFS中的错误(由于它们有用的错误页面,我无法看到它。)无论我使用什么url wreply,都会抛出错误。 我是否正确使用wsignoutcleanup1.0?仅供参考,以下是我处理登录/退出请求的STS中的代码:

if (action == "wsignin1.0")
{
  SignInRequestMessage signInRequestMessage = (SignInRequestMessage)WSFederationMessage.CreateFromUri(Request.Url);

  if (User != null && User.Identity != null && User.Identity.IsAuthenticated)
  {
    SecurityTokenService securityTokenService = new CustomSecurityTokenService(CustomSecurityTokenServiceConfiguration.Current);
    SignInResponseMessage signInResponseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(signInRequestMessage, User as ClaimsPrincipal, securityTokenService);
    FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse(signInResponseMessage, Response);
  }
  else
  {
     throw new UnauthorizedAccessException();
  }
}
else if (action == "wsignout1.0")
{
  SignOutRequestMessage signOutRequestMessage = (SignOutRequestMessage)WSFederationMessage.CreateFromUri(Request.Url);                    
  FederatedPassiveSecurityTokenServiceOperations.ProcessSignOutRequest(signOutRequestMessage, User as ClaimsPrincipal, signOutRequestMessage.Reply, Response);
}

1 个答案:

答案 0 :(得分:0)

我所需要的正确行为是正确的注销代码。此代码最终将我的用户注销并进行了适当的清理:

var module = FederatedAuthentication.WSFederationAuthenticationModule;
module.SignOut(false);
var request = new SignOutRequestMessage(new Uri(module.Issuer), module.Realm);
Response.Redirect(request.WriteQueryString());

此代码放在我的依赖方应用程序的注销按钮的事件处理程序中。