Python Social Auth - Facebook Auth API v2.5 - python

I'm using python-social-auth. On June I've created the app on developers.facebook.com. Facebook's api version is v2.2. Everything is working.
Additionally my user model using email as username so I defined in settings.py SOCIAL_AUTH_FACEBOOK_SCOPE = ['email'].
Today I've created new app on developers.facebook.com, api version is v2.5. Configuration of app is the same like in my v2.2 app. There is a problem. After redirect from facebook.com, Im using create_user() to create user. I don't know why I've know user data (email, gender, etc) I've only UID, first name and second name.
Of course Im testing social authentication in one www project.
It may be the fault of Facebook App Update?

Related

If the user visits my flask website from his/her email; how can I get his/her email address?

If the user has a mail message containing a link to my webapp which is built in flask. The user clicks the link and visits my site.
The question now: how can I configure my flask app to detect that this user has visited the site via email?
You can configure the URL as a campaign. So for example:
https://www.example.com/?utm_source=newsletter&utm_medium=email
You can build the link here: https://ga-dev-tools.appspot.com/campaign-url-builder/
Then in your app, you can get the utm_source and utm_medium like so:
from flask import request
source = request.args.get('utm_source')
medium = request.args.get('utm_medium')
It also works with Google Analytics if you have G Analytics installed.

Native app rest api social login flow

I am developing a native frontend application which communicates with a backend rest api built using python django rest framework.
The rest framework uses django rest framework token authentication in which every user has an authorization token and the token will have to be attached to the header of every http request to the rest api in the form of “Authorization: Token ”.
My application provides the user with two main ways to login. The first one is to register an account with username and password. This will create a django User model object and a token will be generated. This login method works well.
The second login method is to login with the user's social account. My idea is whenever an user login with their facebook account, the app will be redirected to my website which will then redirect the user to the social media of their choice. After authorizing the social media api will redirect them to my website again which a user and a token will be created. Then my website will redirect back to my native app using a custom uri with the token attached in the uri like this:
myapp://authenticate#token=xhskscjndjnccjdsdc
The native app will then parse the uri and obtain the token.
The part that I am worried about is security. This method works but attaching a token in an uri seems a bit insecure to me. Is there any best practice that I can follow? Thanks!
I can propose you to use django-rest-auth for dealing with Authentification and Registration.
With that package/library you can use Social Authentication through Facebook, Twitter, Google or other provider.

Using OAuth for django, how to save username from google account to database

I have managed to use Google authentication in my django site. The problem is when I go to user profile which is: http://127.0.0.1:8000/user/username
for example if my google username is Chazefate then when I go to Profile then this site is not avaible, because it didn't save the user to database, I think.
http://127.0.0.1:8000/user/Chazefate
I am using django python social auth.
So the main question is how can I save this google user in my database.

Facebook status update using django

I have used python-social-auth for social authentication in my django application. Now I am going to post facebook status from this application.
At first I have created a facebook app from https://developers.facebook.com/. Here are the steps I have followed ,
Create new app
Display name and namespace is given. Category selected as Games then create app.
App settings -> Add platform -> Website -> site url = test1.com:8000 -> save changes.
I have also made the application and all its live features available to the general public.
Then I have added ,
SOCIAL_AUTH_FACEBOOK_KEY='****************'
SOCIAL_AUTH_FACEBOOK_SECRET='**************************'
and
SOCIAL_AUTH_FACEBOOK_SCOPE = [
'publish_actions'
]
to settings.py .
When I run this app and start with facebook authentication it displays following popup,
And when I click on Play now button it successfully redirects to my django app's homepage and post my facebook status,
Here is my code for posting facebook status ,
social_user = request.user.social_auth.filter( provider='facebook',)[0]
graph = facebook.GraphAPI(social_user.extra_data['access_token'])
graph.put_object("me", "feed", message="here is status messgae")
But when another user [other than my facebook account] tries to authenticate this app is displaying popup like this ,
In first case I have successfully posted my status, But In second case I am [ message in second popup clearly shows that the app doesn't have any access to users wall.]
This is the error I am getting for the second case ,
GraphAPIError at /
(#200) The user hasn't authorized the application to perform this action.
My question is that , Why my app is not able to post on others wall ?
Is there is any bad configuration (or missed something) I did while creating facebook app ?
Or something else I have to add in settings.py.
The app settings are just fine. Actually, facebook recently made some significant changes and introduced v2.0 (learn more about this here)
So from now on (you can even check the warning in the first dialog)-
If your app asks for more than than public_profile, email and user_friends it will require review by Facebook before your app can be used by people other than the app's developers.
Only the testers/developers of the app can test the app with other permissions before they are reviewed by facebook.
You can check out the review documentation for more details.

django social auth , create user model with email as primary key

I am trying to integrate django social auth for my website which will have Facebook and Google login. I am trying to customize the user model to make email as primary key.
Any advice ?
I tried creating a UserModel also but ended up with errors.
i tried creating a pipeline enter code here
from social_auth.backends.pipeline.user import create_user
def custom_create_user(request, *args, **kwargs):
print kwargs
return create_user(request, args, kwargs)
My aim is to have a site with Facebook And Google - oauth2 login with email as primary key !
Well I am doing facebook login for my ios app. What I am doing is
Login to facebook from my app and get the facebook access token
Send the facebook email and access token to the django backend
Then what I do is, instead of using the django default authenticate method which takes the username and password to authenticate a user, I overwrite my own authenticate method. Doing this is really easy just read Django Custom Authentication
In my custom authentication class I verify the email-token pair sent from the front using fb sdk for python and that is it. After than I can login the user using the django in built login

Categories