Search code examples
djangoangularjsfacebook-authentication

Django Angular Facebook authentication


I want to do a very simple web app where you can log-in using your facebook account.

I am very comfortable with the django framework and also angularjs. I have an idea how to integrate these two using tastypie api framework for django.

So if I am correct django's backend would be throwing some JSON which can be used by angularjs and so on.

Where I am confused is the authentication mechanism with facebook. How do I integrate the Facebook's authentication with my app ? What would be a good design for such an app ?

I am not expecting a complete design or architecture for my app from anyone , but some direction so that I can go forward with the app .

Thanks :)


Solution

  • I wrote a small article on this subject as it seems it was not clearly explained anywhere. I found it easily done with django-rest-framework instead of tastypie though.

    Here are the main steps used to authenticate (I’ll try to add a little schema to illustrate) :

    1. On the angular side, user authenticate on facebook with Oauth.io API (it could be directly with Facebook js API).
    2. Client gets a Facebook authentication token.
    3. FB token is used to ask for authentication on server side.
    4. python-social-auth authenticate with FB with the given token.
    5. django-rest-framework sends back to client a auth token for REST API calls.
    6. Angular client passes the token in headers when making API calls.

    You can find my article here about facebook angularjs auth with a django rest backend