RealmTeam / django-rest-framework-social-oauth2

python-social-auth and oauth2 support for django-rest-framework
MIT License
1.06k stars 191 forks source link

Oauth with google convert token give invalid backend #110

Closed XoronMirror closed 7 years ago

XoronMirror commented 7 years ago

settings: INSTALLED_APPS = [ 'oauth2_provider', 'social_django', 'rest_framework_social_oauth2', 'ourapp', 'rest_framework' ] 'context_processors': [ 'django.template.context_processors.debug', 'social_django.context_processors.backends', 'social_django.context_processors.login_redirect', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ],

REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'oauth2_provider.contrib.rest_framework.OAuth2Authentication', 'rest_framework_social_oauth2.authentication.SocialAuthentication', ), } OAUTH2_PROVIDER = {

this is the list of available scopes

'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}

}

AUTHENTICATION_BACKENDS = ( 'social_core.backends.google.GoogleOAuth2', 'social_core.backends.google.GoogleOAuth', 'rest_framework_social_oauth2.backends.DjangoOAuth2', 'django.contrib.auth.backends.ModelBackend',

)

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = ' ' SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = ' ' SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = ['email']

I received token from google using java-script jso and then i request using curl curl -X POST -d "grant_type=convert_token&client_id=&client_secret=&backend=google&token= " http://localhost:8000/o/convert-token

give error invalid backend parameter?

Also google give token in the url why? thx for help

PhilipGarnero commented 7 years ago

You need to check the name of the backend defined by python-social-auth : here you can see that it says google-oauth2

When you're using javascript to authenticate with a third-party auth provider, usually, you will be redirected to their website and then back to your website with the token in the url. The url is simply one way to send data and it is simple.