snok / django-auth-adfs

A Django authentication backend for Microsoft ADFS and AzureAD
http://django-auth-adfs.readthedocs.io/
BSD 2-Clause "Simplified" License
270 stars 98 forks source link

Rest Framework integration #268

Closed snowcrash-arin closed 1 year ago

snowcrash-arin commented 1 year ago

I'm following the instructions here.

https://django-auth-adfs.readthedocs.io/en/latest/rest_framework.html#setup

(Optional) Override the standard Django Rest Framework login pages in your main urls.py:

urlpatterns = [
    ...
    # The default rest framework urls shouldn't be included
    # If we include them, we'll end up with the DRF login page,
    # instead of being redirected to the ADFS login page.
    #
    # path('api-auth/', include('rest_framework.urls')),
    #
    # This overrides the DRF login page
    path('oauth2/', include('django_auth_adfs.drf_urls')),
    ...
]

And I'm getting the following errors on startup.

Exception in thread django-main-thread:
Traceback (most recent call last):
  File venv\lib\site-packages\django\urls\base.py", line 71, in reverse
    extra, resolver = resolver.namespace_dict[ns]
KeyError: 'django_auth_adfs'
...
    raise NoReverseMatch("%s is not a registered namespace" % key)
django.urls.exceptions.NoReverseMatch: 'django_auth_adfs' is not a registered namespace

If I change back to path('oauth2/', include('django_auth_adfs.urls')), no issue.

Upvote & Fund

Fund with Polar

tim-schilling commented 1 year ago

What is the full stacktrace? If that is the full stacktrace, what is being passed into the reverse call?

tim-schilling commented 1 year ago

The path('oauth2/', include('django_auth_adfs.drf_urls')) are not meant to replace path('oauth2/', include('django_auth_adfs.urls')). They should replace path('api-auth/', include('rest_framework.urls')).

snowcrash-arin commented 1 year ago

Thanks @tim-schilling I misunderstood the instruction. I no longer see the issue after appending the line and removing the rest_framework_urls.