Closed Venefilyn closed 3 years ago
After adding AUTHENTICATION_BACKENDS = [mozilla_django_oidc.auth.OIDCAuthenticationBackend]
there seems to be progress, although now getting NoReverseUrl, despite having it defined
DEFAULT_CALLBACK_CLASS = 'mozilla_django_oidc.views.OIDCAuthenticationCallbackView'
CALLBACK_CLASS_PATH = import_from_settings('OIDC_CALLBACK_CLASS', DEFAULT_CALLBACK_CLASS)
OIDCCallbackClass = import_string(CALLBACK_CLASS_PATH)
DEFAULT_AUTHENTICATE_CLASS = 'mozilla_django_oidc.views.OIDCAuthenticationRequestView'
AUTHENTICATE_CLASS_PATH = import_from_settings(
'OIDC_AUTHENTICATE_CLASS', DEFAULT_AUTHENTICATE_CLASS
)
OIDCAuthenticateClass = import_string(AUTHENTICATE_CLASS_PATH)
# namespaced urls
urlpatterns = [
url(r'^login/$', OIDCAuthenticateClass.as_view(), name='login'),
url(r'^login/$', OIDCAuthenticateClass.as_view(), name='oidc_authentication_init'),
url(r'^auth/$', OIDCCallbackClass.as_view(), name='oidc_authentication_callback_alt')
]
# also tried with mozilla urls
urlpatterns = [
url(r'^oidc/', include('mozilla_django_oidc.urls')),
url(r'^login/$', OIDCAuthenticateClass.as_view(), name='login'),
url(r'^auth/$', OIDCCallbackClass.as_view(), name='oidc_authentication_callback_alt')
]
Reverse for 'oidc_authentication_init' not found. 'oidc_authentication_init' is not a valid view function or pattern name.
Right, putting
url(r'^api/oidc/', include('mozilla_django_oidc.urls')),
in project root removed the error (presumably due to namespacing) although I would like to specify the URLs myself. Though is_authenticated()
still returns false.
I've submitted another PR to help with middleware redirects. It seems the issue with authentication lies with DRF.
Running user.is_authenticated()
inside a DRF view always returns false. Whereas outside DRF in plain Django it returns true. This happens despite only having Mozilla Django OIDC in the REST_FRAMEWORK.DEFAULT_AUTHENTICATION_CLASSES
setting
Turns out we need to add SessionAuthentication to DRF auth classes, similar to #265, otherwise it will not work
'DEFAULT_AUTHENTICATION_CLASSES': [
'mozilla_django_oidc.contrib.drf.OIDCAuthentication',
'rest_framework.authentication.SessionAuthentication',
],
I've setup a login and callback endpoint directly from
mozilla_django_oidc
. It redirects to OIDC provider, logs me in, redirects me back, and also creates a correct user on the user table.However, the session never persists. There is a
sessionid
cookie being set, thoughrequest.user.is_authenticated
returns false. This is with DRF, though I don't see why it would have much of an impact on authenticating.Hopefully there's just a simple oversight..
Here's the configuration I've used so far:
requirements.txt:
Edit: with session data in database matching the
sessionid
:I'm beginning to suspect this is Django rather than this library