cobywinfield / umd-python-cas

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

umd-python-cas

Getting Started

umd-python-cas allows authentication through the University of Maryland's Central Authentication Service (CAS) using any Python backend Framework.

To get started, follow the instructions on one of our demo repos, with Flask or Django. Those examples will help you get started with umd-python-cas in a web app environment. The rest of this readme has extra information.

Install

pip install umd-python-cas

Example Use

from umd_python_cas import UMDCASClient

client = UMDCASClient(host_name="http://127.0.0.1:5000", post_auth_route="/secure")

How It Works

UMDCASClient class

umd-python-cas contains a single class, called UMDCASClient that can be used with any Python backend framework to interact with the University of Maryland Central Authentication Services. This class manages the authentication to the UMD CAS servers. To create an instance of the class, you use the constructor, passing in both a hostname and a post_auth_route:

from umd_python_cas import UMDCASClient

client = UMDCASClient(host_name="http://127.0.0.1:5000", post_auth_route="/secure")

The hostname tells the client what the base URL of your web sever is. For development, this is something like 127.0.0.1:5000 or localhost:5000 as shown. For a production app, this could be something like myapp.com.

The post_auth_route tells the client where to return to after the user logs in. This depends on how you set up your web server, see the Flask and Django demos at the beginning of this repo for examples.

get_login_cas_url

This returns the URL on the UMD CAS server that you can redirect to in order to log the user in. It contains an encoded version of the location to return to so that the CAS servers know how to redirect the user back after logging in. You should set up a route on your app for something like /login to return a redirect to this URL, as shown in the Flask and Django demos.

get_logout_cas_url

This returns the URL on the UMD CAS server that you can redirect to in order to to log the user out. Map this to a route such as /logout just like the previous.

validate_ticket

When the user has redirected back from the UMD CAS servers after logging in, they will return to your server (at the URL defined by post_auth_route) with a ticket. Pass the ticket to validate_ticket to verify that the user logged in correctly, in which case it will return the user's username. Store this in a session variable in your app, to keep track that the user is logged in and give access to the app.

Authors

  • Jacob (Coby) Winfield
  • Johan Vandegriff

Credits

  • Daniel Laurence
  • Jim Purtilo
  • Ronel Aguilar

References

About

License:MIT License


Languages

Language:Python 100.0%