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 :)
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) :
On the angular side, user authenticate on facebook with Oauth.io API (it could be directly with Facebook js API).
Client gets a Facebook authentication token.
FB token is used to ask for authentication on server side.
python-social-auth authenticate with FB with the given token.
django-rest-framework sends back to client a auth token for REST API calls.
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
This repo is designed with php on authenticate server side but it has all of the facebook login code you would need for angular. It should give you an overall idea of how to get started:
https://github.com/Terumi/AngularJS-Facebook-Login
Related
I have created a WebAPI for user authentication using Token Authentication built on Django Rest Framework. with the help of Postman I am able to determine that my user is being created, authenticated and logged out successfully.
I have created a Django web application and have successfully consumed the WebAPI endpoints which do not require authentication in my HTML files.
Now I wish to create user Login/Logout functionality and since I am new to the subject, I don't know how to do this.
Please help? a link to a tutorial would be appreciated
Regards,
Arun
That not token authentication but may be help you
clik
I am creating a Flutter project with Django + Django Rest framework as the backend. I want to add user authentication to the app.
I found some ways to achieve that such as Session authentication or token authentication. According to this article, if we want to add user authentication for mobile-based apps, it is best to use token authentication since session authentication is not suited for mobile phones.
Is it really best to use token authentication for mobile-based apps instead of session authentication?
Yes, token is best for mobile client.
Mobile and cookies are not good friends ;)
Token authentication work well for multiple device connection with same account and it's easier to store token.
It's stateless and work without cookies.
I have worked on two projects with Django and flutter.
I think for android or ios projects, token based authentication is best to go with because they are stateless and you can easily manage user roles and permissions for the application too.
From security point of view, it's also better because there's no possibility of creating a CSRF request when you app is using tokens.
Cookies don't fit much with other platform than a browser.
I am developing Django(Server) with React(Web Client).
And I want to use facebook social login.
I knew that client is public client, server is confidential. So I want to use authentication code grant way for authenticating user.
So I find out the way but there is no way to implement that. All the python oauth2 library limplements is just for django server side rendering.(Django Server + Web client).
So I confused about I am wrong or just the others just did not make the grant way.
When you use DRF(Server API) + React(public Web Client),
how do you implement for OAuth2 social login?
I wonder that. please give me some advise to me.
Thanks.
Let's start from basics, people usually split frontend and backend to improve the production speed as frontend and backend can be developed by two separate teams. But in order for the frontend and backend to work together, there needs to be a connection interface, an API.
React is a frontend that runs in the browser, so in order to talk to the server, it uses a REST protocol.
As the backend in this scenario is Django we use DRF as React uses REST API. DRF provides easy flexible pre-built packages to carry out this communication job between server and client.
Now the authenticator for web login you choose to be Facebook hence you will get the identity token from facebook, which will correspond to the rows in the Django User table which will give you access to the user's data in Django.
You don't need to do everything at once, you need to first implement the Facebook social auth and after test(test using postman app) only think about connecting React
A good place to start is this DRF documentation, look into Social OAuth2
https://www.django-rest-framework.org/api-guide/authentication/#django-oauth-toolkit
Hi everyone I want to put a google+ login button on my website (coded in django) w/o using any 3rd party tool like Django-Social-Auth, etc.
So can anyone point me to some tutorial or help me how to do it. I want user to login via Google+ and then I can get their information at backend in django views. I will be then hosting it on Google App Engine so if some GAE API can help me then it will also be great.
I figured out the solution:
Got access_token using https://developers.google.com/+/web/signin/javascript-flow
Then send out the access_token to Server for getting User Details, considering these security measures (https://developers.google.com/+/web/signin/client-to-server-flow).
Use Django CSRF Token functionality to send token safely (https://docs.djangoproject.com/en/dev/ref/contrib/csrf/).
I'm using Django Social Auth for connect with Facebook issue and it works perfect. I have developed an API for my Django app with Django Rest Framework. But I'm confused about using Django Social Auth with Django Rest Framework for iOS devices.
I have searched 1, 2, 3 and 4 but they are generally with Angular.js. I'm not familiar with iOS development.
What is different between facebook connect with spa and a mobile device? * How could I use these packages together?
May I migrate from django-social-auth to python-social-auth?
You can now authenticate your users against your django-rest-framework with bearer tokens/third party access tokens from any python-social-auth backend (Facebook, Google, Github, etc.) using this library https://github.com/PhilipGarnero/django-rest-framework-social-oauth2
This module provides a python-social-auth and oauth2 support for django-rest-framework. Thus this saves you a lot of time to setup what is required to have your DRF with social authorization and to be OAuth2 secure.
I think that you can achieve that using django rest framework, django-rest-auth and allauth.
Those three work nice together.
With django rest framework you already familiar.
The allauth is responsible for the social authentication.
The django-rest-auth responsible for create the RESTful api for the social authentication, i.e. the connection between django-rest-framework and allauth.
It is recommended that you let python-social-auth handle the Facebook login for you, and instead you use another OAuth plugin for Django REST Framework to authenticate with Django. This has the added benefit of also supporting non-Facebook login through the standard Django authentication system.
I'm confused about using Django Social Auth with Django Rest Framework for ios devices.
I recently answered a similar question about implementing authentication with python-social-auth and Django REST Framework. It includes some important points to read about when implementing authentication using a third party along with some important notes about how you should not pass the third-party OAuth tokens back to your client.
How could I use these packages together?
While that answer specifically mentions using OAuth as the authentication method for the API that is behind python-social-auth, you can use other authentication methods that internally use Django authentication system, such as TokenAuthentication. In any case, you will end up proxying authentication between your front end application and your third party authentication provider, using your back end API.
What is different between facebook connect with spa and a mobile device?
Facebook provides direct integration with some mobile operating systems, most notably iOS and Android. This bypasses your API for authentication, and directly authenticates your mobile application with Facebook. Ideally, it would be authenticating your back end API instead of the mobile application. This may still be possible to do if you pass the access token back to your API manually, essentially doing the same thing that python-social-auth would be doing, but that could be risky and may not be worth the extra effort.
Facebook Connect (now known as just Facebook Login) works in a similar way to how Facebook integration works on mobile devices. The one difference that may work in your favor is that it's very easy to move from Facebook Login for single page apps, to an OAuth-based authentication pattern. This is documented in the Facebook developers documentation as "Manually Building a Login Flow" and is compatible with libraries that support OAuth-based login, like python-social-auth.
May I migrate from django-social-auth to python-social-auth?
This shouldn't be an issue anymore, as python-social-auth has effectively replaced django-social-auth.