Django-social-auth extended facebook permissions like spotify - python

I was able to get the publish_actions permission for my facebook app by using this setting
FACEBOOK_EXTENDED_PERMISSIONS = ['publish_actions']
The problem is that when authorizing my facebook app is that a second window is used to prompt the user to allow my app to publish actions after the initial prompt for the basic info.
How can I use only one window to get users to authorize my app? I'm trying to get my authorization window to look similar spotify's authorization

Django-social-auth has been superseded by python-social-auth. In python-social-auth, you define extended permission by using SOCIAL_AUTH_FACEBOOK_SCOPE inside settings.py. For example:
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email', 'user_photos']
It will only show a single authorization dialog.

Related

Azure Python Flask Get Email id of the user logged in

I created the sample Python Flask Webapp by following the below link.
https://learn.microsoft.com/en-us/azure/app-service/containers/quickstart-python?tabs=bash
I also added the AD Authentication for the Flask application by enabling Authentication in the Settings of the App Services. Now the app works only when the user is logged in and cannot access otherwise.
I would want to fetch the email id if the user who is logged in. I tried checking online but unable to find a way to get the email address of the user.
Any help is really appreciated.
App Service passes user claims to your application by using special headers. So you can get user information from the request header. Some example headers include:
X-MS-CLIENT-PRINCIPAL-NAME
X-MS-CLIENT-PRINCIPAL-ID
You can use res.headers to see all the values.
Reference:
Access user claims

having trouble setting up python social auth to log in to facebook, facebook giving error that test user is not registered

I am running my django app on a remote server. When I try to log in to facebook using python-social-auth, I get the following error
App Not Setup: This app is still in development mode, and you don't have access to it. Switch to a registered test user or ask an app admin for permissions.
I'm using a tutorial from simpleisbetterthancomplex.com
I've named the app that demonstrates the login "test_social" with a prefix "tsoc" as in /tsoc/login/facebook, etc.
I've managed to get it working on my localhost, I got it ssl certification using letsencrypt.org
it's just getting it to work remotely is very hard, I'm sure there is something I'm missing here. I can't even use the test users I made to log in.
If I am already logged in as a nomral user I get the following error:
App Not Setup: This app is still in development mode, and you don't have access to it. Switch to a registered test user or ask an app admin for permissions.
screenshot of attempted sign-in while already logged in
This happens if I'm signed in as the app administrator or if I'm signed in as an an accepted app developer.
If I'm NOT already signed in to facebook and I try to use the log in I get the following error:
Error Accessing App - We're sorry but the application you are trying to use doesn't exist or has been disabled
screenshot of attempted sign-in while NOT already logged in
here are some of the settings I already have on my facebook app
==========================================================
Basic Settings
(note: I changed the domain name, but the format is the same)
Settings->Basic (top part)
Settings->Basic (bottom part)
==========================================================
Facebook login settings
Products->Facebook Login ->Settings
==========================================================
** test user settings **
==========================================================
django settings
TEMPLATES[0]['OPTIONS']['context_processors'].append(
'social_django.context_processors.backends')
TEMPLATES[0]['OPTIONS']['context_processors'].append(
'social_django.context_processors.login_redirect')
INSTALLED_APPS.append('social_django')
MIDDLEWARE.append('social_django.middleware.SocialAuthExceptionMiddleware')
(tsoc is the django app I'm using to login - as I said above it's based on a tutorial by simpleisbetterthancomplex.com
I've named the app that demonstrates the login "test_social" with a prefix "tsoc" as in /tsoc/login/facebook, etc.
)
SOCIAL_AUTH_LOGIN_ERROR_URL = '/tsoc/settings/'
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/tsoc/settings/'
SOCIAL_AUTH_RAISE_EXCEPTIONS = False
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_URL_NAMESPACE = 'social'
AUTHENTICATION_BACKENDS = (
'social_core.backends.github.GithubOAuth2',
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',)
SOCIAL_AUTH_FACEBOOK_KEY = "XXXX" # they exist, just hidden
SOCIAL_AUTH_FACEBOOK_SECRET = "XXXX"
It would seem that your redirect URL defined in Facebook has /oauth/ where your app is defined as /tsoc/. Other than that, the app is clearly defined as "in development" -- did you try to access it while logged into facebook as one of your test users?

django rest auth facebook code for login

On project I use django-rest-auth for user registration and authentication. Also i added code for facebook login:
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
from rest_auth.registration.views import SocialLoginView
class FacebookOAuth2AdapterFixed(FacebookOAuth2Adapter):
def __init__(self):
pass
class FacebookLogin(SocialLoginView):
adapter_class = FacebookOAuth2Adapter
And in my project urls.py I add
url(r'^rest-auth/facebook/$', FacebookLogin.as_view(), name='fb_login'),
But on url localhost:8000/rest-auth/facebook I see form with 2 parameters: Access token(already have) and code.
My question is next: Can I login via facebook without this code, and if not, how can I get this code without frontend? How can I check work user authentication/registration or not?
PS: SocialApp created, facebook app created, app id and app secret added to social app.
Only one of "Access Token" or "Code" field is required. (I have not tested the Code field but the Access Token field works, with the Code field left blank)
To use Access Token, after the user performs the "Login to Facebook" step on the client side using Facebook javascript SDK, you will receive a response from Facebook which includes "accessToken" for accessing data on Facebook. Simply paste this accessToken into the "Access Token" field and it will automatically login and/or create the user's account from data retrieved from Facebook.
Obviously you can then perform the same process by posting the access token to the form all in javascript.
In the field of Access Token, Pass the User Access Token that you will get from Facebook developer dashboard(generate and debug), code field you can leave as blank. It will create user in your application and will return JWT token with user details.

django register user with django-facebook

Ok I see everyone saying use django-facebook, and it says it can do everything I want.
I have it installed on my app and the example page works, but how do I actually register a user with it?
Apart from the installation all the rest of the docs seem autogenerated and I have yet to find a step by step guide as to how to register a user on my site using django-facebook.
Here is a working example of facebook auth with django.
Facebook uses OAuth2 to federate user logins. An OAuth2 authorization step-by-step consists of
Create an authorization token by calling the request-token url with your consumer keys
Send the user to the authorize url with the token that you created and a callback url
Once authorized the user will be redirected to your callback url with an auth-token
Convert the auth-token to an access token at the request-token url
Save the access token and use it to make authorized requests

GAE and django same users

I'm running a GAE and Django helper project and i ran into some issues when creating a User from de django shell. After exploring the code under the helper directory i came across with the following code:
class User(BaseModel):
user = db.UserProperty(required=True)
My question is, do i have to bind the django user to a google account if so, how do i create a django or google user from my code?
UPDATE: I meant to say create the account without having the google account itself. For instace not having:
users.get_current_user()
UPDATE: A user must be able to create a new account just like regular django users, with a register page for that matter.
For AppEngine, you can get the users who are logged into your application.
from google.appengine.api import users
And then you do
username = users.get_current_user()
And set your user property
User(user=username)
You could lookup the tutorial on how to do redirect to login to ask the application to login to get the user.

Categories

Resources