NetWave
NetWave

Reputation: 399

Pass ASP.NET membership credentials from MVC application to WCF application

I have developed an MVC application that is build on forms authentication using the ASP.NET membership provider.

The same server also contains a WCF application that points to the same database as the MVC application (including all aspnet tables).

I want to check to which groups the user belongs to in the services.

How can I pass the credentials from the MVC application to the WCF application?

Upvotes: 3

Views: 1396

Answers (2)

WDRust
WDRust

Reputation: 3713

Well, you can either

  • develop any kind of API on the MVC application for the WCF application to interact with (and that's will allow you to deploy the two things wherever you want in the future),

  • Try and let the WCF service use the Membership providers for authentication, and point the membership providers on the wcf side on the same db.

check this out

[Speaking of membership providers] Windows Communication Foundation (WCF) developers can take advantage of these features for security purposes. When integrated into an WCF application, users must supply a user name/password combination to the WCF client application. To transfer the data to the WCF service, use a binding that supports user name/password credentials, such as the WSHttpBinding (in configuration, the wsHttpBinding Element) and set the client credential type to UserName. On the service, WCF security authenticates the user based on the user name and password, and also assigns the role specified by the ASP.NET role.

That's the article containing configuration samples

Hope i understood your needs.

Upvotes: 1

Jed
Jed

Reputation: 10877

Since you are using the Membership Provider, you could check the Identity (the authenticated user) that is running the thread that is accessing your resource in the WCF application via System.Threading.Thread.CurrentPrincipal.Identity.

Example:

In your WCF application, you can have a method that discovers the authenticated user then, from there, query your DB to get the groups that the user is a member of:

static List<UserGroup> GetUserGroups()
{

// Get the authenticated username
string username = System.Threading.Thread.CurrentPrincipal.Identity.Name;

// Get the user's groups from your data store and pack them up in a list
...
etc

}

Upvotes: 0

Related Questions