What is the right way to use django-allauth with tastypie?
Asked Answered
S

2

12

I'm writing a Django app that uses django-allauth for Facebook integration, and uses django-tastypie for a backend for an iOS app. The iOS app will use the native 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.

The issue is that django-allauth doesn't seem to have an API that can be accessed externally. The only clean way to plugin to allauth's functionality seems to be via Django template tags. Is there a way I can expose this functionality to be used with tastypie?

Django-allauth is all open source, so I've tried to parse through the code. 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). 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.

Update: There's been some discussion concerning this issue on the 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). I'll post what I did here later if it works.

Stroganoff answered 13/8, 2013 at 17:8 Comment(0)
E
1

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.

You need to create an API endpoint based on SocialAccount model. You need to pass there variables like: account type (facebook, local, twitter etc), additional auth variables needed by social auth providers. 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. Finally you should return result of your auth call.

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.

Eastwards answered 17/10, 2013 at 14:38 Comment(0)
D
0

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.

PS. I used django-rest-framework to build the rest backend for mobile apps, also including local account login and social site login.

Dysarthria answered 1/9, 2013 at 7:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.