{"id":454,"date":"2013-07-12T10:00:34","date_gmt":"2013-07-12T14:00:34","guid":{"rendered":"http:\/\/dashdrum.com\/blog\/?p=454"},"modified":"2013-07-12T10:00:34","modified_gmt":"2013-07-12T14:00:34","slug":"cas-with-django-1-5","status":"publish","type":"post","link":"https:\/\/dashdrum.com\/blog\/2013\/07\/cas-with-django-1-5\/","title":{"rendered":"CAS with Django 1.5"},"content":{"rendered":"<p>I&#8217;ve posted a <a href=\"http:\/\/dashdrum.com\/blog\/2009\/04\/using-cas-with-django\/\">couple<\/a> of <a href=\"http:\/\/dashdrum.com\/blog\/2009\/11\/using-cas-with-django-an-update\/\">times<\/a> before about using a <a href=\"http:\/\/www.jasig.org\/cas\">Central Authentication Service<\/a> with Django.  As I update my applications to Django v1.5, it is time to revisit the subject.<\/p>\n<p>In my Django v1.3 setup, the <a href=\"https:\/\/bitbucket.org\/cpcc\/django-cas\/overview\">django-cas<\/a> library has served me well.  However, in this later version of the framework, there are changes that break the library.  The maintainer of django-cas has not yet updated their code to work with 1.5 (although there are pull requests waiting that address the issue &#8211; stay tuned).<\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Kansas_State_University\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/1.bp.blogspot.com\/-TYCAMTSoaQQ\/Twh91lC87OI\/AAAAAAAAD-4\/Xxa-2U3PNEU\/s200\/wildcatlogo.jpg\" width=\"185\" height=\"200\" alt=\"Kansas State Wildcat\" class=\"alignright\" \/><\/a>Luckily, another educational institution has forked the library.  Our friends at <a href=\"http:\/\/www.k-state.edu\/\">Kansas State University<\/a> (Go Wildcats!) have released their maintained version of <a href=\"https:\/\/github.com\/kstateome\/django-cas\">django-cas on github<\/a>.  They have fixed the issue with the <code>get_host()<\/code> call, plus added some proxy features.  Note that the fix is in a branch and not yet in a released version &#8211; currently at v0.8.5.  I have installed it in my first app to be converted, and it works fine.<\/p>\n<h2>Installation<\/h2>\n<p>As far as I can tell, this K-State fork is not hosted on PyPi at this time, so I use this line in my requirements file to get the library via pip:<\/p>\n<pre><code>svn+https:\/\/github.com\/kstateome\/django-cas\/branches\/bugfix\/django_1_5\n<\/code><\/pre>\n<p>This uses Subversion because that is what is available on the servers, but the git syntax will work just as well.<\/p>\n<h2>Configuration<\/h2>\n<p>K-State has provided only minimal documentation, but they link back to the original <a href=\"http:\/\/www.cpcc.edu\/\">CCPC<\/a> <a href=\"https:\/\/bitbucket.org\/cpcc\/django-cas\/overview\">installation guide<\/a>. Below are my <code>settings.py<\/code> and <code>urls.py<\/code> code. (Note that <code>USE_CAS<\/code> is a variable I define that is set True or False based on the environment.)<\/p>\n<pre><code>## django_cas settings\nif USE_CAS:\n    CAS_SERVER_URL = '### your server URL here ###'\n    CAS_VERSION = '2'\n    CAS_LOGOUT_COMPLETELY = True\n\n    AUTHENTICATION_BACKENDS = (\n        'django.contrib.auth.backends.ModelBackend',\n        'cas.backends.CASBackend',\n    )\n\n    MIDDLEWARE_CLASSES += (\n        'cas.middleware.CASMiddleware',\n    )\n## end django_cas settings\n\n# django_cas urls\nif settings.USE_CAS:\n    urlpatterns = patterns('',\n    ('^admin\/logout\/$', RedirectView.as_view(url='..\/..\/accounts\/logout')), ## TODO: This could be better\n    ('^admin\/password_change\/$',RedirectView.as_view(url='### URL to your password change service ###')),\n    url(r'^accounts\/login\/$', 'cas.views.login',name='login'),\n    url(r'^accounts\/logout\/$', 'cas.views.logout',name='logout'),\n                       ) + urlpatterns\nelse:\n    urlpatterns = patterns('',\n    url(r'^accounts\/login\/$', 'django.contrib.auth.views.login',{'template_name': 'login.html'},name='login'),\n                       ) + urlpatterns       \n# end django_cas urls\n<\/code><\/pre>\n<p>Biggest change is that the package name changed from <code>django-cas<\/code> to <code>cas<\/code>.<\/p>\n<p>Best of luck with your CAS setup!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve posted a couple of times before about using a Central Authentication Service with Django. As I update my applications to Django v1.5, it is time to revisit the subject. In my Django v1.3 setup, the django-cas library has served me well. However, in this later version of the framework, there are changes that break &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/dashdrum.com\/blog\/2013\/07\/cas-with-django-1-5\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;CAS with Django 1.5&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-454","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/posts\/454","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/comments?post=454"}],"version-history":[{"count":2,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/posts\/454\/revisions"}],"predecessor-version":[{"id":456,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/posts\/454\/revisions\/456"}],"wp:attachment":[{"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/media?parent=454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/categories?post=454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/tags?post=454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}