13

On project I use django-rest-auth for user registration and authentication. Also i added code for facebook login:

from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
from rest_auth.registration.views import SocialLoginView

class FacebookOAuth2AdapterFixed(FacebookOAuth2Adapter):

    def __init__(self):
        pass


class FacebookLogin(SocialLoginView):
    adapter_class = FacebookOAuth2Adapter

And in my project urls.py I add

url(r'^rest-auth/facebook/$', FacebookLogin.as_view(), name='fb_login'),

But on url localhost:8000/rest-auth/facebook I see form with 2 parameters: Access token(already have) and code. enter image description here My question is next: Can I login via facebook without this code, and if not, how can I get this code without frontend? How can I check work user authentication/registration or not? PS: SocialApp created, facebook app created, app id and app secret added to social app.

Simple runner
  • 445
  • 6
  • 19
  • 1
    You don’t _log in_ using either a code or an access token. When the user is send to the FB login dialog and then redirected back from there to your app, a code is passed as a GET parameter to your app, and your app then needs to go and exchange it for an access token. And then that access token can be used to make API requests. Why you have a form to manually input either of those values, I don’t know; but that is not how FB login generally works. – CBroe Jul 08 '16 at 10:47
  • 1
    Did you got answer to your question? I have the same dilemma. – Jadav Bheda Aug 25 '16 at 23:50
  • No, I don't. got answer to this question. – Simple runner Aug 27 '16 at 09:17

2 Answers2

5

Only one of "Access Token" or "Code" field is required. (I have not tested the Code field but the Access Token field works, with the Code field left blank)

To use Access Token, after the user performs the "Login to Facebook" step on the client side using Facebook javascript SDK, you will receive a response from Facebook which includes "accessToken" for accessing data on Facebook. Simply paste this accessToken into the "Access Token" field and it will automatically login and/or create the user's account from data retrieved from Facebook.

Obviously you can then perform the same process by posting the access token to the form all in javascript.

pythonjsgeo
  • 5,122
  • 2
  • 34
  • 47
0

In the field of Access Token, Pass the User Access Token that you will get from Facebook developer dashboard(generate and debug), code field you can leave as blank. It will create user in your application and will return JWT token with user details.

PyMonk
  • 1