跳至主要内容

Single Sign On (sso)

Well, let me explain a bit further then. (All URLs are fictional!) As I said, the visitor goes tohttp://www.yourwebpage.com and indicates he wants to log in. He is redirected tohttp://your.loginpage.org?return=http://www.yourwebpage.com/Authenticated where he will have to provide his username and password.
When his account information is valid, he will return to the page that was provided in the login URL, but with an additional parameter that will be used as ID. Thus, he goes tohttp://www.yourwebpage.com/Authenticated?ID=SharedSecret where SharedSecret would be a temporary ID, valid for 30 seconds or less.
When your authentication page gets called, the page would then call a method that's shared between yourwebpage.com and loginpage.org to look for the account information of SharedSecret to retrieve a more permanent ID. This permanent ID is stored in the web session of yourwebpage.com and should NEVER be shown to the user.
The shared method could be anything. If both servers are on the same machine, they could just both access the same database. Otherwise, they might communicate with another server through web services. This would be server-to-server communication thus it doesn't matter if the user is a robot or has no cookie support. This part won't be noticed by the user.
The only thing you'll have to deal with is the session for the user. Normally, users will be sent a session ID that's stored in a cookie but it can also be part of the URL as part of a GET request. It's a bit more secure to have the session ID inside a POST request, though, by adding a hidden input field to your form.

Fortunately, several web development languages do already provide session support so you don't even have to worry about maintaining sessions and sending session ID's. The technique is interesting, though. And you need to be aware that sessions should always be temporary since there's a risk that session ID's get hijacked. 

If you have to deal with multiple sites on different domains then you will need to work on some server-to-server communication first. The easiest would be by letting them share the same database but it's better to build a web service around this database, for additional protection. Make sure this web service only accepts requests from your own domains just to add even a bit more protection.
When you have server-to-server connections, then the user will be able to switch between your domains and as long as you're passing along a session ID to the new domain, the user will be logged in. If the user is using cookies, it's not very likely that the session gets lost which would require to log in again. Without cookies, there's a chance that the user will have to log in again to get a new cookie if the session ID gets lost between browsing pages. (For example, the visitor goes to visit Google and then goes back to your site. With a cookie, the session could be read from the cookie. Without a cookie the session is lost since Google won't pass the session ID forwards.

Do keep in mind that passing on session ID's between different domains is a security risk. The session ID can be hijacked, thus making it possible for someone else to impersonate your visitor. Therefore, session ID's should be short-lived and obfuscated. But even if a hacker gains access to a session ID, he still won't have full access to the account itself. He won't be able to intercept the server-to-server communication so he can't access the database with your user information, unless he goes to the login page directly.

从stack overflow里摘过来的,写的很好,简明扼要的解释了多个domain共享login的方法和概念

评论

此博客中的热门博文

jquery on 的问题

return false  from  within a jQuery event handler  is effectively the same as calling both  e.preventDefault and  e.stopPropagation  on the passed  jQuery.Event object. e.preventDefault()  will prevent the default event from occuring,  e.stopPropagation()  will prevent the evet from bubbling up and  return false  will do both. Note that this behaviour differs from  normal  (non-jQuery) event handlers, in which, notably,  return false   does  not  stop the event from bubbling up . 所以on前半部分的selector必须是静态的。

chrome extension Error: attempting to use a disconnected prot object

if you get this error: Port error: Could not establish connection. Receiving end does not exist. miscellaneous_bindings:236 chromeHidden.Port.dispatchOnDisconnect miscellaneous_bindings:236 Uncaught Error: Attempting to use a disconnected port object miscellaneous_bindings:58 PortImpl.postMessage miscellaneous_bindings:58 responseCallback miscellaneous_bindings:143 xhr.onreadystatechange That means you have make some mistake as this discussed: This is caused when a connection get closed. For example if you open a tab that has the content_script injected, it opens a connection, the tab is closed, and then the background_page tries to pass a message. It will fail because the tab is no longer active to receive the message. In your case I would guess that as tabs close and new tabs open you are attempting to post messages with the old tabId instead of creating a new connection to the new tab. I would recommend reading through the  long-lived connections s

记得很久以前,不知道是在跟谁发感慨,久到好像是上大学时候的事了。我说,我流过很多眼泪,看电影流眼泪,看小说流眼泪,听别人的故事留言了,听歌的时候流眼泪,晚上一个人的时候独自流眼泪。我似乎是一个是一个太不像男人的男人。可是我又说,这些眼泪都是为自己流的。于是我也问对面那个人,(嗯,我也记不起她是谁了): "你为别人流过眼泪么?",居然没有回答我. 也许看见这篇文章的人也不相信,但是我真的想问你一句,你为别人流过眼泪么?真真正正的是为别人的,不是可怜自己,不是觉得别人可怜而让自己也感到了可怜,仅仅是为了别人而悲伤,有过么?如果真的有,我想那也许才是爱吧。 也许您会觉得奇怪,这和爱有什么关系?是啊,流眼泪就是爱么?我们因为悲伤而流泪,流泪是因为,爱别离,求不得,这些的主体是什么?是自己。 我们都是爱自己的,只是99%的人是吧。所以我们流泪了,因为我们的那些种种原因,我们很少会因为别人“求不得,爱别离”而流泪吧。也许说,那又不是自己,对呀,你爱自己,你又不爱她,何苦要为她流这种泪? 我不是一个宽容的人,我也不是一个豁达的人,这是我一生的缺点。我们会为了爱去宽容,我们会因为爱而变的豁达,也许,这是因为我从来都没有真正的爱过谁吧,甚至,连自己。嘿,我现在都开始疑惑,我真的爱过你么,如果是,我为什么都没有宽容和豁达呢?