views:

704

answers:

2

I am putting a plan together for a series of sites that will share user account information among them. The idea is that once a user logs in using their OpenID, they can access any of the sites and it will know who they are.

What are the common patterns/best practices that i could employ to achieve this?

+6  A: 

If all the sites share a common hostname in their URL then you can set an auth cookie (FormsAuthentication.SetAuthCookie) specifying the path of the cookie to be "/" so that all sites can see the user is logged in.

If the sites are not sharing a common host name, I think the only way to get a truly "once signed in, signed in everywhere [within your ring of web sites]" would be for all authentication to happen at just one site (perhaps one dedicated to authenticating the user) and for the other sites to redirect the user to that site for authentication and then that site would redirect back. In essence, that auth site becomes an identity provider, and almost exactly fills the role of an OpenID Provider (in fact DotNetOpenAuth could be used here for this exact purpose). Since it sounds like your goal is to let the user log in with their OpenID, your OpenID Provider on that one auth site could itself use OpenID to authenticate the user. Your own pure-delegation OpenID Provider could be written such that it always responds immediately to checkid_immediate requests as long as the Realm in the auth request is one of your trusted ring of sites. Thus you could effect single-sign-on across all your sites.

Andrew Arnott
RE setting global auth cookie: wouldn't that cause a vulnerability? I forgot what this kind of attack is called, but it's when the authcookie is stolen. Or am I mistaken that this is not safe?One more thing - is that how the new Stack Exchange sites do it (after you log in on the main one you are automatically logged in on its meta)?
Maxim Zaslavsky
This isn't a global cookie. It's only as wide as a single Internet host, as most cookies are. And you'd only want to do this if you control or trust all sites on that host.If all *.stackexchange.com sites share a login for a user, then perhaps the cookie is domain-wide.
Andrew Arnott
+1  A: 

Please consider the following Patterns & Practices on Web Service Security from Microsoft:

Brokered Authentication - http://msdn.microsoft.com/en-us/library/aa480560.aspx

The main topic is - Web Service Security

Scenarios, Patterns, and Implementation Guidance for Web Services Enhancements (WSE) 3.0

http://msdn.microsoft.com/en-us/library/aa480545.aspx

Ultimately theres lots of ways you could do it. I achieved a simple single sign on by building a url with a token from one website pointing to another domain. The encoded & encrypted token contained details to submit back to the previous domain. Upon receiving an incoming request on the second domain, an underlying web service checks that the incoming request's token is valid with the previous domain using a shared private secret, known to both domains.

Rabid