In this article I am going to show how to use Authorization and Authentication using a WCF service in Enterprise Architecting standards. This article is about advanced WCF concepts. I am using an error driven approach for better experience with the problems and the solutions.
The core aspects we cover here are:
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.
Stay tuned to my blog, twitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.
The core aspects we cover here are:
- WCF
- ASP.NET Authentication Service
- Custom Authentication
- HTTP Cookies
- Authorization PrincipalPermission attribute
- Thread CurrentPrincipal
- Message Interceptors
- Create a WCF Service Application
- Add a AuthenticationService.svc reusing the ASP.NET Authentication Service
- Create a User Validator class
- Enable Custom Authentication in Global.asax
- Return Cookie if valid user
- Modify service configuration
- Try accessing the Authentication Service in the browser
- Create a UtilityService.svc with a method named GetData(int)
- Decorate GetData(int) with the PrincipalPermission attribute for Authorized Access only
- Decorate the UtilityService class with the AspNetCompatibilityRequirements attribute
- Set he Utility Service constructor to set CurrentPrincipal from the Cookie
- Create the client application and add references to both services
- Create the Authentication Service instance and invoke the Login() method
- Receive the cookie and store it
- Create the UtilityService instance and invoke GetData()
- Attach the Cookie to the UtilityService client
- Test the application and ensure proper functioning
- Move the cookie attaching code to Interceptors in the Client Application
- Move the identity setting code to Interceptors in the Service Application
- Modify the service side code to include Role instead of Name
- Use Encrypted Ticket for storing User Name and Roles
- Retest the application
Stay tuned to my blog, twitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.
No comments:
Post a Comment