Skip to main content

django-iitg-auth

https://img.shields.io/pypi/v/django-iitg-auth.svg?style=plastic https://travis-ci.org/narenchoudhary/django-iitg-auth.svg?branch=master https://codecov.io/gh/narenchoudhary/django-iitg-auth/branch/master/graph/badge.svg

django-iitg-auth is a reusable Django application which provides a custom authencation backend for authenticating with IIT Guwahati webmail servers, a login form and a utility view.

Installation

django-iitg-auth can be installed using following pip command.

pip install django-iitg-auth

Usage: Authentication Backend

Add 'iitgauth' to INSTALLED_APPS settings of the project.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    ...
    ...
    'iitgauth',
]

Add 'iitgauth.auth.WebMailAuthenticationBackend' to AUTHENTICATION_BACKENDS in settings.py.

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'iitgauth.auth.WebMailAuthenticationBackend',
]

This is all the configuration required to use the webmail authentication backend.

Note that authenticate method of the backend requires following credentials:
  • username

  • password

  • login server

  • port (default is set to 995)

Following snippet shows how webmail authentication can be done in a custom view.

from django.contrib.auth import authenticate
from django.views.generic import View

class LoginView(View):

    def get(self, request):
        # get request handling logic
        #

    def post(self, request):
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data('username')
            password = form.cleaned_data('password')
            login_server = form.cleaned_data('login_server')

            # open a socket to login server and query validity of credentials
            user = auth.authenticate(username=username, password=password,
                        login_server=login_server, port=995)
            #
            # rest of authentication logic
            #
       else:
           # invalid form hadling

Usage: WebmailLoginForm and WebmailLoginView

A ready-to-use form (WebmailLoginForm) and a class based view (WebmailLoginView) are also available. Using this form and view is not necessary. You can write your own custom login form and view to use with webmail authentication backend as explained above.

This form works exactly similar to Django’s built-in AuthenticationForm. Only difference is WebmailLoginForm has one extra field, .i.e. Login Server field.

WebmailLoginForm has 3 fields:
  • username

  • password

  • login_server

WebmailLoginView is a FormView which renders WebmailLoginForm on GET and redirects to success_url on successful authentication.

Demo

Note: There is a working demo project available under example directory.

demo

Metadata

Release files for django-iitg-auth 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-iitg-auth 0.0.4
File Size Uploaded
django-iitg-auth-0.0.4.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-iitg-auth 0.0.4
File Interpreter ABI Platform
django_iitg_auth-0.0.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 15.0 kB

Release files / django-iitg-auth-0.0.4.tar.gz

Download URL django-iitg-auth-0.0.4.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dff29f27f523361ac09f5e81a60ca90e3e90a6ed49fbe7fc4dff839078fbde63
BLAKE2b-256 checksum
How to use checksums
afd3ba5fb43ed004cbb4f87a289e72b8fa2047dad9f4b9a82b20e4a8eff69813
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_iitg_auth-0.0.4-py2.py3-none-any.whl

Download URL django_iitg_auth-0.0.4-py2.py3-none-any.whl
Size 8.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d854cc7b3faf7a12f135443b489545573c5498f860215200020f020c8574af66
BLAKE2b-256 checksum
How to use checksums
8e335fbc90a481e105a3c8c922ec021481c0d5f43c206f09c0cc22501d438c8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

1 release file

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page