Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAML with Django authentication

I'm using Django and nginx hosted on AWS. I'm trying to integrate with a university for SAML authentication, using their idp. There are plenty of outdated answers on SO, but is there anything more relevant with current standards?

Many of the apps i've seen are for django 1.2 and lower. Specifically i'm looking for resources that would allow me to more easily manage the SAML authentication through some middleware or anything else.

Some of the things I have seen are:

https://github.com/unomena/django-saml2-idp

https://github.com/WiserTogether/django-saml2-sp

like image 229
KVISH Avatar asked Mar 26 '14 17:03

KVISH


People also ask

Does Django support SAML?

Any SAML2 based SSO(Single-Sign-On) identity provider with dynamic metadata configuration is supported by this Django plugin, for example Okta.

Does SAML provide authentication?

SAML is an open standard used for authentication. Based upon the Extensible Markup Language (XML) format, web applications use SAML to transfer authentication data between two parties - the identity provider (IdP) and the service provider (SP).

Can I use SAML for authorization?

SAML is a protocol that can be used for exchange of any information, including authorization-related "stuff". For example, in a very simple role-based access control scenario a SAML assertion issued by the identity provider can contain user's roles represented as attributes (or a single multi-valued attribute).


2 Answers

SAML is two sides:

  • IDP -> Identity Provider side -> i.e. the university
  • SP -> Service Provider -> i.e. your application

Sounds like this one is what you want: https://github.com/WiserTogether/django-saml2-sp.

You have to take into account that SAML as a standard is complex, so you might find issues getting the library talk to the SAML implementation in the university. You will also have to get from them the identity provider cert public key and ask them to add your application on their side with a specific entity id. And when you start managing a couple of them it gets complex.

You might also want to check out something like Auth0 to handle all those SAML connections. There is a very simple python sample https://gist.github.com/woloski/8149412

like image 39
woloski Avatar answered Sep 17 '22 09:09

woloski


The project I found is below:

https://bitbucket.org/lgs/djangosaml2/overview

The project uses psaml2 for SAML support. Pysaml2 can be found here:

https://github.com/rohe/pysaml2

Bear in mind that djangosaml2 may not use the latest version of pysaml2. I tested it and its working fine.

UPDATE

djangosaml2 works with latest version of pysaml2, but make sure to add this line to make it work:

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

This should be in your settings.py.

like image 128
KVISH Avatar answered Sep 18 '22 09:09

KVISH