Rails and ASP.NET Single Sign-On

I have an ASP.NET application that uses auth forms and saves credentials in a table - pretty vanilla. Since I know how the password is hashed, can I somehow separate the auth cookie forms with Rails, effectively creating single sign-on? Both web applications will live in the same domain.

+4
source share
2 answers

You can share ASP.NET Forms Auth Cookies with Rails, but you will have to decrypt it on the Rails side. Maybe this is too much trouble.

A simpler solution is to skip the .NET Authentication Ticket and save your own authorization ticket (cookie) on both sides using the encryption algorithm you want and the same salt between the two platforms. Salt can be stored in the database or in a physical file if they are on the same disk.

Example:

C # side:

public class MyTicket { ... public string ToSerializableFormat() { return String.Format("{0}|{1}", t.Username, t.somethingElseYouNeed); } public static MyTicket Parse(string value) { var vals = value.Split('|'); return MyTicket(values[0], values[1]); } } 

Somewhere else in your application, replacing the calls to FormsAuthentication.Encrypt and FormsAuthentication.Decrypt :

 string MakeTicket(MyTicket t) { return EncryptSomehow(key, t.ToSerializableFormat()); } MyTicket ReadTicket(string cookieValue) { return MyTicket.Parse( DecryptSomehow(key, cookieValue) ); } 

And the Ruby equivalent:

 class MyTicket def to_serializable_format "#{@username}|#{@something_else}" end def self.parse(value) values = value.split '|' MyTicket.new(*values) end end 

Somewhere in the Rails code, you will decrypt and encrypt the auth cookie. Use the same name on both sides.

Profit

+7
source

I don't know about sharing the auth cookie - this will probably be tricky. But sharing identity information will be quite simple.

I would write a user model in Rails that acts as an adapter to your existing identity table using the establish_connection trick:

 class User < ActiveRecord::Base establish_connection( { :adapter => "mysql", :database => "db_name", :host => "db.example.com", :username => "user", :password => "password" }) end 

this will connect the User model to another db. The event is better, you can add another entry to database.yml and load it here.

Then you just need to overload the access functions to work with a non-standard scheme.

0
source

All Articles