weixin_33725807 2016-02-26 10:00 采纳率: 0%
浏览 91

跨域登录

Let's say I've one site LoginSite and other two sites site1 and site2.

Now, If user logs in from LoginSite then he/she should be automatically logged in into the site1 and site2.


I've tried below two ways for the same

Way1 :: using ajax

I've white listed LoginSite's domain into site1 and site2.

But, It has only enabled cross domain ajax requests. It is not storing session for site1 and site2.

Way2 :: using cURL

I've tried the same using cURL by set of below code.

$username="mylogin@gmail.com"; 
$password="mypassword"; 
$url="http://site1.com/api/login"; 
$cookie="cookie.txt"; 

$postdata = "username=myusername@gmail.com&password=mypassword";

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 

echo $result;  
curl_close($ch);

Above code is not working. There must be something missing. I guess somehow I've to return sessionID from site1 and use it.

Pl. help/guide me how to do this.

Note : I do not want to post form to site1 or site2

  • 写回答

1条回答 默认 最新

  • larry*wei 2016-02-26 10:09
    关注

    LoginSite must generate a UniqueID and give it back to the connected User, it will be used as a token
    When User connect to site2 it will send his token, and site2 will ask for his validity, if it still valid, so it will accept the connection and creting a session

    Conclusion : think about token, validity and security :)

    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上