Last active
December 14, 2015 19:09
-
-
Save astaykov/5134934 to your computer and use it in GitHub Desktop.
Dealing with Context in WSFederation and ACS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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