trembler2003
trembler2003

Reputation: 567

MVC3 Application using Forms Authentication consuming WCF in other solutions

Here's our scenario:

So essentially, what we require is that access to the two WCF services can be done from the MVC site by users already authenticated through the MVC application and in the case of the W2 service, we need to know which user it is. Any access to the WCF services outside the MVC site needs to also be authenticated or shouldn't work (no anonymous access to the WCF services is permitted).

Is there a standard approach to solving this problem? Does anyone know of any sample projects where I can see this kind of thing in action?

A few extra details - we are using Visual Studio 2012 RC, .NET 4.5 and IIS7.

Thanks

Upvotes: 1

Views: 990

Answers (1)

VJAI
VJAI

Reputation: 32758

I guess what you are trying to achieve is sharing the Forms Authentication across MVC application and the WCF services. You could do that :)

The idea is you have to share the cookie from the MVC application to the WCF services.

Following are the things you have to take care on doing this.

  1. The MVC and WCF services should use the same forms and machineKey sections in the web.config. See here. Means WCF services should also use forms authentication and all the three of them should share the same machine key to have the cookie being shared.

  2. Of course the WCF services should run in asp.net compatibility mode.

  3. When making calls to WCF services you should manually add the forms authentication cookie to the outgoing message header. See here.

EDIT:

Based upon the OP's comment I'm updating my answer.

The above solution seems to be good when the WCF service has to be used only by the MVC and not by other clients. But if the WCF service also want to be consumed by different clients other than the MVC project then the client will face tough time because they have to construct the cookie and append to the request (i'm not sure whether this is possible!).

So little more elegant solution would be make the WCF services self-contained, means, integrate the authentication/authorization mechanism separately to it. One way is you can easily integrate the ASP.NET membership provider to the WCF services. By this way the authentication will happen separately at the WCF service side. The other advantages are third-party clients or other applications can easily consume the WCF service passing the credentials through the proxy.

So here is a link that says how to configure asp.net membership provider in WCF service,

Upvotes: 1

Related Questions