简体   繁体   English

将django-allauth与tastypie一起使用的正确方法是什么?

[英]What is the right way to use django-allauth with tastypie?

I'm writing a Django app that uses django-allauth for Facebook integration, and uses django-tastypie for a backend for an iOS app. 我正在编写一个Django应用程序,它使用django-allauth进行Facebook集成,并使用django-tastypie作为iOS应用程序的后端。 The iOS app will use the native Facebook iOS SDK. iOS应用程序将使用原生Facebook iOS SDK。 I'd like to be able to sign up and verify both Facebook and non-Facebook users from the iOS app, in addition to the website. 除了网站之外,我还希望能够从iOS应用程序中注册并验证Facebook和非Facebook用户。

The issue is that django-allauth doesn't seem to have an API that can be accessed externally. 问题是django-allauth似乎没有可以从外部访问的API。 The only clean way to plugin to allauth's functionality seems to be via Django template tags. 插入allauth功能的唯一简洁方法似乎是通过Django模板标签。 Is there a way I can expose this functionality to be used with tastypie? 有没有办法可以公开这个功能与tastypie一起使用?

Django-allauth is all open source, so I've tried to parse through the code. Django-allauth都是开源的,所以我试图解析代码。 My initial idea is to authenticate users on the iOS side using the native Facebook SDK, and then manually fill in information for SocialAccount, SocialToken, and add the SocialAccount to SocialApp (those are all django-allauth models). 我最初的想法是使用本机Facebook SDK对iOS端的用户进行身份验证,然后手动填写SocialAccount,SocialToken的信息,并将SocialAccount添加到SocialApp(这些都是django-allauth模型)。 However, that seems to be quite a hacky solution. 然而,这似乎是一个非常糟糕的解决方案。 I'd love a way to cleanly create all those models given a Facebook ID, or something similar. 我喜欢通过Facebook ID或类似方式干净地创建所有模型的方法。

Update: There's been some discussion concerning this issue on the GitHub . 更新:GitHub上有一些关于这个问题的讨论 Basically, there's no built-in functionality yet. 基本上,还没有内置功能。 I'm going to whip up a custom solution that only deals with Facebook (because that's all I'm using in my application). 我打算制定一个只处理Facebook的自定义解决方案(因为这就是我在我的应用程序中使用的所有内容)。 I'll post what I did here later if it works. 如果有效,我会发布我之后在这里做的。

Quick look into django-allauth shows that they are using SocialAccount model to hold data on specific method of authentication and type of social account. 快速浏览django-allauth表明他们正在使用SocialAccount模型来保存特定身份验证方法和社交帐户类型的数据。

You need to create an API endpoint based on SocialAccount model. 您需要基于SocialAccount模型创建API端点。 You need to pass there variables like: account type (facebook, local, twitter etc), additional auth variables needed by social auth providers. 您需要传递变量,如:帐户类型(Facebook,本地,推特等),社交身份验证提供程序所需的其他身份验证变量。 Then, in your code you can create SocialAccount model instances, feed with data received from API endpoint call and trigger corresponding auth call via django-allauth. 然后,在您的代码中,您可以创建SocialAccount模型实例,使用从API端点调用接收的数据进行提要,并通过django-allauth触发相应的auth调用。 Finally you should return result of your auth call. 最后你应该返回你的auth调用的结果。

I don't see a big reason to use django-allauth for local/facebook auth only, with some small effort you can have whole range of social auth providers. 我没有看到将django-allauth用于本地/ facebook auth的一个重要原因,通过一些小小的努力,你可以拥有全系列的社交认证提供商。

I used requests library to deal with facebook API and it works great, I think no social login plugin for Django works for others but the author, if you want to do something seriously. 我使用requests库来处理facebook API并且它工作得很好,我认为Django的社交登录插件不适用于其他人,但作者,如果你想认真做一些事情。

PS. PS。 I used django-rest-framework to build the rest backend for mobile apps, also including local account login and social site login. 我使用django-rest-framework为移动应用程序构建了休息后端,还包括本地帐户登录和社交网站登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM