Plug in django-allauth as endpoint in django-rest-framework

后端 未结 4 1272
遥遥无期
遥遥无期 2021-01-30 10:58

I\'m using django-allauth on my website for social logins. I also have a REST API powered by django-rest-framework that serves as the backend of a mobile app. Is there a way I c

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 11:17

    While I'm not quite sure how to use allauth and rest-fremework together, allauth does not offer such an endpoint.

    Suggestion: make your own that does a variation of the following:
    Call allauth.socialaccount.providers.facebook.views.fb_complete_login(None, socialtoken) where socialtoken is as created in login_by_token. That performs (a few functions deeper) a django.contrib.auth.login, possibly creating the acct.

    After that, for use on mobile devices, it might be possible to the the auth (not FB) token: get the user data (from session?), and call rest_framework.authtoken.views.obtain_auth_token

    Notes:
    1. This offers no way to resolve email conflicts or connect social/local accts.
    2. I haven't tried it - please post code if you can get it working.

提交回复
热议问题