
    )Jf+                       d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
mZmZmZmZmZ ddlmZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZmZmZ dd
lmZ ddl m!Z!m"Z# ddl$m%Z% ddlm&Z& g dZ' ej(        e)          Z*d Z+d Z, G d de-          Z. G d de-          Z/ G d de/          Z0 G d de-          Z1 G d de2          Z3 G d de4          Z5 G d de5          Z6 G d d e2          Z7 G d! d"e-          Z8 G d# d$e-          Z9d%Z:d&Z;d'Z<d(Z= G d) d*e-          Z> G d+ d,e>          Z? G d- d.e>          Z@ G d/ d0e>          ZA G d1 d2e>          ZBdS )3a   OpenID support for Relying Parties (aka Consumers).

This module documents the main interface with the OpenID consumer
library.  The only part of the library which has to be used and isn't
documented in full here is the store required to create an
C{L{Consumer}} instance.  More on the abstract store type and
concrete implementations of it that are provided in the documentation
for the C{L{__init__<Consumer.__init__>}} method of the
C{L{Consumer}} class.


OVERVIEW
========

    The OpenID identity verification process most commonly uses the
    following steps, as visible to the user of this library:

        1. The user enters their OpenID into a field on the consumer's
           site, and hits a login button.

        2. The consumer site discovers the user's OpenID provider using
           the Yadis protocol.

        3. The consumer site sends the browser a redirect to the
           OpenID provider.  This is the authentication request as
           described in the OpenID specification.

        4. The OpenID provider's site sends the browser a redirect
           back to the consumer site.  This redirect contains the
           provider's response to the authentication request.

    The most important part of the flow to note is the consumer's site
    must handle two separate HTTP requests in order to perform the
    full identity check.


LIBRARY DESIGN
==============

    This consumer library is designed with that flow in mind.  The
    goal is to make it as easy as possible to perform the above steps
    securely.

    At a high level, there are two important parts in the consumer
    library.  The first important part is this module, which contains
    the interface to actually use this library.  The second is the
    C{L{openid.store.interface}} module, which describes the
    interface to use if you need to create a custom method for storing
    the state this library needs to maintain between requests.

    In general, the second part is less important for users of the
    library to know about, as several implementations are provided
    which cover a wide variety of situations in which consumers may
    use the library.

    This module contains a class, C{L{Consumer}}, with methods
    corresponding to the actions necessary in each of steps 2, 3, and
    4 described in the overview.  Use of this library should be as easy
    as creating an C{L{Consumer}} instance and calling the methods
    appropriate for the action the site wants to take.


SESSIONS, STORES, AND STATELESS MODE
====================================

    The C{L{Consumer}} object keeps track of two types of state:

        1. State of the user's current authentication attempt.  Things like
           the identity URL, the list of endpoints discovered for that
           URL, and in case where some endpoints are unreachable, the list
           of endpoints already tried.  This state needs to be held from
           Consumer.begin() to Consumer.complete(), but it is only applicable
           to a single session with a single user agent, and at the end of
           the authentication process (i.e. when an OP replies with either
           C{id_res} or C{cancel}) it may be discarded.

        2. State of relationships with servers, i.e. shared secrets
           (associations) with servers and nonces seen on signed messages.
           This information should persist from one session to the next and
           should not be bound to a particular user-agent.


    These two types of storage are reflected in the first two arguments of
    Consumer's constructor, C{session} and C{store}.  C{session} is a
    dict-like object and we hope your web framework provides you with one
    of these bound to the user agent.  C{store} is an instance of
    L{openid.store.interface.OpenIDStore}.

    Since the store does hold secrets shared between your application and the
    OpenID provider, you should be careful about how you use it in a shared
    hosting environment.  If the filesystem or database permissions of your
    web host allow strangers to read from them, do not store your data there!
    If you have no safe place to store your data, construct your consumer
    with C{None} for the store, and it will operate only in stateless mode.
    Stateless mode may be slower, put more load on the OpenID provider, and
    trusts the provider to keep you safe from replay attacks.


    Several store implementation are provided, and the interface is
    fully documented so that custom stores can be used as well.  See
    the documentation for the C{L{Consumer}} class for more
    information on the interface for stores.  The implementations that
    are provided allow the consumer site to store the necessary data
    in several different ways, including several SQL databases and
    normal files on disk.


IMMEDIATE MODE
==============

    In the flow described above, the user may need to confirm to the
    OpenID provider that it's ok to disclose his or her identity.
    The provider may draw pages asking for information from the user
    before it redirects the browser back to the consumer's site.  This
    is generally transparent to the consumer site, so it is typically
    ignored as an implementation detail.

    There can be times, however, where the consumer site wants to get
    a response immediately.  When this is the case, the consumer can
    put the library in immediate mode.  In immediate mode, there is an
    extra response possible from the server, which is essentially the
    server reporting that it doesn't have enough information to answer
    the question yet.


USING THIS LIBRARY
==================

    Integrating this library into an application is usually a
    relatively straightforward process.  The process should basically
    follow this plan:

    Add an OpenID login field somewhere on your site.  When an OpenID
    is entered in that field and the form is submitted, it should make
    a request to your site which includes that OpenID URL.

    First, the application should L{instantiate a Consumer<Consumer.__init__>}
    with a session for per-user state and store for shared state.
    using the store of choice.

    Next, the application should call the 'C{L{begin<Consumer.begin>}}' method on the
    C{L{Consumer}} instance.  This method takes the OpenID URL.  The
    C{L{begin<Consumer.begin>}} method returns an C{L{AuthRequest}}
    object.

    Next, the application should call the
    C{L{redirectURL<AuthRequest.redirectURL>}} method on the
    C{L{AuthRequest}} object.  The parameter C{return_to} is the URL
    that the OpenID server will send the user back to after attempting
    to verify his or her identity.  The C{realm} parameter is the
    URL (or URL pattern) that identifies your web site to the user
    when he or she is authorizing it.  Send a redirect to the
    resulting URL to the user's browser.

    That's the first half of the authentication process.  The second
    half of the process is done after the user's OpenID Provider sends the
    user's browser a redirect back to your site to complete their
    login.

    When that happens, the user will contact your site at the URL
    given as the C{return_to} URL to the
    C{L{redirectURL<AuthRequest.redirectURL>}} call made
    above.  The request will have several query parameters added to
    the URL by the OpenID provider as the information necessary to
    finish the request.

    Get a C{L{Consumer}} instance with the same session and store as
    before and call its C{L{complete<Consumer.complete>}} method,
    passing in all the received query arguments.

    There are multiple possible return types possible from that
    method. These indicate whether or not the login was successful,
    and include any additional information appropriate for their type.

@var SUCCESS: constant used as the status for
    L{SuccessResponse<openid.consumer.consumer.SuccessResponse>} objects.

@var FAILURE: constant used as the status for
    L{FailureResponse<openid.consumer.consumer.FailureResponse>} objects.

@var CANCEL: constant used as the status for
    L{CancelResponse<openid.consumer.consumer.CancelResponse>} objects.

@var SETUP_NEEDED: constant used as the status for
    L{SetupNeededResponse<openid.consumer.consumer.SetupNeededResponse>}
    objects.
    N)urlparse	urldefrag	parse_qsl)fetchers)discoverOpenIDServiceEndpointDiscoveryFailureOPENID_1_0_TYPEOPENID_1_1_TYPEOPENID_2_0_TYPE)Message	OPENID_NS
OPENID2_NS
OPENID1_NSIDENTIFIER_SELECT
no_defaultBARE_NS)	cryptutil)oidutil)Associationdefault_negotiatorSessionNegotiator)DiffieHellman)mkNoncesplit)	Discovery)urinorm)
AuthRequestConsumerSuccessResponseSetupNeededResponseCancelResponseFailureResponseSUCCESSFAILURECANCELSETUP_NEEDEDc                 r    t          j        ||                                           }t          ||          S )zMake a Direct Request to an OpenID Provider and return the
    result as a Message object.

    @raises openid.fetchers.HTTPFetchingError: if an error is
        encountered in making the HTTP post.

    @rtype: L{openid.message.Message}
    )body)r   fetchtoURLEncoded_httpResponseToMessage)request_message
server_urlresps      [/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/consumer/consumer.py
makeKVPostr1      s6     >*?+G+G+I+IJJJD "$
333    c                     t          j        | j                  }| j        dk    rt                              |          | j        dvr"d}||| j        fz  }t          j        |          |S )au  Adapt a POST response to a Message.

    @type response: L{openid.fetchers.HTTPResponse}
    @param response: Result of a POST to an OpenID endpoint.

    @rtype: L{openid.message.Message}

    @raises openid.fetchers.HTTPFetchingError: if the server returned a
        status of other than 200 or 400.

    @raises ServerError: if the server returned an OpenID error.
    i  )      z"bad status code from server %s: %s)r   
fromKVFormr)   statusServerErrorfromMessager   HTTPFetchingError)responser.   response_messagefmterror_messages        r0   r,   r,      ss     )(-88#%%&6777	
	*	*2z8?;;(777r2   c                   T    e Zd ZdZdZdZ ee          ZddZ	ddZ
ddZd	 Zd
 ZdS )r   a  An OpenID consumer implementation that performs discovery and
    does session management.

    @ivar consumer: an instance of an object implementing the OpenID
        protocol, but doing no discovery or session management.

    @type consumer: GenericConsumer

    @ivar 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.

    @cvar 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.
    _openid_consumer_
last_tokenNc                 n    || _         |t          } ||          | _        | j        | j        z   | _        dS )ax  Initialize a Consumer instance.

        You should create a new instance of the Consumer object with
        every HTTP request that handles OpenID transactions.

        @param session: See L{the session instance variable<openid.consumer.consumer.Consumer.session>}

        @param store: an object that implements the interface in
            C{L{openid.store.interface.OpenIDStore}}.  Several
            implementations are provided, to cover common database
            environments.

        @type store: C{L{openid.store.interface.OpenIDStore}}

        @see: L{openid.store.interface}
        @see: L{openid.store}
        N)sessionGenericConsumerconsumersession_key_prefix_token
_token_key)selfrC   storeconsumer_classs       r0   __init__zConsumer.__init__!  s<    $ !,N&u--1DK?r2   Fc                 $   t          | j        || j                  }	 |                    | j                  }n/# t
          j        $ r}t          d|j        d          d}~ww xY w|t          d|d          | 	                    ||          S )aw  Start the OpenID authentication process. See steps 1-2 in
        the overview at the top of this file.

        @param user_url: 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.

        @type user_url: unicode

        @param anonymous: 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."

        @type anonymous: bool

        @returns: 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
            L{addExtensionArg<openid.consumer.consumer.AuthRequest.addExtensionArg>}
            method.

        @returntype: L{AuthRequest<openid.consumer.consumer.AuthRequest>}

        @raises openid.consumer.discover.DiscoveryFailure: when I fail to
            find an OpenID server for this URL.  If the C{yadis} package
            is available, L{openid.consumer.discover.DiscoveryFailure} is
            an alias for C{yadis.discover.DiscoveryFailure}.
        zError fetching XRDS document: Nz$No usable OpenID services found for )
r   rC   rF   getNextService	_discoverr   r:   r	   whybeginWithoutDiscovery)rI   user_url	anonymousdiscoservicerP   s         r0   beginzConsumer.begin9  s    H $,$2IJJ	6**4>::GG) 	6 	6 	6""$'GG$/046 6 6	6 ?""$,H$0157 7 7 --gyAAAs   8 A$AA$c                     | j                             |          }|j        | j        | j        <   	 |                    |           n.# t          $ r!}t          t          |                    d}~ww xY w|S )a  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.

        @param service: an OpenID service endpoint descriptor.  This
            object and factories for it are found in the
            L{openid.consumer.discover} module.

        @type service:
            L{OpenIDServiceEndpoint<openid.consumer.discover.OpenIDServiceEndpoint>}

        @returns: an OpenID authentication request object.

        @rtype: L{AuthRequest<openid.consumer.consumer.AuthRequest>}

        @See: Openid.consumer.consumer.Consumer.begin
        @see: openid.consumer.discover
        N)	rE   rV   endpointrC   rH   setAnonymous
ValueErrorProtocolErrorstr)rI   rU   rS   auth_reqrP   s        r0   rQ   zConsumer.beginWithoutDiscoveryj  s    * =&&w//(0(9T_%	*!!),,,, 	* 	* 	*C)))	* s   A 
A1A,,A1c                 n   | j                             | j                  }t          j        |          }| j                            |||          }	 | j         | j        = n# t          $ r Y nw xY w|j        dv r=|j	        6t          | j         |j	        | j                  }|                    d           |S )aZ  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.

        @param query: A dictionary of the query parameters for this
            HTTP request.

        @param current_url: The 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: L{SuccessResponse<openid.consumer.consumer.SuccessResponse>}
        @see: L{CancelResponse<openid.consumer.consumer.CancelResponse>}
        @see: L{SetupNeededResponse<openid.consumer.consumer.SetupNeededResponse>}
        @see: L{FailureResponse<openid.consumer.consumer.FailureResponse>}
        )successcancelNT)force)rC   getrH   r   fromPostArgsrE   completeKeyErrorr7   identity_urlr   rF   cleanup)rI   querycurrent_urlrX   messager;   rT   s          r0   rd   zConsumer.complete  s    2 <##DO44&u--=))'8[II	T_-- 	 	 	D	 O444%1dlH,A"57 7E MMM%%%s   A 
A,+A,c                 8    t          |          | j        _        dS )a   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.

        @param association_preferences: 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.
        @type association_preferences: [(str, str)]

        @returns: None

        @see: C{L{openid.association.SessionNegotiator}}
        N)r   rE   
negotiator)rI   association_preferencess     r0   setAssociationPreferencez!Consumer.setAssociationPreference  s    ( $55L#M#M   r2   N)F)__name__
__module____qualname____doc__rF   rG   staticmethodr   rO   rL   rV   rQ   rd   rn    r2   r0   r   r   
  s           -FX&&I@ @ @ @0/B /B /B /Bb   >, , ,\N N N N Nr2   r   c                   P    e Zd ZdZ eej                  ZdZdgZ	ddZ
d Zd ZdS )	 DiffieHellmanSHA1ConsumerSessionDH-SHA1   	HMAC-SHA1Nc                 >    |t          j                    }|| _        d S ro   )r   fromDefaultsdh)rI   r}   s     r0   rL   z)DiffieHellmanSHA1ConsumerSession.__init__  s     :+--Br2   c                    t          j        | j        j                  }d|i}| j                                        sP|                    t          j        | j        j                  t          j        | j        j                  d           |S )Ndh_consumer_public)
dh_modulusdh_gen)r   longToBase64r}   publicusingDefaultValuesupdatemodulus	generator)rI   cpubargss      r0   
getRequestz+DiffieHellmanSHA1ConsumerSession.getRequest  s    %dgn55$d+w))++ 	KK'4TW_EE#01BCC    
 r2   c                    |                     t          dt                    }|                     t          dt                    }t          j        |          }t          j        |          }| j                            ||| j	                  S )Ndh_server_publicenc_mac_key)
getArgr   r   r   base64ToLongr   
fromBase64r}   	xorSecret	hash_func)rI   r;   dh_server_public64enc_mac_key64r   r   s         r0   extractSecretz.DiffieHellmanSHA1ConsumerSession.extractSecret  sr    %__Y8J-79 9 	=*MM$12DEE(77w  !1;OOOr2   ro   )rp   rq   rr   session_typert   r   sha1r   secret_sizeallowed_assoc_typesrL   r   r   ru   r2   r0   rw   rw     sn        LY^,,IK&-     P P P P Pr2   rw   c                   <    e Zd ZdZ eej                  ZdZdgZ	dS )"DiffieHellmanSHA256ConsumerSession	DH-SHA256    HMAC-SHA256N)
rp   rq   rr   r   rt   r   sha256r   r   r   ru   r2   r0   r   r     s4        LY-..IK(/r2   r   c                   &    e Zd ZdZddgZd Zd ZdS )PlainTextConsumerSessionno-encryptionrz   r   c                     i S ro   ru   rI   s    r0   r   z#PlainTextConsumerSession.getRequest  s    	r2   c                 l    |                     t          dt                    }t          j        |          S )Nmac_key)r   r   r   r   r   )rI   r;   	mac_key64s      r0   r   z&PlainTextConsumerSession.extractSecret  s(    OOIy*EE	!),,,r2   N)rp   rq   rr   r   r   r   r   ru   r2   r0   r   r     sB        "L&6  - - - - -r2   r   c                       e Zd ZdZddZdS )SetupNeededErrorzVInternally-used exception that indicates that an immediate-mode
    request cancelled.Nc                 J    t                               | |           || _        d S ro   )	ExceptionrL   user_setup_url)rI   r   s     r0   rL   zSetupNeededError.__init__  s&    4000,r2   ro   )rp   rq   rr   rs   rL   ru   r2   r0   r   r     s2         - - - - - -r2   r   c                       e Zd ZdZdS )r[   zsException that indicates that a message violated the
    protocol. It is raised and caught internally to this file.N)rp   rq   rr   rs   ru   r2   r0   r[   r[     s"        B B B Br2   r[   c                       e Zd ZdZd Zd ZdS )TypeURIMismatchz8A protocol error arising from type URIs mismatching
    c                 Z    t                               | ||           || _        || _        d S ro   )r[   rL   expectedrX   )rI   r   rX   s      r0   rL   zTypeURIMismatch.__init__  s,    tXx888  r2   c                 z    d| j         j        d| j         j        d| j        d| j        j        d| j        d}|S )N<.z: Required type z not found in z for endpoint >)	__class__rq   rp   r   rX   	type_uris)rI   ss     r0   __str__zTypeURIMismatch.__str__  sK     N%%%t~'>'>'>M###T]]]4 r2   N)rp   rq   rr   rs   rL   r   ru   r2   r0   r   r     s<         ! ! !
    r2   r   c                   4    e Zd ZdZd Zd Z ee          ZdS )r8   z]Exception that is raised when the server returns a 400 response
    code to a direct request.c                 f    t                               | |           || _        || _        || _        d S ro   )r   rL   
error_text
error_coderj   )rI   r   r   rj   s       r0   rL   zServerError.__init__%  s1    4,,,$$r2   c                     |                     t          dd          }|                     t          d          } | |||          S )zgGenerate a ServerError instance, extracting the error text
        and the error code from the message.errorz<no error message supplied>r   )r   r   )clsrj   r   r   s       r0   r9   zServerError.fromMessage+  sG     ^^Iw$AC C
^^I|<<
s:z7333r2   N)rp   rq   rr   rs   rL   r9   classmethodru   r2   r0   r8   r8   !  sG        ! !  4 4 4 +k**KKKr2   r8   c                   *   e Zd ZdZdZdZeeedZ	 e
e          Zd Zd Zd Zd Zd	 Zd
 Zd Zd Zd Z e
e          Zd Zd Zd Zd Zd Zd Zd Z e
e          Zd&dZd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d  Z)d! Z*d" Z+d# Z,d$ Z-d% Z.dS )'rD   a  This is the implementation of the common logic for OpenID
    consumers. It is unaware of the application in which it is
    running.

    @ivar negotiator: An object that controls the kind of associations
        that the consumer makes. It defaults to
        C{L{openid.association.default_negotiator}}. Assign a
        different negotiator to it if you have specific requirements
        for how associations are made.
    @type negotiator: C{L{openid.association.SessionNegotiator}}
    janrain_nonceopenid1_claimed_id)rx   r   r   c                 D    || _         t          j                    | _        d S ro   )rJ   r   copyrl   )rI   rJ   s     r0   rL   zGenericConsumer.__init__X  s    
,133r2   c                     | j         d}n|                     |          }t          ||          }t                      |j        | j        <   |j                                        r|j        j	        |j        | j
        <   |S )zCreate an AuthRequest object for the specified
        service_endpoint. This method will create an association if
        necessary.N)rJ   _getAssociationr   r   return_to_argsopenid1_nonce_query_arg_namerj   	isOpenID1rX   
claimed_id!openid1_return_to_identifier_name)rI   service_endpointassocrequests       r0   rV   zGenericConsumer.begin\  s     :EE(()9::E.66DKIIt@A?$$&& 	, + "4#IJ r2   c                     |                     t          dd          }t          | d|z   | j                  } ||||          S )zProcess the OpenID message, using the specified endpoint
        and return_to URL as context. This method will handle any
        OpenID message that is sent to the return_to URL.
        mode<No mode set>
_complete_)r   r   getattr_completeInvalid)rI   rj   rX   	return_tor   
modeMethods         r0   rd   zGenericConsumer.completen  sF    
 ~~iAAT<$#68MNN
z'8Y777r2   c                      t          |          S ro   )r"   )rI   rj   rX   _s       r0   _complete_cancelz GenericConsumer._complete_cancely  s    h'''r2   c                     |                     t          d          }|                     t          d          }|                     t          d          }t          ||||          S )Nr   contact	reference)r   r   r   r   r#   )rI   rj   rX   r   r   r   r   s          r0   _complete_errorzGenericConsumer._complete_error|  s_    y'22..I66NN9k::	eW	C C C 	Cr2   c                     |                                 s|                     |||          S |                    t          d          }t	          ||          S )Nr   )	isOpenID2r   r   r   r!   )rI   rj   rX   r   r   s        r0   _complete_setup_neededz&GenericConsumer._complete_setup_needed  sR      "" 	?(((A>>> 
4DEE"8^<<<r2   c                    	 |                      |           	 |                     |||          S # t          t          f$ r}t	          ||          cY d }~S d }~ww xY w# t
          $ r}t          ||j                  cY d }~S d }~ww xY wro   )_checkSetupNeeded_doIdResr[   r	   r#   r   r!   r   )rI   rj   rX   r   rP   s        r0   _complete_id_resz GenericConsumer._complete_id_res  s    	6""7+++6}}Wh	BBB!#34 6 6 6&x555555556   	E 	E 	E&x1CDDDDDDDD	Es8   A / A AAA
B'B;BBc                 `    |                     t          dd          }t          |d|          S )Nr   r   zInvalid openid.mode: r   )rI   rj   rX   r   r   s        r0   r   z GenericConsumer._completeInvalid  s.    ~~iAAxxdd)MNNNr2   c                    	 |                      |                                           n5# t          $ r(}t                              d|           Y d}~dS d}~ww xY w|                    t          d          }t          t          j        |                    }t          t          j        |                    }t          dd          D ]}||         ||         k    r dS dS )zCheck an OpenID message and its openid.return_to value
        against a return_to URL from an application.  Return True on
        success, False on failure.
        zVerifying return_to arguments: NFr   r      T)
_verifyReturnToArgs
toPostArgsr[   logger	exceptionr   r   r   r   range)rI   rj   r   rP   msg_return_to	app_parts	msg_partsparts           r0   _checkReturnTozGenericConsumer._checkReturnTo  s    	$$W%7%7%9%9:::: 	 	 	CCJKKK55555	
  y+>> W_Y7788	W_];;<<	 !QKK 	 	D)D/11uu 2 ts   '* 
AAAc                     |                                 r,|                    t          d          }|t          |          dS dS )zCheck an id_res message to see if it is a
        checkid_immediate cancel response.

        @raises SetupNeededError: if it is a checkid_immediate cancellation
        r   N)r   r   r   r   )rI   rj   r   s      r0   r   z!GenericConsumer._checkSetupNeeded  sP      	7$^^J8HIIN)&~666	7 	7))r2   c           	      d   |                      |           |                     ||          s.t          d|d|                    t          d                    |                     ||          }t                              d|j        d|                    t          d                     | 	                    ||j                   | 
                    ||           |                    t          dt                    }|                    d          }d	 |D             }t          |||          S )
a  Handle id_res responses that are not cancellations of
        immediate mode requests.

        @param message: the response paramaters.
        @param endpoint: the discovered endpoint object. May be None.

        @raises ProtocolError: If the message contents are not
            well-formed according to the OpenID specification. This
            includes missing fields or not signing fields that should
            be signed.

        @raises DiscoveryFailure: If the subject of the id_res message
            does not match the supplied endpoint, and discovery on the
            identifier in the message fails (this should only happen
            when using OpenID 2)

        @returntype: L{Response}
        z.return_to does not match return URL. Expected , got r   zReceived id_res response from z using association assoc_handlesigned,c                     g | ]}d |z   S )zopenid.ru   ).0r   s     r0   
<listcomp>z,GenericConsumer._doIdRes.<locals>.<listcomp>  s    <<<1Q<<<r2   )_idResCheckForFieldsr   r[   r   r   _verifyDiscoveryResultsr   infor.   _idResCheckSignature_idResCheckNoncer   r   r    )rI   rj   rX   r   signed_list_strsigned_listsigned_fieldss          r0   r   zGenericConsumer._doIdRes  s@   * 	!!'***""7I66 	E-GNN9kBBBDE E E
 //BB)))nnY???A 	B 	B 	B 	!!'8+>??? 	gx000!..HjII%++C00<<<<<x-@@@r2   c                 B    |                     t          | j                  S )aB  Extract the nonce from an OpenID 1 response.  Return the
        nonce from the BARE_NS since we independently check the
        return_to arguments are the same as those in the response
        message.

        See the openid1_nonce_query_arg_name class variable

        @returns: The nonce as a string or None
        )r   r   r   )rI   rj   rX   s      r0   _idResGetNonceOpenID1z%GenericConsumer._idResGetNonceOpenID1  s     ~~gt'HIIIr2   c                    |                                 r|                     ||          }d}n"|                    t          d          }|j        }|t          d          	 t          |          \  }}n$# t          $ r}t          d|          d }~ww xY w| j        +| j        	                    |||          st          d          d S d S )N response_noncezNonce missing from responsezMalformed nonce: z"Nonce already used or out of range)
r   r  r   r   r.   r[   
splitNoncerZ   rJ   useNonce)rI   rj   rX   noncer.   	timestampsaltrP   s           r0   r  z GenericConsumer._idResCheckNonce  s     	-..wAAEJJNN:/?@@E!,J= =>>>	A(//OItt 	A 	A 	A- ?@@@	A J"J''
ItDD # DEEE #"""s   "A5 5
B?BBc                 \   |                     t          d          }| j        d }n| j                            ||          }|rD|j        dk    rt          d|d          |                    |          st          d          d S |                     ||          st          d          d S )Nr   r   zAssociation with z expiredzBad signaturez"Server denied check_authentication)r   r   rJ   getAssociation	expiresInr[   checkMessageSignature
_checkAuth)rI   rj   r.   r   r   s        r0   r  z$GenericConsumer._idResCheckSignature  s    ~~i@@:EEJ--j,GGE 	J!## $m%/ZZ%3 4 4 4 ..w77 5#O4445 5 ??7J77 J#$HIIIJ Jr2   c                    g d}ddg}t           |dgz   t          |dgz   i}t           |g dz   t          |i}||                                         D ]/}|                    t          |          st          d|          0|                    t          dt                    }|                    d          }||                                         D ]4}|                    t          |          r||vrt          d	|d
          5d S )N)r   r   sigr   r   identityop_endpoint)r
  r   r   r  zMissing required field r   r   "z" not signed)	r   r   getOpenIDNamespacehasKeyr   r[   r   r   r   )	rI   rj   basic_fieldsbasic_sig_fieldsrequire_fieldsrequire_sigsfieldr  r  s	            r0   r   z$GenericConsumer._idResCheckForFields0  sG    FEE'4 6
|3
 KKKL
 $G$>$>$@$@A 	M 	ME>>)U33 M#m55$KLLLM "..HjII%++C00!'"<"<">">? 	C 	CE~~i// CE4L4L#m$ABBB	C 	Cr2   c                    t          j        |           }|                    t          d          }|t	          d          t          |          }|d         }t          |          }|D ]O\  }}	 | |         }||k    rd}	t	          |	|||fz            ,# t          $ r d}	t	          |	|| fz            w xY w|                    t                    }
|

                                D ]}||vrt	          d|d         d	           dS )
z]Verify that the arguments in the return_to URL are present in this
        response.
        r   NzResponse has no return_to   z9parameter %s value %r does not match return_to's value %rz+return_to parameter %s absent from query %rz
Parameter r   z not in return_to URL)r   rc   r   r   r[   r   r   re   getArgsr   items)rh   rj   r   
parsed_urlrt_queryparsed_argsrt_keyrt_valuevalueformat	bare_argspairs               r0   r   z#GenericConsumer._verifyReturnToArgsS  sW    &u--NN9k::	 ;<<<i((
a=))
 !, 		> 		>FH>fu$$5F'&%1J(JKKK %  > > >F#Ffe_$<===> OOG,,	OO%% 	1 	1D;&&#m%)!WWW%0 1 1 1 '	1 	1s   /%B!B6Nc                     |                                 t          k    r|                     ||          S |                     ||          S )a  
        Extract the information from an OpenID assertion message and
        verify it against the original

        @param endpoint: The endpoint that resulted from doing discovery
        @param resp_msg: The id_res message object

        @returns: the verified endpoint
        )r  r   _verifyDiscoveryResultsOpenID2_verifyDiscoveryResultsOpenID1)rI   resp_msgrX   s      r0   r   z'GenericConsumer._verifyDiscoveryResults{  sG     &&((J6666xJJJ66xJJJr2   c                 B   t                      }t          g|_        |                    t          d          |_        |                    t          d          |_        |                    t          dt                    |_        |j        |j        t          d          |j        |j        t          d          |j        t          j
        |j                  S |s7t                              d           |                     |j        |g          }n|                                r7t                              d           |                     |j        |g          }n	 |                     ||           nw# t          $ rj}t                              dt#          |          z              t                              d	           |                     |j        |g          }Y d }~nd }~ww xY w|j        |j        k    r t%          j        |          }|j        |_        |S )
Nr   r  r  z4openid.identity is present without openid.claimed_idz4openid.claimed_id is present without openid.identityz'No pre-discovered information supplied.z>Pre-discovered information based on OP-ID; need to rediscover.6Error attempting to use stored discovery information: 'Attempting discovery to verify endpoint)r   r   r   r   r   r   local_idr   r.   r[   fromOPEndpointURLr   r   _discoverAndVerifyisOPIdentifier_verifyDiscoverySingler   r\   r   )rI   r1  rX   to_matches        r0   r/  z.GenericConsumer._verifyDiscoveryResultsOpenID2  s2   (**-.&ooj,GG$OOJ
CC 'ooj-.8: :
 'H,=,IFH H H !-(2C2KFH H H  ((:8;NOOO  	?KKABBB..x/BXJOOHH$$&& 	?KKP   ..x/BXJOOHH
?++Hh????  ? ? ?  LFF   EFFF2283F4<:? ?? ("555y**H"*"5Hs   !E8 8
G,A G''G,c                    |                     t          | j                  }||t          d          |	||j        }t                      }t          g|_        |                     t          d          |_	        ||_        |j	        t          d          t          j        |          }t          g|_        |	 	 |                     ||           n&# t          $ r |                     ||           Y nw xY w|S # t          $ rN}t                              dt#          |          z              t                              d           Y d }~nd }~ww xY w|                     |||g          S )NzWhen using OpenID 1, the claimed ID must be supplied, either by passing it through as a return_to parameter or by using a session, and supplied to the GenericConsumer as the argument to complete()r  z&Missing required field openid.identityr3  r4  )r   r   r   RuntimeErrorr   r   r   r   r   r5  r[   r   r
   r9  r   r   r   r\   r   r7  )rI   r1  rX   r   r:  to_match_1_0r;  s          r0   r0  z.GenericConsumer._verifyDiscoveryResultsOpenID1  s   __W%)%KM M
 
 201 1 1
 !j&8!,J(**-.$OOJ
CC($ HIIIy**"1!2 H//(CCCC& H H H//,GGGGGH   ! G G G  LFF   EFFFFFFFF	G &&zHl3KLLLs7   <C C;  C63C; 5C66C; ;
EAEEc                 `   |j         D ]'}|                    |          st          ||          (t          |j                  \  }}||j        k    rt          d|d|j                  |                                |                                k    r9t          d|                                d|                                          |j        )|                                t          k    s
J d            dS |j        |j        k    rt          d|j        d|j                  dS )a  Verify that the given endpoint matches the information
        extracted from the OpenID assertion, and raise an exception if
        there is a mismatch.

        @type endpoint: openid.consumer.discover.OpenIDServiceEndpoint
        @type to_match: openid.consumer.discover.OpenIDServiceEndpoint

        @rtype: NoneType

        @raises ProtocolError: when the endpoint does not match the
            discovered information.
        z:Claimed ID does not match (different subjects!), Expected r   zlocal_id mismatch. Expected NzThe code calling this must ensure that OpenID 2
                responses have a non-none `openid.op_endpoint' and
                that it is set as the `server_url' attribute of the
                `to_match' endpoint.zOP Endpoint mismatch. Expected )
r   usesExtensionr   r   r   r[   
getLocalIDr.   preferredNamespacer   )rI   rX   r:  type_uridefragged_claimed_idr   s         r0   r9  z&GenericConsumer._verifyDiscoverySingle  s    !* 	: 	:H))(33 :%h999:
 #,H,?"@"@a8#666- &%%x':':<= = =
   H$7$7$9$999-!)!4!4!6!6!6!68K8K8M8M8M!O P P P &..00J>>>( ?>>>>  H$777-!)!4!4!4h6I6I!K L L L 87r2   c                     t                               d|           |                     |          \  }}|st          d|d          |                     |||          S )a`  Given an endpoint object created from the information in an
        OpenID response, perform discovery and verify the discovery
        results, returning the matching endpoint that is the result of
        doing that discovery.

        @type to_match: openid.consumer.discover.OpenIDServiceEndpoint
        @param to_match: The endpoint whose information we're confirming

        @rtype: openid.consumer.discover.OpenIDServiceEndpoint
        @returns: The result of performing discovery on the claimed
            identifier in `to_match'

        @raises DiscoveryFailure: when discovery fails.
        zPerforming discovery on zNo OpenID information found at N)r   r   rO   r	   _verifyDiscoveredServices)rI   r   to_match_endpointsr   servicess        r0   r7  z"GenericConsumer._discoverAndVerify  s~     	JJABBBnnZ008 	9""$.J$2379 9 9--j(.@B B 	Br2   c                 h   g }|D ]\}|D ]W}	 |                      ||           |c c S # t          $ r,}|                    t          |                     Y d}~Pd}~ww xY w]t                              d|           |D ]}t                              d|z               t          d|d          )zSee @L{_discoverAndVerify}Nz#Discovery verification failure for z * Endpoint mismatch: z-No matching endpoint found after discovering )r9  r[   appendr\   r   r   r	   )	rI   r   rH  rG  failure_messagesrX   to_match_endpointrP   failure_messages	            r0   rF  z)GenericConsumer._verifyDiscoveredServices6  s      	& 	&H%7 $ $!$//:KLLL $OOOOO % 6 6 6$++CHH555555556$ LLL%:) * * *#3 I I5GHHHH"" $& & &s   (
A"AAc                 ^   t                               d           |                     |          }|dS 	 |                     ||          }|                     ||          S # t
          j        t          f$ r5}|j        d         }t           	                    d|z             Y d}~dS d}~ww xY w)zMake a check_authentication request to verify this message.

        @returns: True if the request is valid.
        @rtype: bool
        z!Using OpenID check_authenticationNFr   zcheck_authentication failed: %s)
r   r   _createCheckAuthRequest_makeKVPost_processCheckAuthResponser   r:   r8   r   r   )rI   rj   r.   r   r;   r;  e0s          r0   r  zGenericConsumer._checkAuthQ  s     	7888..w77?5	H''<<H 11(JGGG *K8 	 	 	B>CDDD55555	s   A! !B,7*B''B,c                    |                     t          d          }|rt          |t                    rt	          |d          }|                    d          D ]S}t                              |           |                    |          }| t                              d|            dS T|	                                }|
                    t          dd           |S )	zYGenerate a check_authentication request message given an
        id_res message.
        r   zutf-8)encodingr   NzMissing signed field r   check_authentication)r   r   
isinstancebytesr\   r   r   r   getAliasedArgr   setArg)rI   rj   r   kvalcheck_auth_messages         r0   rO  z'GenericConsumer._createCheckAuthRequestd  s     	844 
	 &%(( 7Vg666\\#&&    A++A.. ;KKKQQ ABBB44  %\\^^!!)V5KLLL!!r2   c                 p   |                     t          dd          }|                     t          d          }|Zt                              d|           | j        t                              d           n| j                            ||           |dk    rdS t                              d	           d
S )zzProcess the response message from a check_authentication
        request, invalidating associations if requested.
        is_validfalseinvalidate_handleNz)Received "invalidate_handle" from server z3Unexpectedly got invalidate_handle without a store!trueTz0Server responds that checkAuth call is not validF)r   r   r   r   rJ   r   removeAssociation)rI   r;   r.   r^  r`  s        r0   rQ  z)GenericConsumer._processCheckAuthResponsey  s     ??9j'BB$OOI7JKK(KKK$*( ) ) )z! ) * * * * 
,,Z9JKKKv4LLKLLL5r2   c                     | j                             |j                  }||j        dk    r7|                     |          }| | j                             |j        |           |S )a  Get an association for the endpoint's server_url.

        First try seeing if we have a good association in the
        store. If we do not, then attempt to negotiate an association
        with the server.

        If we negotiate a good association, it will get stored.

        @returns: A valid association for the endpoint's server_url or None
        @rtype: openid.association.Association or NoneType
        Nr   )rJ   r  r.   r  _negotiateAssociationstoreAssociationrI   rX   r   s      r0   r   zGenericConsumer._getAssociation  sf     
))(*=>>=EOq00..x88E 
++H,?GGGr2   c           
         | j                                         \  }}	 |                     |||          }|S # t          $ r}|                     |||          }|h|\  }}	 |                     |||          }|cY d}~S # t          $ r7}t
                              d|j        d|d|           Y d}~Y d}~dS d}~ww xY wY d}~dS d}~ww xY w)zMake association requests to the server, attempting to
        create a new association.

        @returns: a new association object

        @rtype: L{openid.association.Association}
        NzServer z6 refused its suggested association type: session_type=z, assoc_type=)rl   getAllowedType_requestAssociationr8    _extractSupportedAssociationTyper   r   r.   )rI   rX   
assoc_typer   r   rP   supportedTypess          r0   rd  z%GenericConsumer._negotiateAssociation  sL    $(?#A#A#C#C 
L	,,Xz-9; ;E0 L-  	! 	! 	!!BBXz+ +N)+9(
L! 44Xz5AC CE !LLLLLL #       LLL %///zzKL L L  444444444  *)))))	!sE   7 
CC A>7C8C>
B?(B:0C:B??CCc                 0   |j         dk    s|j                                        r,t                              d|j        d|j                   dS t                              d|d|j                   |j                            t          d          }|j                            t          d          }||t                              d           dS | j	        
                    ||          s#d	}t                              |||fz             dS ||fS )
a,  Handle ServerErrors resulting from association requests.

        @returns: If server replied with an C{unsupported-type} error,
            return a tuple of supported C{association_type}, C{session_type}.
            Otherwise logs the error and returns None.
        @rtype: tuple or None
        zunsupported-typez1Server error when requesting an association from : NzUnsupported association type rk  r   zTServer responded with unsupported association session but did not supply a fallback.zPServer sent unsupported session/association type: session_type=%s, assoc_type=%s)r   rj   r   r   r   r.   r   r   r   rl   	isAllowed)rI   server_errorrX   rk  r   r=   s         r0   rj  z0GenericConsumer._extractSupportedAssociationType  sA    "&888#--// 9LLL$$$l&=&=?@ @ @ 4
 	!zz<#:#:> 	? 	? 	?
 ")00LII
#+229nMM!5LL C D D D4**:|DD 	,4CLLj99:::4|++r2   c                     |                      |||          \  }}	 |                     ||j                  }n:# t          j        $ r(}t
                              d|           Y d}~dS d}~ww xY w	 |                     ||          }|S # t          $ r0}t
                              d|j        d|           Y d}~dS d}~wt          $ r0}t
                              d|j        d|           Y d}~dS d}~ww xY w)a  Make and process one association request to this endpoint's
        OP endpoint URL.

        @returns: An association object or None if the association
            processing failed.

        @raises ServerError: when the remote OpenID server returns an error.
        z!openid.associate request failed: Nz,Missing required parameter in response from rn  z%Protocol error parsing response from )
_createAssociateRequestrP  r.   r   r:   r   r   _extractAssociationre   r[   )	rI   rX   rk  r   assoc_sessionr   r;   rP   r   s	            r0   ri  z#GenericConsumer._requestAssociation  sc    #::j,0 0t	''h.ABBHH) 	 	 	ccLMMM44444		,,X}EEE L  	 	 	$$$cc+, , , 44444 	 	 	'222CC9 : : :44444	s9   8 A/A**A/3B 
C=%C  C=%C88C=c                 F   | j         |         } |            }d|d}|                                s
t          |d<   |                                r|j        dk    r
|j        |d<   |                    |                                           t          j        |          }||fS )a  Create an association request for the given assoc_type and
        session_type.

        @param endpoint: The endpoint whose server_url will be
            queried. The important bit about the endpoint is whether
            it's in compatiblity mode (OpenID 1.1)

        @param assoc_type: The association type that the request
            should ask for.
        @type assoc_type: str

        @param session_type: The session type that should be used in
            the association request. The session_type is used to
            create an association session object, and that session
            object is asked for any additional fields that it needs to
            add to the request.
        @type session_type: str

        @returns: a pair of the association session object and the
            request message that will be sent to the server.
        @rtype: (association session type (depends on session_type),
                 openid.message.Message)
        	associate)r   rk  nsr   r   )session_typescompatibilityModer   r   r   r   r   fromOpenIDArgs)rI   rX   rk  r   session_type_classrt  r   rj   s           r0   rr  z'GenericConsumer._createAssociateRequest  s    0 "/=**,,  $
 

 ))++ 	$#DJ **,, 	>*o==#0#=D M,,..///(..g%%r2   c                     |                     t          d          }|dk    rt                              d           n
|dk    s|d}|S )a  Given an association response message, extract the OpenID
        1.X session type.

        This function mostly takes care of the 'no-encryption' default
        behavior in OpenID 1.

        If the association type is plain-text, this function will
        return 'no-encryption'

        @returns: The association type for this message
        @rtype: str

        @raises KeyError: when the session_type field is absent.
        r   r   z0OpenID server sent "no-encryption"for OpenID 1.Xr	  )r   r   r   warning)rI   assoc_responser   s      r0   _getOpenID1SessionTypez&GenericConsumer._getOpenID1SessionType@  sc    " &,,ZHH ?**NN - . . . . R<#7*Lr2   c                 h   |                     t          dt                    }|                     t          dt                    }|                     t          dt                    }	 t          |          }n$# t          $ r}t          d|          d}~ww xY w|                                r|                     |          }n!|                     t          dt                    }|j	        |k    rF|                                r|dk    rt                      }nd}	|	|j	        |fz  }
t          |
          ||j        vrd	}	t          |	|j	        |fz            	 |                    |          }n-# t          $ r }d
}	t          |	|j	        |fz            d}~ww xY wt          j        ||||          S )a  Attempt to extract an association from the response, given
        the association response message and the established
        association session.

        @param assoc_response: The association response message from
            the server
        @type assoc_response: openid.message.Message

        @param assoc_session: The association session object that was
            used when making the request
        @type assoc_session: depends on the session type of the request

        @raises ProtocolError: when data is malformed
        @raises KeyError: when a field is missing

        @rtype: openid.association.Association
        rk  r   
expires_inzInvalid expires_in field: Nr   r   z*Session type mismatch. Expected %r, got %rz2Unsupported assoc_type for session %s returned: %sz%Malformed response for %s session: %s)r   r   r   intrZ   r[   r   r  r   r   r   r   r   r   fromExpiresIn)rI   r~  rt  rk  r   expires_in_strr  rP   r   r=   rj   secrets               r0   rs  z#GenericConsumer._extractAssociationf  s   ( $**9lJOO
%,,Y-79 9 (..y,/9; ;	J^,,JJ 	J 	J 	J-## HIII	J ##%% 	=66~FFLL)00^1;= =L %55((** - O33 !9 : :
 C!;\ JJ#G,,, ]>>>FC}'A:&N NOOO
	I"00@@FF 	I 	I 	I9C}'A3&G GHHH	I (\6)35 5 	5s0   %A5 5
B?BBE0 0
F:FFro   )/rp   rq   rr   rs   r   r   rw   r   r   rx  rt   r   rO   rL   rV   rd   r   r   r   r   r   r   r1   rP  r   r   r  r  r  r   r   r   r/  r0  r9  r7  rF  r  rO  rQ  r   rd  rj  ri  rr  r  rs  ru   r2   r0   rD   rD   6  s       
 
$ $3 
 )=% 471 M X&&I4 4 4  $	8 	8 	8( ( (C C C= = =	6 	6 	6O O O  : ,z**K7 7 7*A *A *AX
J 
J 
JF F F*J J J8!C !C !CF$1 $1 $1L ',':;;K K K K9 9 9v(M (M (MT.L .L .L`B B B.& & &6H H H&" " "*  ,  *$ $ $L', ', ',R  @+& +& +&Z$ $ $LK5 K5 K5 K5 K5r2   rD   c                   \    e Zd ZdZd Zd Zd Zd ZddZdd	Z		 	 	 dd
Z
	 	 	 ddZd ZdS )r   a  An object that holds the state necessary for generating an
    OpenID authentication request. This object holds the association
    with the server and the discovered information with which the
    request will be made.

    It is separate from the consumer because you may wish to add
    things to the request before sending it on its way to the
    server. It also has serialization options that let you encode the
    authentication request as a URL or as a form POST.
    c                     || _         || _        i | _        t          |                                          | _        d| _        dS )a  
        Creates a new AuthRequest object.  This just stores each
        argument in an appropriately named field.

        Users of this library should not create instances of this
        class.  Instances of this class are created by the library
        when needed.
        FN)r   rX   r   r   rB  rj   
_anonymousrf  s      r0   rL   zAuthRequest.__init__  s@     
  x::<<==r2   c                 h    |r(| j                                         rt          d          || _        dS )a  Set whether this request should be made anonymously. If a
        request is anonymous, the identifier will not be sent in the
        request. This is only useful if you are making another kind of
        request with an extension in this request.

        Anonymous requests are not allowed when the request is made
        with OpenID 1.

        @raises ValueError: when attempting to set an OpenID1 request
            as anonymous
        z<OpenID 1 requests MUST include the identifier in the requestN)rj   r   rZ   r  )rI   is_anonymouss     r0   rY   zAuthRequest.setAnonymous  sE      	+DL2244 	+ 9 : : : +DOOOr2   c                 :    |                     | j                   dS )zAdd an extension to this checkid request.

        @param extension_request: An object that implements the
            extension interface for adding arguments to an OpenID
            message.
        N)	toMessagerj   )rI   extension_requests     r0   addExtensionzAuthRequest.addExtension  s      	##DL11111r2   c                 >    | j                             |||           dS )a  Add an extension argument to this OpenID authentication
        request.

        Use caution when adding arguments, because they will be
        URL-escaped and appended to the redirect URL, which can easily
        get quite long.

        @param namespace: The namespace for the extension. For
            example, the simple registration extension uses the
            namespace C{sreg}.

        @type namespace: str

        @param key: The key within the extension namespace. For
            example, the nickname field in the simple registration
            extension's key is C{nickname}.

        @type key: str

        @param value: The value to provide to the server for this
            argument.

        @type value: str
        N)rj   rY  )rI   	namespacekeyr*  s       r0   addExtensionArgzAuthRequest.addExtensionArg  s$    2 	IsE22222r2   NFc           	         |rt          j        || j                  }nO|rt          d          | j                                        rt          d          | j        rt          d          |rd}nd}| j                                        }|                                rd}nd}|                    t          ||d|d	|i           | j	        s| j
                                        r
t          x}}n%| j
                                        }| j
        j        }|                    t          d
|           |                                r|                    t"          d|           | j        r6|                    t          d| j        j                   d| j        j        }	nd}	t(                              d|d| j
        j        d|	           |S )a2  Produce a L{openid.message.Message} representing this request.

        @param realm: The URL (or URL pattern) that identifies your
            web site to the user when she is authorizing it.

        @type realm: str

        @param return_to: The URL that the OpenID provider will send the
            user back to after attempting to verify her identity.

            Not specifying a return_to URL means that the user will not
            be returned to the site issuing the request upon its
            completion.

        @type return_to: str

        @param immediate: If True, the OpenID provider is to send back
            a response immediately, useful for behind-the-scenes
            authentication attempts.  Otherwise the OpenID provider
            may engage the user before providing a response.  This is
            the default case, as the user may need to provide
            credentials or approve the request before a positive
            response can be sent.

        @type immediate: bool

        @returntype: L{openid.message.Message}
        z7"return_to" is mandatory when using "checkid_immediate"z."return_to" is mandatory for OpenID 1 requestszJextra "return_to" arguments were specified, but no return_to was specifiedcheckid_immediatecheckid_setup
trust_rootrealmr   r   r  r   r   zwith association zusing stateless mode.z
Generated z request to  )r   
appendArgsr   rZ   rj   r   r   
updateArgsr   r  rX   r8  r   rA  r   rY  r   r   r   handler   r   r.   )
rI   r  r   	immediater   rj   	realm_keyr   request_identityassoc_log_msgs
             r0   
getMessagezAuthRequest.getMessage  s   :  		?*9d6IJJII 	?IK K K\##%% 	?MNNN  	? > ? ? ?  	#&DD"D,##%% 	 $III9uD'
 	 	 	  	E}++-- 6 1BA
--#'=#;#;#=#= !]5
 NN9j2BCCC  "" Ez<DDD: 	4NN9ndj6GHHHH59Z5F5FIMM3MddDM444mmE 	F 	F 	F r2   c                 n    |                      |||          }|                    | j        j                  S )ah  Returns a URL with an encoded OpenID request.

        The resulting URL is the OpenID provider's endpoint URL with
        parameters appended as query arguments.  You should redirect
        the user agent to this URL.

        OpenID 2.0 endpoints also accept POST requests, see
        C{L{shouldSendRedirect}} and C{L{formMarkup}}.

        @param realm: The URL (or URL pattern) that identifies your
            web site to the user when she is authorizing it.

        @type realm: str

        @param return_to: The URL that the OpenID provider will send the
            user back to after attempting to verify her identity.

            Not specifying a return_to URL means that the user will not
            be returned to the site issuing the request upon its
            completion.

        @type return_to: str

        @param immediate: If True, the OpenID provider is to send back
            a response immediately, useful for behind-the-scenes
            authentication attempts.  Otherwise the OpenID provider
            may engage the user before providing a response.  This is
            the default case, as the user may need to provide
            credentials or approve the request before a positive
            response can be sent.

        @type immediate: bool

        @returns: The URL to redirect the user agent to.

        @returntype: str
        )r  toURLrX   r.   )rI   r  r   r  rj   s        r0   redirectURLzAuthRequest.redirectURLY  s1    L //%I>>}}T]5666r2   c                 p    |                      |||          }|                    | j        j        |          S )au  Get html for a form to submit this request to the IDP.

        @param form_tag_attrs: Dictionary of attributes to be added to
            the form tag. 'accept-charset' and 'enctype' have defaults
            that can be overridden. If a value is supplied for
            'action' or 'method', it will be replaced.
        @type form_tag_attrs: {unicode: unicode}
        )r  toFormMarkuprX   r.   )rI   r  r   r  form_tag_attrsrj   s         r0   
formMarkupzAuthRequest.formMarkup  s4     //%I>>##DM$<nMMMr2   c                 V    t          j        |                     ||||                    S )zGet an autosubmitting HTML page that submits this request to the
        IDP.  This is just a wrapper for formMarkup.

        @see: formMarkup

        @returns: str
        )r   autoSubmitHTMLr  )rI   r  r   r  r  s        r0   
htmlMarkupzAuthRequest.htmlMarkup  s1     %OOE9iHHJ J 	Jr2   c                 4    | j                                         S )zShould this OpenID authentication request be sent as a HTTP
        redirect or as a POST (form submission)?

        @rtype: bool
        )rX   ry  r   s    r0   shouldSendRedirectzAuthRequest.shouldSendRedirect  s     }..000r2   )NF)NFN)rp   rq   rr   rs   rL   rY   r  r  r  r  r  r  r  ru   r2   r0   r   r     s        	 	     + + +$2 2 23 3 36R R R Rh'7 '7 '7 '7V """&	N N N N$ """&	J J J J1 1 1 1 1r2   r   failurer_   r`   setup_neededc                       e Zd ZdZd Zd ZdS )ResponseNc                 B    || _         |	d | _        d S |j        | _        d S ro   )rX   rf   r   rI   rX   s     r0   setEndpointzResponse.setEndpoint  s.      $D ( 3Dr2   c                 F    | j         | j                                         S dS )a  Return the display identifier for this response.

        The display identifier is related to the Claimed Identifier, but the
        two are not always identical.  The display identifier is something the
        user should recognize as what they entered, whereas the response's
        claimed identifier (in the L{identity_url} attribute) may have extra
        information for better persistence.

        URLs will be stripped of their fragments for display.  XRIs will
        display the human-readable identifier (i-name) instead of the
        persistent identifier (i-number).

        Use the display identifier in your user interface.  Use
        L{identity_url} for querying your database or authorization server.
        N)rX   getDisplayIdentifierr   s    r0   r  zResponse.getDisplayIdentifier  s%      =$=55777tr2   )rp   rq   rr   r7   r  r  ru   r2   r0   r  r    s7        F4 4 4    r2   r  c                   V    e Zd ZdZeZddZd Zd ZddZ	d Z
d Zd	 Zd
 Zd Zd ZdS )r    a  A response with a status of SUCCESS. Indicates that this request is a
    successful acknowledgement from the OpenID server that the
    supplied URL is, indeed controlled by the requesting agent.

    @ivar identity_url: The identity URL that has been authenticated;
          the Claimed Identifier.
        See also L{getDisplayIdentifier}.

    @ivar endpoint: The endpoint that authenticated the identifier.  You
        may access other discovered information related to this endpoint,
        such as the CanonicalID of an XRI, through this object.
    @type endpoint:
       L{OpenIDServiceEndpoint<openid.consumer.discover.OpenIDServiceEndpoint>}

    @ivar signed_fields: The arguments in the server's response that
        were signed and verified.

    @cvar status: SUCCESS
    Nc                 P    || _         |j        | _        || _        |g }|| _        d S ro   )rX   r   rf   rj   r  )rI   rX   rj   r  s       r0   rL   zSuccessResponse.__init__  s6     !$/ M*r2   c                 4    | j                                         S )zVWas this authentication response an OpenID 1 authentication
        response?
        )rj   r   r   s    r0   r   zSuccessResponse.isOpenID1  s     |%%'''r2   c                 F    | j                             ||          | j        v S )z]Return whether a particular key is signed, regardless of
        its namespace alias
        )rj   getKeyr  )rI   ns_urins_keys      r0   isSignedzSuccessResponse.isSigned  s$     |""6622d6HHHr2   c                 j    |                      ||          r| j                            |||          S |S )zYReturn the specified signed field if available,
        otherwise return default
        )r  rj   r   )rI   r  r  defaults       r0   	getSignedzSuccessResponse.getSigned  s9     ==(( 	<&&vvw???Nr2   c                     | j                             |          }|                                D ]<}|                     ||          s$t                              d|d|d            dS =|S )zGet signed arguments from the response message.  Return a
        dict of all arguments in the specified namespace.  If any of
        the arguments are not signed, return None.
        zSuccessResponse.getSignedNS: (z, z) not signed.N)rj   r#  keysr  r   r   )rI   r  msg_argsr  s       r0   getSignedNSzSuccessResponse.getSignedNS  s    
 <''//==?? 	 	C==-- VVSSS"# # # tt	 r2   c                 d    |r|                      |          S | j                            |          S )aw  Return response arguments in the specified namespace.

        @param namespace_uri: The namespace URI of the arguments to be
        returned.

        @param require_signed: True if the arguments should be among
        those signed in the response, False if you don't care.

        If require_signed is True and the arguments are not signed,
        return None.
        )r  rj   r#  )rI   namespace_urirequire_signeds      r0   extensionResponsez!SuccessResponse.extensionResponse  s6      	7##M222<''666r2   c                 8    |                      t          d          S )ap  Get the openid.return_to argument from this response.

        This is useful for verifying that this request was initiated
        by this consumer.

        @returns: The return_to URL supplied to the server on the
            initial request, or C{None} if the response did not contain
            an C{openid.return_to} argument.

        @returntype: str
        r   )r  r   r   s    r0   getReturnTozSuccessResponse.getReturnTo(  s     ~~i555r2   c                     | j         |j         k    o?| j        |j        k    o/| j        |j        k    o| j        |j        k    o| j        |j        k    S ro   )rX   rf   rj   r  r7   rI   others     r0   __eq__zSuccessResponse.__eq__6  s_    %.0 ."e&88... #u'::. ,		/r2   c                     | |k     S ro   ru   r  s     r0   __ne__zSuccessResponse.__ne__=  s    EM""r2   c           	      \    d| j         j        d| j         j        d| j        d| j        d	S )Nr   r    id=z signed=r   )r   rq   rp   rf   r  r   s    r0   __repr__zSuccessResponse.__repr__@  s@     N%%%t~'>'>'>t1113 	3r2   ro   )rp   rq   rr   rs   r$   r7   rL   r   r  r  r  r  r  r  r  r  ru   r2   r0   r    r      s         ( F
+ 
+ 
+ 
+( ( (I I I      7 7 7"6 6 6/ / /# # #3 3 3 3 3r2   r    c                   $    e Zd ZdZeZddZd ZdS )r#   a  A response with a status of FAILURE. Indicates that the OpenID
    protocol has failed. This could be locally or remotely triggered.

    @ivar identity_url:  The identity URL for which authenitcation was
        attempted, if it can be determined. Otherwise, None.

    @ivar message: A message indicating why the request failed, if one
        is supplied. otherwise, None.

    @cvar status: FAILURE
    Nc                 Z    |                      |           || _        || _        || _        d S ro   )r  rj   r   r   )rI   rX   rj   r   r   s        r0   rL   zFailureResponse.__init__U  s/    """"r2   c           	      \    d| j         j        d| j         j        d| j        d| j        d	S )Nr   r   r  z	 message=r   )r   rq   rp   rf   rj   r   s    r0   r  zFailureResponse.__repr__[  s@     -1^-F-F-F-1^-D-D-D-1->->->N 	Nr2   )NNN)rp   rq   rr   rs   r%   r7   rL   r  ru   r2   r0   r#   r#   F  sM        
 
 F# # # #N N N N Nr2   r#   c                       e Zd ZdZeZd ZdS )r"   a  A response with a status of CANCEL. Indicates that the user
    cancelled the OpenID authentication request.

    @ivar identity_url: The identity URL for which authenitcation was
        attempted, if it can be determined. Otherwise, None.

    @cvar status: CANCEL
    c                 0    |                      |           d S ro   )r  r  s     r0   rL   zCancelResponse.__init__m  s    """""r2   N)rp   rq   rr   rs   r&   r7   rL   ru   r2   r0   r"   r"   a  s4          F# # # # #r2   r"   c                       e Zd ZdZeZddZdS )r!   a8  A response with a status of SETUP_NEEDED. Indicates that the
    request was in immediate mode, and the server is unable to
    authenticate the user without further interaction.

    @ivar identity_url:  The identity URL for which authenitcation was
        attempted.

    @ivar setup_url: A URL that can be used to send the user to the
        server to set up for authentication. The user should be
        redirected in to the setup_url, either in the current window
        or in a new browser window.  C{None} in OpenID 2.0.

    @cvar status: SETUP_NEEDED
    Nc                 >    |                      |           || _        d S ro   )r  	setup_url)rI   rX   r  s      r0   rL   zSetupNeededResponse.__init__  s!    """"r2   ro   )rp   rq   rr   rs   r'   r7   rL   ru   r2   r0   r!   r!   q  s9          F# # # # # #r2   r!   )Crs   r   loggingurllib.parser   r   r   openidr   openid.consumer.discoverr   r   r	   r
   r   r   openid.messager   r   r   r   r   r   r   r   r   openid.associationr   r   r   	openid.dhr   openid.store.noncer   r   r  openid.yadis.managerr   r   __all__	getLoggerrp   r   r1   r,   objectr   rw   r   r   r   r   rZ   r[   r   r8   rD   r   r%   r$   r&   r'   r  r    r#   r"   r!   ru   r2   r0   <module>r     s  z zx   7 7 7 7 7 7 7 7 7 7      I I I I I I I I I I I I I I I I, , , , , , , , , , , , , , , , , ,                      # # # # # # ; ; ; ; ; ; ; ; * * * * * *         
	8	$	$4 4 4   4AN AN AN AN ANv AN AN ANHP P P P Pv P P PD* * * * *)I * * *	- 	- 	- 	- 	-v 	- 	- 	-- - - - -y - - -B B B B BJ B B B
    m    + + + + +) + + +*{5 {5 {5 {5 {5f {5 {5 {5|s1 s1 s1 s1 s1& s1 s1 s1l 
	    v   >t3 t3 t3 t3 t3h t3 t3 t3nN N N N Nh N N N6# # # # #X # # # # # # # #( # # # # #r2   