Showing posts with label Authentication. Show all posts
Showing posts with label Authentication. Show all posts

Thursday, 8 April 2010

How to preserve the user information in service context

This is follow up to my previous blog on things to watch out when developing application using SL3 + RIA. One issue I ran into during the testing is that the user information did not get persisted as I would have thought. One of the implementation suggested that, Use create the Authentication Service and then implement a singleton pattern to preserve the user once the validation user is successful. From there all the services can consume the singleton user. In my development everything worked great. I didn’t even think twice because each service request will run in its own application domain and so singleton will be a good solution. Well it turned out that my ‘assumption’ was wrong. It seems when two people access the same silver light page, the first user information gets the store and all following users end up using the first user identity and of course it is wrong.

To resolve that problem, I ended up removing the singleton user and started access the User information directly off of ServiceContext.User, but here is the catch. If you override the User information with your custom user and added some property to it, it is not available. But for starters, I have resolved the current problem and I will revisit to see why I can not user custom user I have created.

Wednesday, 10 March 2010

SL3 + RIA custom authentication

I have been playing with Custom Authentication lately and while trying out, I ran into bunch of problem. So I thought I will point out few of things you need to watch out. When you create a SL3 + RIA services, it automatically gives you Windows Authentication. When you need to change to custom authentication, couple of things you need to change and for that I would recommend Brad Abrams (ex-Microsoft) blog

If you are new to this area I would strongly recommend you to look at the authentication quick starts in the following URL, they are very simple and easy to follow.

http://code.msdn.microsoft.com/RiaServices

while you are at it, I would recommend visiting this Silverlight forum question to have an understanding of authentication as well.

Few things to watch out are

1. Make sure you have <authentication mode="Forms" /> in your web.config at the WCF service side.

2. The USER return from GetAuthenticatedUser has a catch, if you do not assign the name to the returning user, then by default IsAuthenticated flag will be false.

3. Make sure you have authentication setup to form authentication in silver light app.xaml.

<local:WebContext.Authentication>
                <appsvc:FormsAuthentication></appsvc:FormsAuthentication>
</local:WebContext.Authentication>

4. If you have a page where you are authenticating and then data binding, do not do data binding till you complete the validation. In other words, make sure you add the root visual element on login completed method delegate.

If you run into any other problems let me know or if you have any comments or suggestion also send me a mail.