Skip to main content

Django app for LDAP authentication using IIT Bombay gymkhana SSO.

Project description

PyPI release Travis-ci Python versions License

Django Oauth2 Client to authenticate using IIT Bombay gymkhana SSO

A small package for LDAP authentication using IIT Bombay gymkhana SSO.

Motivation

SSO can be a tricky thing to setup and bugs can be time consuming to debug. With people moving away from PHP to Django and node, this module can be used to quickly define custom callbacks that map the user details obtained from IIT Bombay gymkhana SSO to your Django user model. You get a quick and easy way to programatically create users once they are authenticated.

Setting up in your app

For using this Django app, the following steps must be done:

INSTALLED_APPS = [
   # ...
    'iitb_oauth'
   # ...
]
AUTHENTICATION_BACKENDS = [
# ...
'iitb_oauth.backend.OauthBackend'
# ...
]

Step 2: Add the oauth urls to the root website:

urlpatterns = [
    # ...
    url(r'', include('iitb_oauth.urls')),
    # ...
]

Step 3: Add the LOGIN_URL and corresponding OAUTH config settings for your application. Also add the FALLBACK_URL as a fallback in case OAuth authentication fails. Example:

AUTH_PROFILE_MODULE = ""  # In case User has a user profile, specify the class here
LOGIN_URL = "/login/"
FALLBACK_URL = "/" # In case user is not logged in or doesn't have enough permissions to view the content


CLIENT_ID = 'my-id'
CLIENT_SECRET = '<secret>'

SCOPE = 'ldap'  # ldap is necessary for login, pass only necessary scopes. seperate with spaces
# Eg: SCOPE = 'profile ldap program'

FIELDS = 'username' # username is mandatory field. seperate with commas
# Eg: FIELDS = 'username,first_name,last_name,email,roll_number'

REDIRECT_URI = '<app_redirect_url>' # should end with /oauth/complete (the view is provided by this app)

LOGIN_COMPLETE_REDIRECT = '/some/url/in/your/app'
LOGOUT_REDIRECT = '/' # redirect to this URL after logout.
MAPPINGS = {
    # fields in User model: "LDAP attributes"
    # email mapped with username@iitb.ac.in if email is not in scope.
    "first_name": "first_name",
    "last_name": "last_name"
}  # In case a custom User model is defined, map fields in User model: "LDAP attributes"
PROFILE_MAPPING = {
    # Maps fields in user profile with response recieved from sso server.
    # AUTH_PROFILE_MODULE needs to be specified for this to work.
    "roll_number" : "roll_number"
}

Usage

Once you try to access some endpoint that has the @login_required decorator on top of it, you'll be redirected to the login URI that you defined. The user is authenticated using IITB gymkhana SSO and any other backends you provided. Upon successful authentication the url specified in LOGIN_COMPLETE_REDIRECT are called and the callbacks are used to shape your user into the form that you've provided. If authentication fails due to any reason or if the user does not have permission, he will be redirected to the URI specified in FALLBACK_URL.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iitb_oauth-1.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

iitb_oauth-1.2-py2.py3-none-any.whl (7.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file iitb_oauth-1.2.tar.gz.

File metadata

  • Download URL: iitb_oauth-1.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.1

File hashes

Hashes for iitb_oauth-1.2.tar.gz
Algorithm Hash digest
SHA256 600602eaa38fa274e1bc7307423c8e9517f73fbbf421551e91a19d52c3c99ca1
MD5 332d7f44e78748bd42cf8c20af5a420c
BLAKE2b-256 ae9522bc6b75c68544a034ba2d736d1a4801cd847dfd53074f861655bc175c67

See more details on using hashes here.

File details

Details for the file iitb_oauth-1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: iitb_oauth-1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.1

File hashes

Hashes for iitb_oauth-1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 92c2dc593c16379b8da96c0c6eb6ec1f9f3c7a7d290fe88815e7173756ee6a1f
MD5 713da2649f22d24825006640157e23b0
BLAKE2b-256 c43d6c69b8fbdefbfa236dc23d7fa94d30a67b54e9c58ca9dec0b0dd2a60fbb0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page