Skip to content

Instantly share code, notes, and snippets.

@astaykov
Last active December 14, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astaykov/5134934 to your computer and use it in GitHub Desktop.
Save astaykov/5134934 to your computer and use it in GitHub Desktop.
Dealing with Context in WSFederation and ACS
[AllowAnonymous]
[ValidateInput(false)]
public class AcsResponseController : Controller
{
public ActionResult Index()
{
if (ControllerContext.HttpContext.Request.Form["wresult"] != null)
{
// This is a response from the ACS - you can further inspect the message if you will
SignInResponseMessage message =
WSFederationMessage.CreateFromNameValueCollection(
WSFederationMessage.GetBaseUrl(ControllerContext.HttpContext.Request.Url),
ControllerContext.HttpContext.Request.Form)
as SignInResponseMessage;
if (!string.IsNullOrWhiteSpace(message.Context))
{
// create Saml2SecurityToken (if we know it is SAML2)
Saml2SecurityToken
token = FederatedAuthentication
.WSFederationAuthenticationModule.GetSecurityToken(message)
as Saml2SecurityToken;
// user the message.Context on our own will
Response.Redirect("~/");
}
else
{
Response.Redirect("~/");
}
return Redirect("~/");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment