Gokul's Blog

ServiceStack custom authentication

Leave a comment

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s