views:

307

answers:

1

I've been configuring some of my applications to use the Windows Identity Foundation. I use the passive redirection to get security tokens from a Security Token Service. I accomplished this by inserting WIF code into a logon web site that existed before I started using WIF and then using the "Add STS Reference" within the applications.

However, I have one application that does not use the logon web site. I think that what I would like to do is generate the security token within the application itself without redirecting the user to an external STS.

I tried unsuccessfully to accomplish this by using the ClaimsAuthenticationManager class which can be used to add additional claims to a security token received from an external STS. However, ClaimsAuthenticationManager doesn't work in this context. Instead of calling ClaimsAuthenticationManager only a single time per session ( the expected and desired result ), it gets called on every page load with no sign of the claims that I assigned to the user on the previous page load.

I'm looking at creating an external STS that will give the user the claims from a database, but I see this as being a hazard. There seems to be no reason that I must create a whole separate STS for only a single web site. I would like to just generate the security token within my application.

A: 

It is possible to put the Security Token Service class within your own application.

However, in order for the user to be able to access a log-in page in your application before they've obtained the token, you must remove the deny users=? from the Authorization section of web.config. This will allow users to hit your web page with no security token. Once they log in, redirect them to the appropriate page.

This has the disadvantage of not being able to use the convenient passive redirect functionality, but it does work. That means that you must manually redirect users to the log-in page when they try to do something that requires them to be logged in.

Rice Flour Cookies
Per the FAQ (http://msdn.microsoft.com/en-us/library/ee748487.aspx) the ClaimsAuthenticationManager is per-call regardless of session, so that would explain the behavior you are seeing.Embedding the STS right in your application sort of defeats the purpose of federation. It sounds like all you really needed was an IClaimsPrincipal rather than a regular principal. Assuming that was the case, it may have been easier to just use regular forms authentication and have a custom HttpModule that rehydrates the claims based on the forms auth token.
Travis Illig