Search code examples
asp.net-mvc-3claims-based-identityfederated-identitywif

MVC3 + WIF - FederationResult missing "wctx"


I have an MVC3 app for which I want to implement claims support. My goal is as follows:

  1. provide a SignIn link, which when clicked displays a popup window with username/password and Facebook/WindowsLive/Google etc. links

  2. automatically redirect to my SignIn page when a protected controller is accessed e.g. /Order/Delete

I've set up the application and providers in AppFabricLabs.com and included the STS in my project. I've also created an implementation of IAuthorizationFilter so I can mark my controllers as [WifAuth] and successfully get the OnAuthorization method called. I've implemented the use-case where the visitor has not been authenticated like this:

    private static void AuthenticateUser(AuthorizationContext context)
    {
        var fam = FederatedAuthentication.WSFederationAuthenticationModule;
        var signIn = new SignInRequestMessage(new Uri(fam.Issuer), fam.Realm);
        context.Result = new RedirectResult(signIn.WriteQueryString());
    }

and successfully get AppFabricLabs page with my Identity Provider choices (haven't figured out how to customise that page). When I log in my returnUrl gets called so I land in a controller method /Home/FederationResult, however the form posted to me contains only wa and wresult fields but I need wctx to know where to send the user... I haven't been able to figure out why.

the wresult is an XML document that contains (amongst a bzillion other things) the name and e-mail address of the user logging in but sadly does not contain the url to which the user was headed.

have I failed to configure something or am I just off base? thoughts anyone?

  • e

Solution

  • Just specify a Context for the SignInRequestMessage:

    signIn.Context = HttpContext.Current.Request.RawUrl;
    

    The wctx parameter is included in every request/response and also part of the form posted finally to your site.