juanifioren / django-oidc-provider

OpenID Connect and OAuth2 provider implementation for Djangonauts.
http://django-oidc-provider.readthedocs.org
MIT License
425 stars 239 forks source link

Cannot import name ScopeClaims circular dependency #403

Closed JordiNeil closed 2 years ago

JordiNeil commented 2 years ago

I created a CustomScopeClaims just as in documentation but the test_claims test fails with error

ImportError: cannot import name 'ScopeClaims' from partially initialized module 'oidc_provider.lib.claims' (most likely due to a circular import)

And make sense because settings.py imports ScopeClaims

from oidc_provider.lib.claims import ScopeClaims

and ScopeClaims imports settings

from oidc_provider import settings

In ScopeClaims class, settings is just being used to get the OIDC_USERINFO constant.

settings.get('OIDC_USERINFO', import_str=True)(claims, self.user)

Can anyone help me? Which is the best way to solve this.

JordiNeil commented 2 years ago

I think I solved it, I just had to move the CustomScopeClaims class to the oidc_provider.lib.claims file and update the constant in the Django settings file

OIDC_EXTRA_SCOPE_CLAIMS = 'yourproject.oidc_provider_settings.CustomScopeClaims'

to

OIDC_EXTRA_SCOPE_CLAIMS = 'yourproject.oidc_provider.lib.claims.CustomScopeClaims'

I this should be in the doc @juanifioren If you create customScopes in the location the Documentation says, the Tests will fail due to circular dependency error.