{"id":18147536,"url":"https://github.com/audiolion/django-shibauth-rit","last_synced_at":"2025-04-23T21:51:33.333Z","repository":{"id":57421901,"uuid":"82232254","full_name":"audiolion/django-shibauth-rit","owner":"audiolion","description":"Integration with RIT's Shibboleth Identity Provider for authentication with Django","archived":false,"fork":false,"pushed_at":"2022-12-26T20:29:08.000Z","size":69,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-16T05:51:19.262Z","etag":null,"topics":["authentication","django","rit","rochester-institute-of-technology","shibboleth"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/audiolion.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-16T22:26:11.000Z","updated_at":"2023-08-23T12:58:31.000Z","dependencies_parsed_at":"2023-01-31T01:15:37.420Z","dependency_job_id":null,"html_url":"https://github.com/audiolion/django-shibauth-rit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/audiolion%2Fdjango-shibauth-rit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/audiolion%2Fdjango-shibauth-rit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/audiolion%2Fdjango-shibauth-rit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/audiolion%2Fdjango-shibauth-rit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/audiolion","download_url":"https://codeload.github.com/audiolion/django-shibauth-rit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250522293,"owners_count":21444510,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","django","rit","rochester-institute-of-technology","shibboleth"],"created_at":"2024-11-01T22:06:49.889Z","updated_at":"2025-04-23T21:51:33.312Z","avatar_url":"https://github.com/audiolion.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=============================\nDjango Shib Auth RIT\n=============================\n\n.. image:: https://badge.fury.io/py/django-shibauth-rit.svg\n    :target: https://badge.fury.io/py/django-shibauth-rit\n\n.. image:: https://travis-ci.org/audiolion/django-shibauth-rit.svg?branch=master\n    :target: https://travis-ci.org/audiolion/django-shibauth-rit\n\n.. image:: https://codecov.io/gh/audiolion/django-shibauth-rit/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/audiolion/django-shibauth-rit\n\nIntegrate Shibboleth Authentication with your RIT projects\n\nQuickstart\n----------\n\nInstall Django Shib Auth RIT::\n\n    pip install django-shibauth-rit\n\nAdd it to your `INSTALLED_APPS`:\n\n.. code-block:: python\n\n    INSTALLED_APPS = (\n        ...\n        'shibauth_rit',\n        ...\n    )\n\nAdd the authentication backend:\n\n.. code-block:: python\n\n    AUTHENTICATION_BACKENDS = [\n        'shibauth_rit.backends.ShibauthRitBackend',\n        ...\n    ]\n\nAdd the middleware to process requests:\n\n.. code-block:: python\n\n    # use MIDDLEWARE_CLASSES on Django 1.8\n    MIDDLEWARE = (\n      ...\n      'django.contrib.auth.middleware.AuthenticationMiddleware',\n      'shibauth_rit.middleware.ShibauthRitMiddleware',\n      ...\n    )\n\nAdd Django Shib Auth RIT's URL patterns:\n\n.. code-block:: python\n\n    urlpatterns = [\n        ...\n        url(r'^', include('shibauth_rit.urls')),\n        ...\n    ]\n\nSet the `LOGIN_URL` setting to the login handler of RIT's Shibboleth installation:\n\n.. code-block:: python\n\n    LOGIN_URL = 'https://\u003cyour-site-root\u003e/Shibboleth.sso/Login'\n\nMap Shibboleth's return attributes to your user model:\n\n.. code-block:: python\n\n    SHIBAUTH_ATTRIBUTE_MAP = {\n        'uid': (True, 'username'),\n        'mail': (False, 'email'),\n    }\n\nShibboleth returns a number of attributes after a successful authentication. According to RIT's\ndocs the current attributes returned are:\n\n.. code-block::\n    uid - the user's RIT username\n    givenName - the user's given (first) name\n    sn -the user's surname (last/family name)\n    mail - the user's email address (note that this can be null)\n    ritEduMemberOfUid - groups the account is a member of (Ex: forklift-operators, vendingmach-admins, historyintegrator, etc.)\n    ritEduAffiliation - multi-valued attribute showing relationship to RIT (Ex: Student, Staff, StudentWorker, Adjust, Retiree etc.)\n\nNote: Additional attributes can be configured on a site-by-site basis. Please contact the ITS Service Desk with requests for additional attributes.\n\nWhen you map attributes, you use a Tuple of ``(Boolean, 'UserModelField')`` where ``Boolean`` indicates if the field is ``REQUIRED``. This should match your\nUser model's requirements. If your User model is as follow:\n\n.. code-block:: python\n\n    class User(AbstractBaseUser, PermissionsMixin):\n        USERNAME_FIELD = 'email'\n        EMAIL_FIELD = 'email'\n\n        email = models.EmailField(_('email address'), unique=True, blank=True, null=True)\n        username = models.CharField(_('username'), unique=True, required=True, max_length=50)\n        name = models.CharField(_('Name of User'), blank=True, max_length=100)\n\nThen ``username`` is a required attribute and should be ``'uid': (True, 'username')`` but email is not\nrequired and should be ``'mail': (False, 'email')``.\n\nNote: If email is a required field on your model, shibboleth doesn't guarantee that `mail` will be populated so you will need to handle that exception. You can do this by subclassing `ShibauthRitBackend` and overriding ``handle_parse_exception()`` method. See `Subclassing ShibauthRitMiddleware`_ .\n\n.htaccess Setup\n---------------\n\nThis package requires your site to be hosted on RIT's servers. The .htaccess should look like this\n\n.. code-block:: apache\n\n  # Ensure https is on. required for shibboleth auth\n  RewriteCond ${HTTPS} off\n  RewriteRule (.*) https://%{HTTP_HOST} [R,L]\n\n  # Two options, lazy loading where people do not need to authenticate to get to your site\n  \u003cIf \"%{HTTPS} == 'on'\"\u003e\n    SSLRequireSSL\n    AuthType shibboleth\n    Require shibboleth\n    ShibRequestSetting requireSession false\n    ShibRedirectToSSL 443\n  \u003c/If\u003e\n\n  # Or no lazy loading, strict requirement of shib authentication before accesing site\n  \u003cIf \"%{HTTPS} == 'on'\"\u003e\n    SSLRequireSSL\n    AuthType shibboleth\n    ShibRequireSession On\n    require valid-user\n    # see https://www.rit.edu/webdev/authenticating-and-authorizing-rit-users for other require options\n  \u003c/If\u003e\n\nThis sets up some stuff with the Apache webserver so when people go to ``https://\u003cyour-site-root\u003e/Shibboleth.sso/Login`` it initiates the redirect to RIT's Shibboleth logon. Don't put a url route there, though I think Apache would always pick it up before it got to your code, might as well not mess with it.\n\nContext Processors\n------------------\n\nThere are two context processors included which allow you to place `{{ login_link }}` or `{{ logout_link }}` in your templates for routing users to the login or logout page. These are available as a convenience and are not required. To activate, add the following to your settings:\n\n.. code-block:: python\n\n    TEMPLATES = [\n        {\n        ...\n            'OPTIONS': {\n                'context_processors': [\n                    ...\n                    'shibauth_rit.context_processors.login_link',\n                    'shibauth_rit.context_processors.logout_link',\n                    ...\n                ],\n            },\n        ...\n        },\n    ]\n\n\nSubclassing ShibauthRitMiddleware\n------------------------------\n\nShibauthRitMiddleware has a few hooks that you can utilize to get customized behavior. To use these create a ``middleware.py`` file and add the following:\n\n.. code-block:: python\n\n    from shibauth_rit.middleware import ShibauthRitMiddleware as middleware\n    from shibauth_rit.middleware import ShibauthRitValidationException\n\n    \n    class ShibauthRitMiddleware(middleware):\n    \n        def make_profile(self, user, shib_meta):\n            \"\"\"\n            This is here as a stub to allow subclassing of ShibauthRitMiddleware\n            to include a make_profile method that will create a Django user profile\n            from the Shib provided attributes.  By default it does nothing.\n            \"\"\"\n            pass\n\n        def setup_session(self, request):\n            \"\"\"\n            If you want to add custom code to setup user sessions, you can extend this.\n            \"\"\"\n            pass\n\n        def handle_parse_exception(self, shib_meta):\n            \"\"\"\n            This is a stub method that can be subclassed to handle what should happen when a parse\n            exception occurs. If you raise ShibauthRitValidationException it will need to be caught\n            further up to prevent an internal server error (HTTP 500). An example of this would be if\n            you require an email address and RIT Shibboleth doesn't return one, what should you do?\n            \"\"\"\n            pass\n\n\nReplace ``pass`` with any custom code you want to run. Then make sure to modify your ``MIDDLEWARE`` or ``MIDDLEWARE_CLASSES`` attribute to include the path to your custom middleware and replace this packages.\n\n.. code-block:: python\n\n    MIDDLEWARE = (\n        ...\n        yourapp.backends.ShibauthRitMiddleware,\n        ...\n    )\n        \nRunning Tests\n-------------\n\nTo do a simple test run with your current config\n\n.. code-block:: bash\n\n    $ python runtests.py\n\nTo comprehensively test the suite across versions of python and django\n\n.. code-block:: bash\n\n    source \u003cYOURVIRTUALENV\u003e/bin/activate\n    (myenv) $ pip install tox\n    (myenv) $ tox\n\n\nCredits\n-------\n\nTools used in rendering this package:\n\n*  Cookiecutter_\n*  `cookiecutter-djangopackage`_\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage\n.. _`Subclassing ShibauthRitMiddleware`: #subclassing-shibauthritmiddleware\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faudiolion%2Fdjango-shibauth-rit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faudiolion%2Fdjango-shibauth-rit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faudiolion%2Fdjango-shibauth-rit/lists"}