Package openid :: Package consumer :: Module consumer :: Class Consumer
[frames] | no frames]

Class Consumer

source code

object --+
         |
        Consumer

An OpenID consumer implementation that performs discovery and does session management.

Instance Methods [hide private]
  __init__(self, session, store, consumer_class=None)
Initialize a Consumer instance.
AuthRequest begin(self, user_url, anonymous=True)
Start the OpenID authentication process.
AuthRequest beginWithoutDiscovery(self, service, anonymous=True)
Start OpenID verification without doing OpenID server discovery.
  complete(self, query, return_to=None)
Called to interpret the server's response to an OpenID request.
  setAssociationPreference(self, association_preferences)
Set the order in which association types/sessions should be attempted.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__


Class Variables [hide private]
  session_key_prefix = '_openid_consumer_'
A string that is prepended to session keys to ensure that they are unique.

Instance Variables [hide private]
GenericConsumer consumer
an instance of an object implementing the OpenID protocol, but doing no discovery or session management.
  session
A dictionary-like object representing the user's session data.

Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, session, store, consumer_class=None)
(Constructor)

source code 

Initialize a Consumer instance.

You should create a new instance of the Consumer object with every HTTP request that handles OpenID transactions.
Parameters:
Overrides: object.__init__
See Also:
openid.store.interface, openid.store

begin(self, user_url, anonymous=True)

source code 

Start the OpenID authentication process. See steps 1-2 in the overview at the top of this file.
Parameters:
  • user_url (unicode) - Identity URL given by the user. This method performs a textual transformation of the URL to try and make sure it is normalized. For example, a user_url of example.com will be normalized to http://example.com/ normalizing and resolving any redirects the server might issue.
  • anonymous (bool) - Whether to make an anonymous request of the OpenID provider. Such a request does not ask for an authorization assertion for an OpenID identifier, but may be used with extensions to pass other data. e.g. "I don't care who you are, but I'd like to know your time zone."
Returns: AuthRequest
An object containing the discovered information will be returned, with a method for building a redirect URL to the server, as described in step 3 of the overview. This object may also be used to add extension arguments to the request, using its addExtensionArg method.
Raises:

beginWithoutDiscovery(self, service, anonymous=True)

source code 

Start OpenID verification without doing OpenID server discovery. This method is used internally by Consumer.begin after discovery is performed, and exists to provide an interface for library users needing to perform their own discovery.
Parameters:
Returns: AuthRequest
an OpenID authentication request object.
See Also:
Openid.consumer.consumer.Consumer.begin, openid.consumer.discover

complete(self, query, return_to=None)

source code 

Called to interpret the server's response to an OpenID request. It is called in step 4 of the flow described in the consumer overview.
Parameters:
  • query - A dictionary of the query parameters for this HTTP request.
  • return_to - The return URL used to invoke the application. Extract the URL from your application's web request framework and specify it here to have it checked against the openid.return_to value in the response. If the return_to URL check fails, the status of the completion will be FAILURE.
Returns:
a subclass of Response. The type of response is indicated by the status attribute, which will be one of SUCCESS, CANCEL, FAILURE, or SETUP_NEEDED.
See Also:
SuccessResponse, CancelResponse, SetupNeededResponse, FailureResponse

setAssociationPreference(self, association_preferences)

source code 

Set the order in which association types/sessions should be attempted. For instance, to only allow HMAC-SHA256 associations created with a DH-SHA256 association session:
>>> consumer.setAssociationPreference([('HMAC-SHA256', 'DH-SHA256')])
Any association type/association type pair that is not in this list will not be attempted at all.
Parameters:
  • association_preferences ([(str, str)]) - The list of allowed (association type, association session type) pairs that should be allowed for this consumer to use, in order from most preferred to least preferred.
Returns:
None

See Also: openid.association.SessionNegotiator


Class Variable Details [hide private]

session_key_prefix


A string that is prepended to session keys to ensure that they are unique. This variable may be changed to suit your application.
Value:
'_openid_consumer_'                                                    
      

Instance Variable Details [hide private]

consumer


an instance of an object implementing the OpenID protocol, but doing no discovery or session management.
Type:
GenericConsumer

session


A dictionary-like object representing the user's session data. This is used for keeping state of the OpenID transaction when the user is redirected to the server.