wagnerdelima / drf-social-oauth2

drf-social-oauth2 makes it easy to integrate Django social authentication with major OAuth2 providers, i.e., Facebook, Twitter, Google, etc.
https://drf-social-oauth2.readthedocs.io/en/latest/
MIT License
274 stars 34 forks source link

ModuleNotFoundError: No module named 'jose' #99

Closed denizdogan closed 2 years ago

denizdogan commented 2 years ago
  1. It seems that jose is not installed as a dependency
  2. It seems that jose is the wrong dependency (py2 only)
  3. It seems that python-jose is the right one (py3 support)

Installation:

$ poetry add drf-social-oauth2
Using version ^1.1.4 for drf-social-oauth2

Updating dependencies
Resolving dependencies... (0.8s)

Writing lock file

Package operations: 5 installs, 0 updates, 0 removals

  • Installing wrapt (1.13.3)
  • Installing deprecated (1.2.13)
  • Installing jwcrypto (1.0)
  • Installing django-oauth-toolkit (1.6.1)
  • Installing drf-social-oauth2 (1.1.4)

In settings:

ACTIVATE_JWT = True

Make request to /social/convert-token/:

{
    "grant_type": "convert_token",
    "client_id": "...",
    "client_secret": "...",
    "backend": "facebook",
    "token": "..."
}

Error:

  File ".../lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py", line 62, in create_token_response
    token = token_handler.create_token(request,
  File ".../lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/tokens.py", line 315, in create_token
    'access_token': self.token_generator(request),
  File ".../lib/python3.9/site-packages/drf_social_oauth2/__init__.py", line 23, in generate_token
    from jose import jwt
ModuleNotFoundError: No module named 'jose'

Installing jose explicitly:

$ poetry add jose
Using version ^1.0.0 for jose

Updating dependencies
Resolving dependencies... (5.6s)

Writing lock file

Package operations: 2 installs, 0 updates, 0 removals

  • Installing pycrypto (2.6.1)
  • Installing jose (1.0.0)

New error:

  File ".../lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/tokens.py", line 315, in create_token
    'access_token': self.token_generator(request),
  File ".../lib/python3.9/site-packages/drf_social_oauth2/__init__.py", line 23, in generate_token
    from jose import jwt
  File ".../lib/python3.9/site-packages/jose.py", line 546
    print decrypt(deserialize_compact(jwt), {'k':key},
          ^
SyntaxError: invalid syntax

After investigations, I found python-jose:

$ poetry remove jose && poetry add python-jose
Updating dependencies
Resolving dependencies... (0.5s)

Writing lock file

Package operations: 0 installs, 0 updates, 2 removals

  • Removing jose (1.0.0)
  • Removing pycrypto (2.6.1)
Using version ^3.3.0 for python-jose

Updating dependencies
Resolving dependencies... (2.0s)

Writing lock file

Package operations: 4 installs, 0 updates, 0 removals

  • Installing pyasn1 (0.4.8)
  • Installing ecdsa (0.17.0)
  • Installing rsa (4.8)
  • Installing python-jose (3.3.0)

Now it works as expected.

wagnerdelima commented 2 years ago

Hi @denizdogan,

Thank you for your issue. You are completely right. I forgot to add the python-jose (not jose) to the setup.py file. Would you be kind and open a pull request with the changes?

Cheers!