Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I always seem to figure out the answers right after I post the question. In any case, the following is a custom method on UserResource (tastypie api using ApiKeyAuthentication). Most of it was taken from the login_by_token method in allauth.socialaccount.providers.facebook.views.</p> <p>I won't select my answer as correct for a while in case anyone posts a better answer.</p> <pre><code>def facebook_login(self, request, **kwargs): self.method_check(request, allowed=['post']) data = self.deserialize(request, request.raw_post_data, format=request.META.get('CONTENT_TYPE', 'application/json')) access_token = data.get('access_token', '') from allauth.socialaccount import providers from allauth.socialaccount.models import SocialLogin, SocialToken, SocialApp from allauth.socialaccount.providers.facebook.views import fb_complete_login from allauth.socialaccount.helpers import complete_social_login try: app = SocialApp.objects.get(provider="facebook") token = SocialToken(app=app, token=access_token) login = fb_complete_login(app, token) login.token = token login.state = SocialLogin.state_from_request(request) ret = complete_social_login(request, login) #if we get here we've succeeded return self.create_response(request, { 'success': True, 'username': request.user.username, 'user_id': request.user.pk, 'api_key': request.user.api_key.key, } ) except: # FIXME: Catch only what is needed return self.create_response(request, { 'success': False, 'reason': "Bad Access Token", }, HttpForbidden ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload