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

'NoneType' object has no attribute 'encode' using Facebook oauth #193

Closed sakulachi8 closed 5 years ago

sakulachi8 commented 5 years ago

Hi i am facing issue after hitting url

curl -X POST -d "grant_type=convert_token&client_id=<client_id>&client_secret=<client_secret>&backend=facebook&token=<backend_token>" http://localhost:8000/auth/convert-token

and in response i get Internal Server Error: /auth/convert-token Traceback (most recent call last): File "D:\env\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "D:\env\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "D:\env\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) . . . . File "D:\env\lib\site-packages\social_core\backends\facebook.py", line 131, in do_auth data = self.user_data(access_token) File "D:\env\lib\site-packages\social_core\backends\facebook.py", line 74, in user_data secret.encode('utf8'), AttributeError: 'NoneType' object has no attribute 'encode'

MichaelLisboa commented 5 years ago

I'm having the same challenge with Instagram oauth. Any thoughts?

sakulachi8 commented 5 years ago

Hi Michael, My issue was resolved. I didnt put facebook id and secret in settings file. Can you check these settings? This library get fb credentials from settings. Let me know if you are still facing issue. I had done. now its working in my project.

MichaelLisboa commented 5 years ago

@sakulachi8 thanks for the info, appreciate it. I have IG creds in settings, but still getting the same error, I'll do some investigation ;-) Could simply be the terrible IG API...

MichaelLisboa commented 5 years ago

Okay, thanks @sakulachi8 for mentioning creds in settings. I had a look and though I had social_auth creds for IG, I had forgotten a couple of things...

For anybody who runs into this error when working with Instagram, ensure you not only have the creds as @sakulachi8 mentioned, but set REDIRECT_STATE = False (this worked for me at least, mileage may vary). See my settings.py snippet below:

from social_core.backends import instagram

instagram.InstagramOAuth2.REDIRECT_STATE = False
SOCIAL_AUTH_INSTAGRAM_REDIRECT_IS_HTTPS = True
SOCIAL_AUTH_INSTAGRAM_KEY = os.environ['IG_KEY']
SOCIAL_AUTH_INSTAGRAM_SECRET = os.environ['IG_SECRET']