views:

21

answers:

1
+2  Q: 

IIS module and WCF

I have written an IIS module (base IHttpModule) that does some custom (OpenAuth) authentication before preceding to my WCF REST service. I have extended GenericPrincipal to track my user, with an IIdentity, and set the context.User field to my new principal: application.context.User = principal

However, when I receive the context in WCF (next step down the pipeline), the User shows up as a "default" unauthenticated WindowsPrincipal (not the GenericPrincipal that i set).

I see lots of stuff on the net about making this work (including aspNetCompatibilityEnabled="true" for serviceHostingEnvironment, playing with OperationContext, etc...) But nothing I have tried seems to work.

Two questions:

  1. Is there a way to get this to work (or am I just barking up the wrong tree here).
  2. What would be the canonical way to do this, or maybe the more "WCF" way to handle this custom authentication.

Thanks

A: 

You have to set your principal identity during the authorization phase in WCF. This requires a custom Authorization Policy. I suggest you read this article for more info. I've not tried to do this with a custom HttpModule and REST, but I have successfully done so with the default authentication schemes.

Randolpho