Reputation: 11935
I tried to use Django AllAuth to make a registration user by Facebook.
I have to make a REST API so I would to use Django REST Framework.
I found this simple tutorial to make the first user registration but probably there are some difference from current implementation:
I tried this code:
def post(self, request):
data = JSONParser().parse(request)
access_token = data.get('access_token', '')
try:
app = SocialApp.objects.get(provider="facebook")
token = SocialToken(app=app, token=access_token)
# check token against facebook
login = fb_complete_login(app, token)
login.token = token
login.state = SocialLogin.state_from_request(request)
# add or update the user into users table
ret = complete_social_login(request, login)
# if we get here we've succeeded
return Response(status=200, data={
'success': True,
'username': request.user.username,
'user_id': request.user.pk,
})
except:
traceback.print_exc()
return Response(status=401, data={
'success': False,
'reason': "Bad Access Token",
})
but now I see that fb_complete_login
take 3 parameters: request
, app
and token
.
So, I tried to put also the request like this function parameter but some lines later I have an error on login = fb_complete_login(app, token)
.
TypeError: add_message() argument must be an HttpRequest object, not 'Request'.
Any suggestions are welcome!
Upvotes: 2
Views: 1204
Reputation: 304
Solution given here: http://tech.agilitynerd.com/django-rest-registration-with-django-rest-auth.html
To disable messaging just for allauth, override the adapter (for instance in main.adapters):
from allauth.account.adapter import DefaultAccountAdapter
class MessageFreeAdapter(DefaultAccountAdapter):
def add_message(self, request, level, message_template,
message_context=None, extra_tags=''):
pass
then add this in settings.py:
ACCOUNT_ADAPTER = 'main.adapters.MessageFreeAdapter'
Upvotes: 2