一个简单而且最新的方法来在Django应用程序中实现Facebook登录 [英] A simple and up-to-date way to implement Facebook login in a Django app

查看:110
本文介绍了一个简单而且最新的方法来在Django应用程序中实现Facebook登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题在stackoverflow中非常普遍,并且有很多不同的问题和答案,但我找不到我需要的。



我想定义我需要的内容:让用户使用他们的Facebook凭据登录到我的应用程序的选项。该应用程序将保存一个匹配的经典Django用户。我只需要使用用户的个人资料图片,并确保每次同一个Facebook用户将与匹配的Django用户相关。



不幸的是,我发现真的很沮丧,因为以下原因:


  1. 到目前为止,阅读很多,我找不到最好的包对于这个任务。

  2. 有些人推荐django-social-auth并赞扬其功能和文档。就个人而言,我不明白为什么,因为它不是专门针对Facebook而且没有关于客户端的说明,即Facebook登录按钮以及整个流程如何工作。

  3. 当你去Facebook开发人员,你突然发现自己在阅读一些神奇的javascript sdk,以及关于一切你所需要的承诺。那么你再次感到沮丧,不能理解客户端相关的sdk如何注册用户到您的应用程序。

我知道开发人员以某种方式在他们的应用程序中实现Facebook身份验证包,但是我无法弄明白如何做到这一点。



如果有人可以告诉我:在这个时间点,什么是为我的Django应用添加Facebook身份验证的最佳方法?我还要求提供详细的文档/教程,说明如何登录Facebook用户,从设置和配置级别通过注册到Django应用程序和客户端代码。

解决方案

有多种方法来解决问题,最好的方式是什么是真正的主观。



主观上说,你可以选择 django-allauth 。以下是一些帮助您开始使用的指针:




  • 如果要保持注册简单,请设置 SOCIALACCOUNT_AUTO_SIGNUP True 以实现无问题登录。用户只需批准FB对话框,最后立即登录您的站点。


  • 将登录按钮添加到模板中只是一个问题: / p>

    < a href ={%provider_login_urlfacebook%}>登录< / a>


  • 该应用程序支持JS SDK登录(专业版:用户习惯于出现的典型FB弹出窗口),或者您可以使用自己的OAuth流。无论你喜欢什么。



This issue is very common in stackoverflow, and there's a lot of different questions and answers about it, yet I couldn't find exactly what I need.

First, I'd like to define exactly what I need: the option to let users log in to my app using their Facebook credentials. The app will save a matching classic Django user. I will only need to use the user's profile picture and to make sure that each time the same Facebook user will be related to the matching Django user.

Unfortunately, I find it really frustrating to implement for the following reasons:

  1. By now, after reading a lot, I couldn't find out what is the best package for this task.
  2. Some people recommend django-social-auth and praise its functionality and documentation. Personally, I don't understand why, since it's not specifically for Facebook and there are no explanations about the client side, i.e the Facebook login button and how the whole flow works.
  3. When you go to Facebook developers, you suddenly find yourself reading about some magical javascript sdk, and about a promise that that's all you need. Then you get frustrated again and can't understand how a client side related sdk can sign up users to your app.

I know developers somehow implement Facebook auth packages in their apps, but I just can't figure out how to do it.

If anyone could tell me: at this time point, what is the best way to add Facebook authentication to my Django app? I would also ask for detailed documentation / tutorial that explains how to log in a Facebook user, from settings and configuration level through signup to Django app and to client side code.

解决方案

There are multiple ways to approach the problem, what is the "best" way is really subjective.

Subjectively speaking, you could opt for django-allauth. Here are a few pointers to help you get started:

  • If you want to keep the signup simple, set SOCIALACCOUNT_AUTO_SIGNUP to True in order to achieve a "no questions asked" login. Users simply approve the FB dialog and they end up logged in in your site right away.

  • Adding a login button to your template is merely a matter of:

    <a href="{% provider_login_url "facebook" %}">Sign In</a>

  • The app offers support for the JS SDK login (pro: users are accustomed to the typical FB popup that appears), or you can use your own OAuth flow. Whatever you please.

这篇关于一个简单而且最新的方法来在Django应用程序中实现Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆