WCF Authentication

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
7/26/2010 12:56:46 PM
Gravatar
Total Posts 72

WCF Authentication

Hi Joe,

I mentioned a while a go that I was building a user files feature (each mojo user can have their own private files). I've completed the web site developments and I now need to expose the files via a WCF service.

Since I need to check the user with each service call I was just going to pass the username and password as service parameters and use the default Membership.ValidateUser methods:

            if (Membership.ValidateUser(username, password))
            {

var user = SiteUser.GetByEmail(CacheHelper.GetCurrentSiteSettings(), username);
if (user != null)
{
// return user data
return user.Name;
}
else
{
return "Could not find user with email " + username;
}
}
else
{
return "Invalid user";
}              

I see you have included the built in AuthenticationService WCF service in mp. It is my understanding that I would need to handle the validating of the user then in the client before calling my custom service? I would rather do it all at once so am thinking my method above will be best.

Just thought I would get your opinions before I go ahead with it.

Thanks

Ben

7/27/2010 10:18:09 AM
Gravatar
Total Posts 18439

Re: WCF Authentication

As long as the web service is in the same site, then you should not need to pass anything, and should be able to get the current user with

SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

Hope it helps,

Joe

7/27/2010 11:48:12 AM
Gravatar
Total Posts 72

Re: WCF Authentication

Hi Joe,

It's from a WPF app (not silverlight) so no http context so think I need to do it how I have done above.

7/28/2010 7:20:06 AM
Gravatar
Total Posts 18439

Re: WCF Authentication

HttpContext definitely exists on the server, but Context.User.Identity is based on the authentication cookie, so if there is not an authentication cookie then there will not be an identity.

I haven't done any WPF against web service work myself, but would have thought it could store an authentication cookie just like a browser in which case it should work, but if it doesn't support cookies I guess you really would need to send credentials for each request or some other approach.  

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.