Skip to content
brianwebb edited this page Feb 7, 2011 · 7 revisions

sibboleth (Python)

Usage

Retrieving a list of identity providers from a slcs server: from sibboleth.credentials import CredentialManager, Idp from sibboleth.shibboleth import Shibboleth from cookielib import MozillaCookieJar

slcs_server_url = "https://slcstest.arcs.org.au/SLCS/login" # URL of the SLCS server
idp = CustomIdp()
c = CustomCredMgr()
cj = MozillaCookieJar()
shibopener = Shibboleth(idp, c, cj)

# Running the openurl method on the Shibboleth object without an idp or username/password will cause 
# an exception to be thrown, but will populate the list of available idp's regardless
try:
    slcsresp = shibopener.openurl(slcs_server_url)
except (Exception):
    pass

idps = shibopener.idp.get_idps() # List of available identity providers for that SLCS server

# We need to override and add some functionality to the standard Idp class
class CustomIdp(Idp):
    def prompt(self, controller):
        """
        Since we don't want to actually prompt the user to choose an identity provider at this point,
        continue the processing of the controller object, which will cause an exception to be thrown
        """
        return controller.run()

    def get_idps(self):
        # Returns the list of identity providers supported by the SLCS server
        return self.idps

    def set_idp(self, idp):
        # Sets the selected identity provider
        self.idp = idp
    
class CustomCredMgr(CredentialManager):
    def prompt(self, controller):
        """
        Since we don't want to actually prompt the user for a username and password at this point,
        continue the processing of the controller object, which will cause an exception to be thrown
        """
        return controller.run()

Examples

Clone this wiki locally