question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TemplateDoesNotExist at /oauth2/callback

See original GitHub issue

I am getting this error after sending the user to log in with AD and then sending it back to the app.

I have set up the @login_required attribute on the index function in the views.py.

I have added the adfs URLs to the views here:

urlpatterns = [
    path('oauth2/', include('django_auth_adfs.urls')),
    path('', views.home, name='home'),
    path('contact/', views.contact, name='contact'),
    path('about/', views.about, name='about'),
    path('testpage/', views.testpage, name='testpage'),
    path('login/',
         LoginView.as_view
         (
             template_name='app/login.html',
             authentication_form=forms.BootstrapAuthenticationForm,
             extra_context=
             {
                 'title': 'Log in',
                 'year' : datetime.now().year,
             }
         ),
         name='login'),
    path('logout/', LogoutView.as_view(next_page='/'), name='logout'),
    path('admin/', admin.site.urls),
]

Here are my templates:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

And my middleware:

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware'
    #'django_auth_adfs.middleware.LoginRequiredMiddleware'
]

ROOT_URLCONF = 'DjangoWebProject1.urls'

The login required line was commented out due to it causing errors on launch.

I also added a template under templates/app/oauth2/callback.html and it does not resolve properly.

Any insight on this is appreciated.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JonasKscommented, Sep 16, 2021

I don’t have the time to really investigate this until next week, but yes, a example repo is a good way to get help. You also have a demo project in this repository here.

I’d recommend you take a step back and ensure that you have the authentication backends installed, the login required middleware is enabled again, and that your redirect URL from ADFS/Azure is correct.
Enable debug to get all the logs.

You’ve also got a new issue now compared to before, so search the previous issues for similar errors. This answer might help you.

0reactions
cataclysm1987commented, Sep 16, 2021

You can close out this issue. I was able to resolve it by adding it to the installed apps.

The error afterwards was resolved by updating my reply url to oauth/login.

Hopefully this helps anyone else.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Login failed issue · Issue #143 · snok/django-auth-adfs - GitHub
When i login via adfs and the user does not exists in django users table i get login failed , also in my...
Read more >
TemplateDoesNotExist at /users/profile - django - Stack Overflow
I am trying to make a profile page, which simply is a page with user details, such as firstname, lastname, email, etc. But...
Read more >
django-auth-adfs - bytemeta
TemplateDoesNotExist at /oauth2/callback ... Make software development more efficient, Also welcome to join our telegram.
Read more >
How to resolve Django TemplateDoesNotExist Error on ...
This video will show you how to resolve Django TemplateDoesNotExist Error on Windows machine.
Read more >
Django Part 1 - TemplateDoesNotExist - Code with Mosh Forum
I tried Stackoverflow's solutions, but it didn't seem to help. Below is the output of the error when I go to http://localhost:8000/playground/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found