作者:小豇豆和花椰菜 | 来源:互联网 | 2023-05-18 23:18
Ivelookedatroughly50questionsonthissite,butnonereallyprovideasolutionthatiseither
I've looked at roughly 50 questions on this site, but none really provide a solution that is either up to date or doesn't require a third part pluggin (I want to keep control of the information and not give other people access to the info I get) or that is complete. I'll take the risk of posting it, and cross my fingers.
我在本网站上查看了大约50个问题,但没有一个真正提供最新的解决方案或者不需要第三部分插件(我想保持对信息的控制而不是让其他人访问我得到的信息)或那是完整的。我会冒着发布它的风险,然后交叉我的手指。
I've seen a bunch more but here are some I looked at:
我已经看到了更多,但这里有一些我看过:
- include facebook and twitter as login option (all answers are third party solutions)
包括facebook和twitter作为登录选项(所有答案都是第三方解决方案)
- https://stackoverflow.com/questions/76184/php-tutorial-for-openid-and-oauth (3yeras old, there must be easier implementation)
https://stackoverflow.com/questions/76184/php-tutorial-for-openid-and-oauth(3岁,必须更容易实现)
- http://wiki.openid.net/w/page/12995176/Libraries => this looks good, but I'm still confused.
http://wiki.openid.net/w/page/12995176/Libraries =>这看起来不错,但我仍然很困惑。
So I'm looking to have Facebook, Google and Twitter as login options on my site (Apparently, that is 80% of peoples preferred social login method).
If I go to the wiki.openid.net, which package would you advise me to use in PHP for easy implementation? Which one did you use in the past?
因此,我希望将Facebook,Google和Twitter作为我网站上的登录选项(显然,这是人们首选的社交登录方式的80%)。如果我去wiki.openid.net,你会建议我使用哪个软件包来轻松实现?你过去使用过哪一个?
Also, if possible, can you give explanations on how to implement the advised library? ie,
另外,如果可能的话,您能解释一下如何实施建议的库吗?即
- I download it, put it on my site,
我下载它,把它放在我的网站上,
- then get an openID for my site,
然后获取我的网站的openID,
- then use the the http://code.google.com/p/openid-selector/ for the display...
然后使用http://code.google.com/p/openid-selector/进行显示...
Is this right? I have no idea...
这是正确的吗?我不知道...
Basically a step by step guide would be awesome. I'm sure anyone who takes time to answer this will get massive points, this is hot topic.
基本上一步一步的指南会很棒。我敢肯定,任何花时间回答这个问题的人都会获得大量积分,这是热门话题。
Thanks for the help.
谢谢您的帮助。
3 个解决方案
11
So you want to implement Google and Facebook/Twitter login, without using a third party service. That means you need to implement OpenID login (for Google) and OAuth (for Facebook/Twitter).
因此,您希望在不使用第三方服务的情况下实施Google和Facebook / Twitter登录。这意味着您需要实施OpenID登录(针对Google)和OAuth(针对Facebook / Twitter)。
First OpenID. You can download LightOpenID a nice lightweight OpenID class for PHP. Quite easy to implement. Some samplecode how to use this class.
第一个OpenID。您可以为Light下载LightOpenID一个很好的轻量级OpenID类。很容易实现。一些samplecode如何使用这个类。
// Set up your OpenID object
$openid = new LightOpenID('http://yourdomain.com');
$openid->returnUrl = 'http://yourdomain.com/after/login/user/goes/here';
$openid->identity = 'https://www.google.com/accounts/o8/id'; // OpenID provider URL
$openid->required = array('namePerson/friendly', 'contact/email');
// Step 1: Redirect the user to the OpenID provider
if (!$openid->mode) // If not authenticated
header('Location: ' . $openid->authUrl()); // Redirect to provider
// Step 2: User returned, sign the user into our application
if ($openid->validate()) {
// OpenID authentication is successful
// Sign in the user and read requested attributes
$attrArray = $openid->getAttributes();
}
That should get you started with the OpenID part. The OpenID selector is nothing more then a selector for the identity URL.
这应该让你开始使用OpenID部分。 OpenID选择器只不过是身份URL的选择器。
Then implementing OAuth sign in to support Facebook and Twitter sign in. There is quite some documentation on how to implement Facebook and Twitter login support. For Facebook you should read the developer site on authentication it's not too complicated. Twitter uses the same protocol and also has quite nice documentation on this topic.
然后实施OAuth登录以支持Facebook和Twitter登录。有一些关于如何实现Facebook和Twitter登录支持的文档。对于Facebook,你应该阅读开发者网站的认证,这不是太复杂。 Twitter使用相同的协议,并且在此主题上也有相当不错的文档。
If you don't want to implement it yourself take a look at OAuth libraries that you can include in your application like socialoauth (supports both) or twitteroauth (supports twitter). Google will help you find a lot more libraries like this.
如果您不想自己实现它,请查看您可以在应用程序中包含的OAuth库,例如socialoauth(支持两者)或twitteroauth(支持twitter)。谷歌将帮助您找到更多这样的图书馆。
Just start implementing with a library read the code, comments and docs and ask questions on StackOverflow if your stuck. :)
刚开始使用库实现读取代码,注释和文档,并在StackOverflow上提问如果卡住了。 :)