Gokul's Blog

Leave a comment

ServiceStack custom authentication

A good explanation on using ServiceStack custom authentication & CORS

Coding in the cloud

I learned a lot from trying to get a ServiceStack authenticate remote ajax requests. (Alternative text: “I spent a lot of hours in frustration…”)

In the end the solution is simple and does not require many lines of code.

[ Edit : see also this gist https://gist.github.com/4518393 ]

When you try to access a remote resource with ajax you will get an error saying:

Enable CORS

That is easy to deal with in ServiceStack just by adding a plugin in your AppHost Configure method:

Add Custom Authentication

If you like to use custom authentication you add a CustomCredentialsAuthProvider just like in the example in this page : https://github.com/ServiceStack/ServiceStack/wiki/Authentication-and-authorization. And then enable it with this code in Configure:

Now you should be able to try login using the default url :

Require authentication

To make a resource require authentication, just add the authenticate attribute on the DTO, on the service…

View original post 328 more words