How to override wagtail authentication?
Asked Answered
J

3

5

When I attempt to access my wagtail back-office at /cms/, I get redirected to wagtail's login page, /cms/login/.

However, I would like to use my own custom login, which is default for the rest of the site, and sits at /auth/.

My LOGIN_URL is already set to /auth/ in django settings.

EDIT : it's been suggested that this is a generic question of how do you override namespaced url patterns but this is not the case. The urls are not namespaced, and I was looking for wagtail functionality that adressed this specific issue. Fortunately, that functionality does exist.

Juniper answered 19/6, 2017 at 18:14 Comment(0)
S
4

WAGTAIL_FRONTEND_LOGIN_URL suggested above is specifically intended just for front end users and there is not an equivalent setting for admin users. You could use redirect_to_login like so:

from django.contrib.auth.views import redirect_to_login
from django.urls import reverse

from wagtail.admin import urls as wagtailadmin_urls


def redirect_to_my_auth(request):
    return redirect_to_login(reverse('wagtailadmin_home'), login_url='myauth:login')



urlpatterns = [
    url(r'^cms/login', redirect_to_my_auth, name='wagtailadmin_login'),
    url(r'^cms/', include(wagtailadmin_urls)),
]
Sneaking answered 17/4, 2018 at 6:28 Comment(1)
I am able to override the login url, but it is not redirecting me to CMS admin. Instead it always redirect me to dashboard even though redirect url is present in the url bar.Mide
V
2

The Wagtail setting WAGTAIL_FRONTEND_LOGIN_URL allows you to configure how users login to the Wagtail admin.

From http://docs.wagtail.io/en/v1.10.1/advanced_topics/privacy.html#setting-up-a-login-page:

If the stock Django login view is not suitable - for example, you wish to use an external authentication system, or you are integrating Wagtail into an existing Django site that already has a working login view - you can specify the URL of the login view via the WAGTAIL_FRONTEND_LOGIN_URL setting

Venatic answered 20/6, 2017 at 0:22 Comment(5)
Wagtail seems to ignore that setting... still redirecting to /cms/login/Juniper
What version of wagtail are you using?Venatic
Latest version, 1.10.1Juniper
Verify that this isn't an artifact of how your custom authentication system works and file an issue on Wagtail's bug tracker?Venatic
It seems WAGTAIL_FRONTEND_LOGIN_URL is specifically intended just for front end users and there is not an equivalent setting for admin users. You could use redirect_to_loginSneaking
B
1

To elaborate on Erick M's answer, since this is the working answer:

You do need to set the correct permission (wagtailadmin.access_admin) or set the is_superuser flag in Django's auth_user database table to be able to access the CMS, otherwise you still get a "permission denied" error.

I thought this had to do with my implementation, but it was already working, but failed because of the above reason.

Barbusse answered 4/11, 2022 at 15:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.