I have an OWIN app that authenticates users with cookie authentication, and if that fails then it tries WS-Federated authentication. In other words, if the correct cookie isn't there in the initial request, then go to the STS and fetch the security token.
The problem I'm having is making sure the user's original URL request is fulfilled if federated authentication is used. Thanks to this post, I realized that the redirect URL from the STS back to the OWIN app contains the "original" URL in the wctx query parameter. The issue is that this value is set, as far as I can tell, using WsFederationAuthenticationOptions.Wtrealm
(perhaps Wreply
?). This is a problem because these values are set in the initial configuration. I don't want a hard coded value -- I just want the URL the user originally used (i.e. IOwinContext.Request.Uri
). The documentation for Wtrealm
and Wreply
does not help explain what the values should be.
I thought I could sneakily set Wtrealm
to the user's request URL before redirecting to the STS, but apparently it's already set by the time RedirectToIdentityProvider
notification is raised:
RedirectToIdentityProvider = context =>
{
context.Options.Wtrealm = context.Request.Uri.ToString();
}
Does anyone know what the correct approach is? Is there a way to make Wtrealm
in the initial configuration the user's request URL? Or is Wtrealm
not what I think it is, and I should be approaching this in a different way?