Git Product home page Git Product logo

Comments (25)

camrongodbout avatar camrongodbout commented on June 19, 2024 2
$./manage.py shell
from social.backends.utils import load_backends
from django.conf import settings
load_backends(settings.AUTHENTICATION_BACKENDS)
{'facebook': <class 'social.backends.facebook.FacebookOAuth2'>, 'facebook-app': <class 'social.backends.facebook.FacebookAppOAuth2'>, 'Django': <class 'rest_framework_social_oauth2.backends.DjangoOAuth2'>}

Was really helpful for finding google-oauth2 as the backend name for google, which wasn't obvious to me. Maybe something like this should be included in the docs so that others can quickly find out the backend names?

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024 1

In django shell try this and see if it returns the facebook backend:

$./manage.py shell
from social.backends.utils import load_backends
from django.conf import settings
load_backends(settings.AUTHENTICATION_BACKENDS)
{'facebook': <class 'social.backends.facebook.FacebookOAuth2'>, 'facebook-app': <class 'social.backends.facebook.FacebookAppOAuth2'>, 'Django': <class 'rest_framework_social_oauth2.backends.DjangoOAuth2'>}

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024 1

@PhilipGarnero please can you test the app with my fb app id an secret ? with follow token ?

CAAUh8COZCK6wBAFZBo9R4BbBpKJJhRpnvxGzJSZAwZBo3H8FVUOvZBEO1MkFJIjurZCS7nosZAO3OaPUEM5jhWfZBZBEvn6dlKKrZAVZAzaNRw4VhFeJftuAFdxgulAWnAgw7VDOIAAM2cd0kST8lYw7kQtHO202BErGsheZBc5bsVqFfQiSGfK2Pj7U9CHlrcfgCZAwvrLZAOu1IV7gGghhxWzZBa5

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024 1

Yes it work like a charm i'm so happy. Thank a lot @PhilipGarnero you are a good guy. Hope many people will use your good library

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

This is because python social auth couldn't find the backend.
Have you got these lines in your settings.py ?

AUTHENTICATION_BACKENDS = (
    # Facebook OAuth2
    'social.backends.facebook.FacebookAppOAuth2',
    'social.backends.facebook.FacebookOAuth2',

    'rest_framework_social_oauth2.backends.DjangoOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

@PhilipGarnero yes i did it but nothing work

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

Can you show me your settings ?

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

@PhilipGarnero You can see my settings bellow

"""
Django settings for flirt project.

DEBUG = True

#TEMPLATE_DEBUG = True

ALLOWED_HOSTS = ['*']

#Application definition

INSTALLED_APPS = (

'django.contrib.admin',
'oauth2_provider',
'social.apps.django_app.default',
'rest_framework_social_oauth2',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.gis',
'rest_framework',

)

MIDDLEWARE_CLASSES = (

'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',

)

WSGI_APPLICATION = 'flirt.wsgi.application'

AUTHENTICATION_BACKENDS = (

'oauth2_provider.backends.OAuth2Backend',

# Facebook OAuth2
'social.backends.facebook.FacebookAppOAuth2',
'social.backends.facebook.FacebookOAuth2',

#django social rest
'rest_framework_social_oauth2.backends.DjangoOAuth2',

'django.contrib.auth.backends.ModelBackend',

)

TEMPLATE_CONTEXT_PROCESSORS = (

'django.contrib.auth.context_processors.auth',
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',

)

SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = [ 'username', 'first_name']

SOCIAL_AUTH_FACEBOOK_KEY = '1444690159152044'
SOCIAL_AUTH_FACEBOOK_SECRET = '**********************'

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

#rest api

LOGIN_REDIRECT_URL = '/users/'

OAUTH2_PROVIDER = {

 # this is the list of available scopes
 'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'},

}

REST_FRAMEWORK = {

# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
    'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    #'rest_framework.permissions.IsAuthenticated'
],
'DEFAULT_AUTHENTICATION_CLASSES': (

    'oauth2_provider.ext.rest_framework.OAuth2Authentication',
    'rest_framework_social_oauth2.authentication.SocialAuthentication',
),
'EXCEPTION_HANDLER': 'rest_framework.views.exception_handler'

}

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

I don't see any problem with your configuration...
Can you try with "Django" instead of "facebook" to see if you're getting the same error ?
If that's the case open your_virtualenv/lib/python2.7/site-packages/rest_framework_social_oauth2/authentication.py and print token and backend lines 47-48.

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

@PhilipGarnero I've already done it and i get for token: b'user_access_token'
and for backend i get value : b'facebook'

Notice that when i run this command:
curl -X POST -d "client_id=<client_id>&client_secret=<client_secret>&grant_type=password&username=<user_name>&password=" http://localhost:8000/auth/token
i get an access_token

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

@PhilipGarnero yes i tried it and it returns the facebook backend

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

Try this now

$./manage.py shell
from django.conf import settings
from social.backends.utils import load_backends, get_backend
get_backend(load_backends(settings.AUTHENTICATION_BACKENDS), "facebook")
<class 'social.backends.facebook.FacebookOAuth2'>

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

@PhilipGarnero i tried it and it return class 'social.backends.facebook.FacebookOAuth2'

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

I really have no clue then ... Everything seems to be ok.
Try to debug in your_virtualenv/lib/python2.7/site-packages/rest_framework_social_oauth2/authentication.py and see if you can reproduce this in the shell.
I'll let this issue opened until you manage to make some progress. Don't hesitate to ask questions if you need help.

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

Ok, thank for consecrated me your precious time @PhilipGarnero . I continue to search a way for solve this issue

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

@gelog93 I was thinking, if your project is not private and doesn't contain sensitive data, you can send it to me and I'll try to figure out what is going on exactly.

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

@PhilipGarnero Sorry for late. I've created minimal project and run curl command on but i get the same error so i've created new repository where i've put this project. You can find it at https://github.com/gelog93/auth/archive/master.zip please download it. i'm so hopeless

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

@gelog93 I tried your setup with a virtualenv and just ran pip install django-rest-framework-social-oauth2 to install everything. I also replaced your postgre db to sqlite and replaced your facebook app id and secret and everything worked as expected.
I think you must have misconfigured your facebook app or your python environment but this has nothing to do with this package.
Make sure you're using a virtualenv and that your app config is correct.
I can't help you much more on this :/

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

@PhilipGarnero what's python version do you use ?

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

I'm using python2.7.3

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

@PhilipGarnero maybe python version is the problem because i use python 3.4

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

I managed to reproduce the error with python 3.4. I suspect a wrong string encoding.

from django-rest-framework-social-oauth2.

gelog93 avatar gelog93 commented on June 19, 2024

@PhilipGarnero Finally we know the cause

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

@gelog93 this should be fixed now.
I released 0.0.8.
Try it and come back here to close the issue if this works

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

The backend names are the same one used by python social auth.
If you are interested in a backend, the best way to go is to check python social auth doc about it and maybe open the backend code for more insights.

from django-rest-framework-social-oauth2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.