You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to implement a OAuth2 authentication on Django 1.10 + Python 3, I'm getting this error:
rauth: the JSON object must be str, not 'bytes'
It happens on the line calling: session = sso.get_auth_session(data=data, decoder=json.loads).
If i remove the decoder=json.loads, I get the following error:
Decoder failed to handle access_token with data as returned by provider. A different decoder may be needed.
Here is my method:
def login(request):
"""
Login view
@author: Leonardo Pessoa
@since: 11/06/2016
"""
from rauth import OAuth2Service
from django.conf import settings
import son
# instantiating our login service with environment defined settings
sso = OAuth2Service(
name = settings.LOGIN_SETTINGS['name'],
client_id = settings.LOGIN_SETTINGS['client_id'],
client_secret = settings.LOGIN_SETTINGS['client_secret'],
access_token_url = settings.LOGIN_SETTINGS['access_token_url'],
authorize_url = settings.LOGIN_SETTINGS['authorize_url'],
base_url = settings.LOGIN_SETTINGS['base_url'],
)
# check if we have a login code returned by OAuth
get_code = request.GET.get('code', '')
if get_code == '':
params = {
'redirect_uri' : settings.LOGIN_SETTINGS['redirect'],
'response_type' : 'code'
}
url = sso.get_authorize_url(**params)
return redirect(url)
else:
# we are in!
data = {'code' : get_code,
'grant_type' : 'authorization_code',
'redirect_uri' : settings.LOGIN_SETTINGS['redirect']
}
session = sso.get_auth_session(data=data, decoder=json.loads)
return redirect('/logado/')
The view is accessed the first time to redirect to the authorize URL (no GET['code']). Next, it's accessed again (with the GET['code']) to handle the authorization code and authenticate.
Feel like there should be a mix of both solutions (encoding UTF-8 + json).
The text was updated successfully, but these errors were encountered:
The problem is that get_auth_session decodes the byte stream from the response to UTF-8 by default. If you specify a new decoder, you override that. So I guess we need both here (UTF-8 + JSON).
annyanich
pushed a commit
to annyanich/mensa-tracker
that referenced
this issue
Apr 15, 2017
I'm not sure why I only just now ran into this problem. It may be due to
a change on Facebook's end. Anyway, now login should be working again. :)
See litl/rauth#194
(cherry picked from commit 648b32d)
Trying to implement a OAuth2 authentication on Django 1.10 + Python 3, I'm getting this error:
If i remove the decoder=json.loads, I get the following error:
Here is my method:
The view is accessed the first time to redirect to the authorize URL (no
GET['code']
). Next, it's accessed again (with theGET['code']
) to handle the authorization code and authenticate.Feel like there should be a mix of both solutions (encoding UTF-8 + json).
The text was updated successfully, but these errors were encountered: