試圖執行上的Django 1.10的OAuth2認證+ Python 3中,我得到這個錯誤:rauth:JSON對象必須str的,而不是 '字節'
rauth: the JSON object must be str, not 'bytes'
它發生就行了電話: session = sso.get_auth_session(data=data, decoder=json.loads)
。
如果我刪除decoder=json.loads
,我收到以下錯誤:
Decoder failed to handle access_token with data as returned by provider. A different decoder may be needed.
這裏是我的方法:
def login(request):
"""
Login view
@author: Leonardo Pessoa
@since: 11/06/2016
"""
from rauth import OAuth2Service
from django.conf import settings
import json
# 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/')
視圖是首次訪問的重定向到授權URL(無GET['code']
)。接下來,再次訪問它(使用GET['code']
)來處理授權碼並進行身份驗證。
任何想法?