matthiask / django-authlib

Utilities for passwordless authentication (using magic links, Google, Facebook and Twitter OAuth currently)
https://django-authlib.readthedocs.io/
MIT License
61 stars 11 forks source link

admin login seems hard-coded to "admin" #12

Closed trondhindenes closed 1 year ago

trondhindenes commented 1 year ago

the first thing we do when configuring a django app is to rename the "/admin/" url to something else, like "/company-admin" or somthing less obvious. It seems like django-authlib is hard-wired to the "admin" path.

matthiask commented 1 year ago

Hey

That would be a bug and a bit unexpected. I have a site where the admin runs on a different path and I'm using the admin OAuth2 module there as well.

It is hardcoded that the admin app namespace is admin, that's for sure, but this cannot be changed anyway (at least I think that's the case?)

The README says to add https://yourdomain.com/admin/__oauth__/ as a valid redirect URI; if you integrate the admin somewhere else you'd have to use https://yourdomain.com/company-admin/__oauth__/ or something?

trondhindenes commented 1 year ago

Hi, thanks for responding so quickly. I see what you mean now. It just means that even if the admin app is running at company-admin/, django-authlib will still use admin/__oauth_ as the redirect url. This means that in any path-based routing rules we'd have to enable both company-admin/ and admin/.

I'm attempting to specify the urlpattern entry by hand instead of just importing the urls file to see if we can get around this:

if settings.USE_GOOGLE_ADMIN_LOGINS:
    from authlib.admin_oauth.views import admin_oauth
    urlpatterns.insert(0, path("company-admin/__oauth__/", admin_oauth, name="admin_oauth"))

(I haven't tested this yet, it may well work)

matthiask commented 1 year ago

Ah, I see. Yes, the bundled URLconf module assumes /admin/.

Yes, your snippet should work fine. I checked, it's what I'm doing as well :-) I didn't remember.

trondhindenes commented 1 year ago

yup, works perfectly. Thanks again for responding.