casdoor/django-casdoor-auth

/casdoor/callback/ Error

Closed this issue · 2 comments

hopomi commented

translate:
This error is returned because the interface actually returns a dict, and the tokenn string needs to be extracted. The error is as follows.

Internal Server Error: /casdoor/callback/
Traceback (most recent call last):
File "C:\Users\BCY\AppData\Roaming\Python\Python310\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
File "C:\Users\BCY\AppData\Roaming\Python\Python310\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\Users\BCY\anaconda3\lib\site-packages\casdoor_auth\views.py", line 45, in callback
user = sdk.parse_jwt_token(token)
File "C:\Users\BCY\AppData\Roaming\Python\Python310\site-packages\casdoor\main.py", line 239, in parse_jwt_token
return_json = jwt.decode(
File "C:\Users\BCY\AppData\Roaming\Python\Python310\site-packages\jwt\api_jwt.py", line 84, in decode
payload, _, _, _ = self._load(jwt)
File "C:\Users\BCY\AppData\Roaming\Python\Python310\site-packages\jwt\api_jws.py", line 176, in _load
raise DecodeError("Invalid token type. Token must be a {0}".format(
jwt.exceptions.DecodeError: Invalid token type. Token must be a <class 'bytes'>

Adding a new judgment on line 43 of views.py can solve the problem.

if isinstance(token, dict): token = token['access_token']

@hopomi hi, can you make a PR to fix it?