Authenticating against Hyperkitty's DB
Hi,
inspired by the question about LDAP, I want to ask a related question. We're currently thinking about adding a wiki to our small OSS project, and requiring users to have multiple accounts for the same project is nonsense. We don't have LDAP set up yet, but we do have a running Mailman 3 installation, including Hyperkitty. Thus I thought about whether it's possible to just write some glue script that authenticates against the user information in Hyperkitty's database. Creating an account for Hyperkitty would then be sufficient to get access to the wiki.
Could someone give me a hint where and in what format Hyperkitty stores the user information into its database?
Marvin
-- Blog: https://mg.guelker.eu
On Thu, Jul 25, 2019, at 12:36 PM, Marvin Gülker wrote:
Hi,
inspired by the question about LDAP, I want to ask a related question. We're currently thinking about adding a wiki to our small OSS project, and requiring users to have multiple accounts for the same project is nonsense. We don't have LDAP set up yet, but we do have a running Mailman 3 installation, including Hyperkitty. Thus I thought about whether it's possible to just write some glue script that authenticates against the user information in Hyperkitty's database. Creating an account for Hyperkitty would then be sufficient to get access to the wiki.
Could someone give me a hint where and in what format Hyperkitty stores the user information into its database?
So, Hyperkitty itself doesn't concern with authentication and it is handled by django-allauth, which itself hooks into the higher level authentication API provided by Django.
Django allows for pluggable Authentication backends, that it can use to authenticate requests. You can read more about it here1. We use Django-allauth as an authentication backend.
You can use the higher level django.contrib.auth.authenticate()
2 function
with right values in a Python script running in the same virtualenv to
authenticate the user to your wiki.
Marvin
-- Blog: https://mg.guelker.eu
Mailman-users mailing list -- mailman-users@mailman3.org To unsubscribe send an email to mailman-users-leave@mailman3.org https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/
-- thanks, Abhilash Raj (maxking)
Am 25. Juli 2019 um 13:16 Uhr -0700 schrieb Abhilash Raj:
So, Hyperkitty itself doesn't concern with authentication and it is handled by django-allauth, which itself hooks into the higher level authentication API provided by Django.
Ah sure. I forgot about that (because I'm not a Pythonista).
You can use the higher level
django.contrib.auth.authenticate()
[2] function with right values in a Python script running in the same virtualenv to authenticate the user to your wiki.
Thank you for the hint. I installed Mailman 3 from Ubuntu's repositories, though. Nevertheless, I managed to write a little test script that works successfully. I used "manage.py runscript" to execute it. For that, I created a scripts/ directory below /usr/share/mailman3-web, added an empty __init__.py and then the script itself, as described in the Django online documentation¹. This is the script I used for testing, adapted from your linked documentation for django.contrib.auth.authenticate:
from django.contrib.auth import authenticate
def run():
user = authenticate(username='johndoe', password='s33cr3t')
if user is not None:
# A backend authenticated the credentials
print "Okay"
else:
print "Not Okay"
# No backend authenticated the credentials
Save it in /usr/share/mailman3-web/scripts/testauth.py and execute
$ python manage.py runscript authtest
as user "www-data" to test it. It'll print "Okay" if the credentials validate and "Not Okay" if not.
Next I'm going to fiddle with it. It's probably possible to move that scripts directory outside /usr into /opt or similar.
Marvin
¹ https://django-extensions.readthedocs.io/en/latest/runscript.html
-- Blog: https://mg.guelker.eu
Am 26. Juli 2019 um 12:48 Uhr +0200 schrieb Marvin Gülker:
Next I'm going to fiddle with it. It's probably possible to move that scripts directory outside /usr into /opt or similar.
I have set up everything successfully now and wrote a blog post about how I did it. It's linked below for anyone who is interested, but it is in German.
https://mg.guelker.eu/articles/2019/07/27/mailman3-moinmoin-verbinden/
Marvin
-- Blog: https://mg.guelker.eu
On Sun, Jul 28, 2019, at 10:44 AM, Marvin Gülker wrote:
Am 26. Juli 2019 um 12:48 Uhr +0200 schrieb Marvin Gülker:
Next I'm going to fiddle with it. It's probably possible to move that scripts directory outside /usr into /opt or similar.
I have set up everything successfully now and wrote a blog post about how I did it. It's linked below for anyone who is interested, but it is in German.
https://mg.guelker.eu/articles/2019/07/27/mailman3-moinmoin-verbinden/
Thanks Marvin for sharing this, I couldn't understand anything because I can't read German, but I looked at the code snippets.
I just wanted to point out /etc/mailman3/customscripts/authtest.py
script
should use print(user.email)
function and not the print user.email
statement
since we don't support Python 2 anymore and it might end up confusing
the readers.
-- thanks, Abhilash Raj (maxking)
Am 28. Juli 2019 um 12:07 Uhr -0700 schrieb Abhilash Raj:
I just wanted to point out
/etc/mailman3/customscripts/authtest.py
script should useprint(user.email)
function and not theprint user.email
statement since we don't support Python 2 anymore and it might end up confusing the readers.
Thanks! The version in Ubuntu 18.04's repositories still does use Python 2, but I didn't notice that I accidentally wrote Python-2-only code, because I can't code Python anyway (which is stated in the text, but I know you couldn't read that). I'm a Ruby coder mostly when it comes to scripting languages.
I've fixed it. Thanks for pointing out the problem.
Marvin
-- Blog: https://mg.guelker.eu
On Mon, Jul 29, 2019, at 12:12 AM, Marvin Gülker wrote:
Am 28. Juli 2019 um 12:07 Uhr -0700 schrieb Abhilash Raj:
I just wanted to point out
/etc/mailman3/customscripts/authtest.py
script should useprint(user.email)
function and not theprint user.email
statement since we don't support Python 2 anymore and it might end up confusing the readers.Thanks! The version in Ubuntu 18.04's repositories still does use Python 2, but I didn't notice that I accidentally wrote Python-2-only code, because I can't code Python anyway (which is stated in the text, but I know you couldn't read that). I'm a Ruby coder mostly when it comes to scripting languages.
Ah! Cool, it should work both of Python 2 and 3 :)
I've fixed it. Thanks for pointing out the problem.
Thank you!
Marvin
-- Blog: https://mg.guelker.eu
Mailman-users mailing list -- mailman-users@mailman3.org To unsubscribe send an email to mailman-users-leave@mailman3.org https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/
-- thanks, Abhilash Raj (maxking)
participants (2)
-
Abhilash Raj
-
Marvin Gülker