
    qh+                    n   S r SSKrSSKrSSKJrJrJr  SSKJr  SSK	J
r
JrJrJrJrJr  SSKJrJrJrJrJrJrJr  SSKJr  SSKJr  SS	KJrJrJr  SS
KJr  SSK J!r!J"r#  SSK$J%r%  SSKJ&r&  / SQr'\RP                  " \)5      r*S r+S r, " S S\-5      r. " S S\-5      r/ " S S\/5      r0 " S S\-5      r1 " S S\25      r3 " S S\45      r5 " S S\55      r6 " S S \25      r7 " S! S"\-5      r8 " S# S$\-5      r9S%r:S&r;S'r<S(r= " S) S*\-5      r> " S+ S,\>5      r? " S- S.\>5      r@ " S/ S0\>5      rA " S1 S2\>5      rBg)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                  " XR                  5       S9n[        X!5      $ )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      J/var/www/html/env/lib/python3.13/site-packages/openid/consumer/consumer.py
makeKVPostr1      s(     >>*+G+G+IJD "$33    c                     [         R                  " U R                  5      nU R                  S:X  a  [        R                  U5      eU R                  S;  a(  SnX1U R                  4-  n[        R                  " U5      eU$ )aY  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,      sp     ))(--8#%%&677	
	*28??;;((77r2   c                   Z    \ rS rSrSrSrSr\" \5      r	SS jr
SS jrSS jrS	 rS
 rSrg)r   i
  aW  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                 x    Xl         Uc  [        nU" U5      U l        U R                  U R                  -   U l        g)a   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__Consumer.__init__!  s6    $ !,N&u-11DKK?r2   c                 .   [        U R                  XR                  5      n UR                  U R                  5      nUc  [        SU< 3S5      eU R                  XB5      $ ! [
        R                   a  n[        SUR                  < 3S5      eSnAff = f)a  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servicerQ   s         r0   beginConsumer.begin9  s    H $,,2I2IJ	6**4>>:G
 ?"$,$0157 7 --gAA )) 	6"$'GG$/046 6	6s   A! !B5BBc                     U R                   R                  U5      nUR                  U R                  U R                  '    UR                  U5        U$ ! [         a  n[        [        U5      5      eSnAff = f)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   rW   endpointrC   rH   setAnonymous
ValueErrorProtocolErrorstr)rI   rV   rT   auth_reqrQ   s        r0   rR   Consumer.beginWithoutDiscoveryj  sk    * ==&&w/(0(9(9T__%	*!!),   	*C))	*s    A 
A6A11A6c                    U R                   R                  U R                  5      n[        R                  " U5      nU R
                  R                  XCU5      n U R                   U R                  	 UR                  S;   aG  UR                  b:  [        U R                   UR                  U R                  5      nUR                  SS9  U$ ! [         a     Nef = f)a  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cancelT)force)rC   getrH   r   fromPostArgsrE   completeKeyErrorr7   identity_urlr   rF   cleanup)rI   querycurrent_urlrZ   messager;   rU   s          r0   rg   Consumer.complete  s    2 <<##DOO4&&u-==))'[I	T__- OO44%%1dllH,A,A"557E MMM%  		s   C	 	
CCc                 8    [        U5      U R                  l        g)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   setAssociationPreference!Consumer.setAssociationPreference  s    ( $55L#M r2   )rH   rE   rC   N)F)__name__
__module____qualname____firstlineno____doc__rF   rG   staticmethodr   rP   rL   rW   rR   rg   rr   __static_attributes__ r2   r0   r   r   
  s<      -FX&I@0/Bb>,\Nr2   r   c                   \    \ rS rSrSr\" \R                  5      rSr	S/r
S
S jrS rS rS	rg) DiffieHellmanSHA1ConsumerSessioni  DH-SHA1   	HMAC-SHA1Nc                 @    Uc  [         R                  " 5       nXl        g rt   )r   fromDefaultsdh)rI   r   s     r0   rL   )DiffieHellmanSHA1ConsumerSession.__init__  s    :++-Br2   c                 h   [         R                  " U R                  R                  5      nSU0nU R                  R	                  5       (       dd  UR                  [         R                  " U R                  R                  5      [         R                  " U R                  R                  5      S.5        U$ )Ndh_consumer_public)
dh_modulusdh_gen)r   longToBase64r   publicusingDefaultValuesupdatemodulus	generator)rI   cpubargss      r0   
getRequest+DiffieHellmanSHA1ConsumerSession.getRequest  s}    %%dggnn5$d+ww))++KK'44TWW__E#001B1BC 
 r2   c                    UR                  [        S[        5      nUR                  [        S[        5      n[        R                  " U5      n[
        R                  " U5      nU R                  R                  XEU R                  5      $ )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   extractSecret.DiffieHellmanSHA1ConsumerSession.extractSecret  si    %__Y8J-79 	=*M$112DE((7ww  !1OOr2   )r   rt   )ru   rv   rw   rx   session_typerz   r   sha1r   secret_sizeallowed_assoc_typesrL   r   r   r{   r|   r2   r0   r~   r~     s2    LY^^,IK&-Pr2   r~   c                   F    \ rS rSrSr\" \R                  5      rSr	S/r
Srg)"DiffieHellmanSHA256ConsumerSessioni  	DH-SHA256    HMAC-SHA256r|   N)ru   rv   rw   rx   r   rz   r   sha256r   r   r   r{   r|   r2   r0   r   r     s$    LY--.IK(/r2   r   c                   ,    \ rS rSrSrSS/rS rS rSrg)	PlainTextConsumerSessioni  no-encryptionr   r   c                     0 $ rt   r|   rI   s    r0   r   #PlainTextConsumerSession.getRequest  s    	r2   c                 d    UR                  [        S[        5      n[        R                  " U5      $ )Nmac_key)r   r   r   r   r   )rI   r;   	mac_key64s      r0   r   &PlainTextConsumerSession.extractSecret  s%    OOIy*E	!!),,r2   r|   N)	ru   rv   rw   rx   r   r   r   r   r{   r|   r2   r0   r   r     s    "L&6-r2   r   c                   "    \ rS rSrSrSS jrSrg)SetupNeededErrori  zRInternally-used exception that indicates that an immediate-mode
request cancelled.Nc                 :    [         R                  X5        Xl        g rt   )	ExceptionrL   user_setup_url)rI   r   s     r0   rL   SetupNeededError.__init__  s    40,r2   )r   rt   )ru   rv   rw   rx   ry   rL   r{   r|   r2   r0   r   r     s    -r2   r   c                       \ rS rSrSrSrg)r]   i  zoException that indicates that a message violated the
protocol. It is raised and caught internally to this file.r|   N)ru   rv   rw   rx   ry   r{   r|   r2   r0   r]   r]     s    Br2   r]   c                   $    \ rS rSrSrS rS rSrg)TypeURIMismatchi  z8A protocol error arising from type URIs mismatching
    c                 H    [         R                  XU5        Xl        X l        g rt   )r]   rL   expectedrZ   )rI   r   rZ   s      r0   rL   TypeURIMismatch.__init__  s    tx8  r2   c                     SU R                   R                  < SU R                   R                  < SU R                  < SU R                  R
                  < SU R                  < S3nU$ )N<.z: Required type z not found in z for endpoint >)	__class__rv   ru   r   rZ   	type_uris)rI   ss     r0   __str__TypeURIMismatch.__str__  sB    NN%%t~~'>'>MM##T]]4 r2   )rZ   r   N)ru   rv   rw   rx   ry   rL   r   r{   r|   r2   r0   r   r     s    !
r2   r   c                   4    \ rS rSrSrS rS r\" \5      rSrg)r8   i!  zYException that is raised when the server returns a 400 response
code to a direct request.c                 R    [         R                  X5        Xl        X l        X0l        g rt   )r   rL   
error_text
error_coderm   )rI   r   r   rm   s       r0   rL   ServerError.__init__%  s    4,$$r2   c                 n    UR                  [        SS5      nUR                  [        S5      nU " X#U5      $ )z_Generate a ServerError instance, extracting the error text
and the error code from the message.errorz<no error message supplied>r   )r   r   )clsrm   r   r   s       r0   r9   ServerError.fromMessage+  s7     ^^Iw$AC
^^I|<
:733r2   )r   r   rm   N)	ru   rv   rw   rx   ry   rL   r9   classmethodr{   r|   r2   r0   r8   r8   !  s    !4 k*Kr2   r8   c                       \ rS rSrSrSrSr\\\	S.r
\" \5      rS rS rS rS	 rS
 rS rS rS rS r\" \5      rS rS rS rS rS rS rS r\" \5      rS(S jr S r!S r"S r#S r$S r%S r&S r'S r(S  r)S! r*S" r+S# r,S$ r-S% r.S& r/S'r0g))rD   i6  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)r   r   r   c                 D    Xl         [        R                  " 5       U l        g rt   )rJ   r   copyrp   )rI   rJ   s     r0   rL   GenericConsumer.__init__X  s    
,113r2   c                 8   U R                   c  SnOU R                  U5      n[        X5      n[        5       UR                  U R
                  '   UR                  R                  5       (       a-  UR                  R                  UR                  U R                  '   U$ )zuCreate 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_namerm   	isOpenID1rZ   
claimed_id!openid1_return_to_identifier_name)rI   service_endpointassocrequests       r0   rW   GenericConsumer.begin\  s     ::E(()9:E.6DKIt@@A??$$&&  ++ ""4#I#IJ r2   c                 v    UR                  [        SS5      n[        U SU-   U R                  5      nU" XU5      $ )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   rm   rZ   	return_tor   
modeMethods         r0   rg   GenericConsumer.completen  s<    
 ~~iAT<$#68M8MN
'Y77r2   c                     [        U5      $ rt   )r"   )rI   rm   rZ   _s       r0   _complete_cancel GenericConsumer._complete_cancely  s    h''r2   c                     UR                  [        S5      nUR                  [        S5      nUR                  [        S5      n[        X$XVS9$ )Nr   contact	reference)r   r   r   r   r#   )rI   rm   rZ   r   r   r   r   s          r0   _complete_errorGenericConsumer._complete_error|  sF    y'2..I6NN9k:	WC 	Cr2   c                     UR                  5       (       d  U R                  XU5      $ UR                  [        S5      n[	        X$5      $ )Nr   )	isOpenID2r   r   r   r!   )rI   rm   rZ   r   r   s        r0   _complete_setup_needed&GenericConsumer._complete_setup_needed  s@      ""((A>> 
4DE"8<<r2   c                      U R                  U5         U R                  XU5      $ ! [        [        4 a  n[	        X$5      s S nA$ S nAff = f! [
         a  n[        X$R                  5      s S nA$ S nAff = frt   )_checkSetupNeeded_doIdResr]   r	   r#   r   r!   r   )rI   rm   rZ   r   rQ   s        r0   _complete_id_res GenericConsumer._complete_id_res  sp    	6""7+6}}W	BB!#34 6&x556   	E&x1C1CDD	Es7   A & A
A AA
A7A2,A72A7c                 P    UR                  [        SS5      n[        USU< 35      $ )Nr   r   zInvalid openid.mode: r   )rI   rm   rZ   r   r   s        r0   r    GenericConsumer._completeInvalid  s$    ~~iAxd)MNNr2   c                     U R                  UR                  5       5        UR                  [        S5      n[        [        R                  " U5      5      n[        [        R                  " U5      5      n[        SS5       H  nXW   Xg   :w  d  M    g   g! [         a#  n[        R	                  SU< 35         SnAgSnAff = f)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   rm   r   rQ   msg_return_to	app_parts	msg_partsparts           r0   _checkReturnToGenericConsumer._checkReturnTo  s    	$$W%7%7%9:  y+> W__Y78	W__];<	 !QKD)/1   %  	CJK	s   B 
CB==Cc                 x    UR                  5       (       a%  UR                  [        S5      nUb  [        U5      egg)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   rm   r   s      r0   r   !GenericConsumer._checkSetupNeeded  s?     $^^J8HIN)&~66 * r2   c           	      2   U R                  U5        U R                  X5      (       d'  [        SU< SUR                  [        S5      < 35      eU R                  X5      n[        R                  SUR                  < SUR                  [        S5      < 35        U R                  XR                  5        U R                  X5        UR                  [        S[        5      nUR                  S5      nU Vs/ s H  nS	U-   PM
     nn[        X!U5      $ s  snf )
ag  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,zopenid.)_idResCheckForFieldsr  r]   r   r   _verifyDiscoveryResultsr  infor.   _idResCheckSignature_idResCheckNoncer   r   r    )rI   rm   rZ   r   signed_list_strsigned_listr   signed_fieldss           r0   r   GenericConsumer._doIdRes  s    * 	!!'*""766GNN9kBDE E
 //B))nnY?A 	B 	!!'+>+>? 	g0!..HjI%++C00;<1Q<x-@@ =s   7Dc                 B    UR                  [        U R                  5      $ )a  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   rm   rZ   s      r0   _idResGetNonceOpenID1%GenericConsumer._idResGetNonceOpenID1  s     ~~gt'H'HIIr2   c                    UR                  5       (       a  U R                  X5      nSnO"UR                  [        S5      nUR                  nUc  [        S5      e [        U5      u  pVU R                  b-  U R                  R                  XEU5      (       d  [        S5      eg g ! [         a  n[        SU< 35      eS nAff = f)N response_noncezNonce missing from responsezMalformed nonce: z"Nonce already used or out of range)
r   r   r   r   r.   r]   
splitNoncer\   rJ   useNonce)rI   rm   rZ   noncer.   	timestampsaltrQ   s           r0   r   GenericConsumer._idResCheckNonce  s    ..wAEJNN:/?@E!,,J= =>>	A(/OI JJ"JJ''
tDD DEE E #  	A ?@@	As   B# #
C-B<<Cc                 Z   UR                  [        S5      nU R                  c  S nOU R                  R                  X#5      nU(       aB  UR                  S::  a  [        SU< S35      eUR                  U5      (       d  [        S5      eg U R                  X5      (       d  [        S5      eg )Nr  r   zAssociation with z expiredzBad signaturez"Server denied check_authentication)r   r   rJ   getAssociation	expiresInr]   checkMessageSignature
_checkAuth)rI   rm   r.   r  r   s        r0   r  $GenericConsumer._idResCheckSignature  s    ~~i@::EJJ--jGE!# $%/%3 4 4 ..w77#O44 8 ??777#$HII 8r2   c                    / SQnSS/n[         US/-   [        US/-   0n[         U/ SQ-   [        U0nXAR                  5           H-  nUR                  [        U5      (       a  M   [        SU< 35      e   UR                  [        S[        5      nUR                  S5      nXQR                  5           H5  nUR                  [        U5      (       d  M   Xh;  d  M'  [        S	U< S
35      e   g )N)r   r  sigr  r   identityop_endpoint)r$  r   r  r4  zMissing required field r  r  "z" not signed)	r   r   getOpenIDNamespacehasKeyr   r]   r   r   r   )	rI   rm   basic_fieldsbasic_sig_fieldsrequire_fieldsrequire_sigsfieldr  r  s	            r0   r  $GenericConsumer._idResCheckForFields0  s     F'4 6
|3
 KL
 $$>$>$@AE>>)U33#5$KLL B "..HjI%++C0!"<"<">?E~~i//E4L#$ABB @r2   c                    [         R                  " U 5      nUR                  [        S5      nUc  [	        S5      e[        U5      nUS   n[        U5      nU H   u  pg X   nXx:w  a  Sn	[	        XX4-  5      eM"     UR                  [        5      n
U
R                  5        H  nX;  d  M
  [	        SUS   < S	35      e   g! [         a    Sn	[	        XU 4-  5      ef = f)
zMVerify 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   rf   r   r   r]   r   r   rh   getArgsr   items)rk   rm   r   
parsed_urlrt_queryparsed_argsrt_keyrt_valuevalueformat	bare_argspairs               r0   r  #GenericConsumer._verifyReturnToArgsS  s     &&u-NN9k:	 ;<<i(
a=)
 !,F>$5F'%1J(JKK % !, OOG,	OO%D&#%)!W%0 1 1 &  >F#Fe_$<==>s   CCNc                 v    UR                  5       [        :X  a  U R                  X5      $ U R                  X5      $ )z
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
)r6  r   _verifyDiscoveryResultsOpenID2_verifyDiscoveryResultsOpenID1)rI   resp_msgrZ   s      r0   r  'GenericConsumer._verifyDiscoveryResults{  s7     &&(J666xJJ66xJJr2   c                 J   [        5       n[        /Ul        UR                  [        S5      Ul        UR                  [        S5      Ul        UR                  [        S[        5      Ul        UR
                  c  UR                  b  [        S5      eUR
                  b  UR                  c  [        S5      eUR
                  c   [         R                  " UR                  5      $ U(       d3  [        R                  S5        U R                  UR
                  U/5      nOZUR                  5       (       a3  [        R                  S5        U R                  UR
                  U/5      nO U R                  X#5        UR
                  UR
                  :w  a'  [$        R$                  " U5      nUR
                  Ul        U$ ! [         a]  n[        R!                  S[#        U5      -   5        [        R                  S	5        U R                  UR
                  U/5      n S nANS nAff = f)
Nr   r3  r4  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   rO  rZ   to_matches        r0   rM  .GenericConsumer._verifyDiscoveryResultsOpenID2  s   (*-.&ooj,G$OOJ
C 'ooj-.8:
 'H,=,=,IFH H !!-(2C2C2KFH H   ((::8;N;NOO KKAB..x/B/BXJOH$$&&KKP ..x/B/BXJOH
?++H? ("5"55yy*H"*"5"5H ! ?  LF EF2283F3F4<:??s   'F; ;
H"AHH"c                    UR                  [        U R                  5      nUc  Uc  [        S5      eUb  Uc  UR                  n[        5       n[        /Ul        UR                  [        S5      Ul	        X4l        UR                  c  [        S5      e[        R                  " U5      n[        /Ul        Ub    U R                  X$5        U$ U R'                  X4U/5      $ ! [         a    U R                  X%5         U$ f = f! [         a@  n[        R!                  S[#        U5      -   5        [        R%                  S5         S nANzS nAff = f)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()r3  z&Missing required field openid.identityrR  rS  )r   r   r   RuntimeErrorr   r   r   r   r   rT  r]   r   r
   rX  r   r  r  r^   r  rV  )rI   rO  rZ   r   rY  to_match_1_0rZ  s          r0   rN  .GenericConsumer._verifyDiscoveryResultsOpenID1  sV   __W%)%K%KM
 
 201 1
 !j&8!,,J(*-.$OOJ
C($ HIIyy*"1!2 H//C   &&zl3KLL ' H//G  H  G  LF EFF	Gs0   :C   C?;D >C??D 
E6EEc                 p   UR                    H$  nUR                  U5      (       a  M  [        X15      e   [        UR                  5      u  pEXAR                  :w  a  [        SU< SUR                  < 35      eUR                  5       UR                  5       :w  a/  [        SUR                  5       < SUR                  5       < 35      eUR                  c   UR                  5       [        :X  d   S5       egUR                  UR                  :w  a'  [        SUR                  < SUR                  < 35      eg)au  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   rZ   rY  type_uridefragged_claimed_idr   s         r0   rX  &GenericConsumer._verifyDiscoverySingle  s+    !**H))(33%h99 + #,H,?,?"@#6#66 &x':':<= =
  H$7$7$99!)!4!4!68K8K8M!O P P &..0J> )()>   H$7$77!)!4!4h6I6I!K L L 8r2   c                     [         R                  SU< 35        U R                  U5      u  p4U(       d  [        SU< 3S5      eU R	                  XU5      $ )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  rP   r	   _verifyDiscoveredServices)rI   r   to_match_endpointsr   servicess        r0   rV  "GenericConsumer._discoverAndVerify  sX     	JABnnZ0"$.$2379 9--j.@B 	Br2   c                 N   / nU H"  nU H  n U R                  XV5        Us  s  $    M$     [        R                  SU< 35        U H  n[        R                  SU-   5        M     [        SU< 3S5      e! [         a%  nUR                  [        U5      5         SnAM  SnAff = f)zSee @L{_discoverAndVerify}Nz#Discovery verification failure for z * Endpoint mismatch: z-No matching endpoint found after discovering )rX  r]   appendr^   r  r   r	   )	rI   r   rj  ri  failure_messagesrZ   to_match_endpointrQ   failure_messages	            r0   rh  )GenericConsumer._verifyDiscoveredServices6  s      H%7!$//L $O &8 ! LL%) *#35GH $4 # $& & % 6$++CH556s   A55
B$?BB$c                 8   [         R                  S5        U R                  U5      nUc  g U R                  X25      nU R	                  XB5      $ ! [
        R                  [        4 a1  nUR                  S   n[         R                  SU-  5         SnAgSnAff = f)zrMake 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   rm   r.   r   r;   rZ  e0s          r0   r/  GenericConsumer._checkAuthQ  s     	78..w7?	H''<H 11(GG **K8 	B>CD	s   A B('BBc                    UR                  [        S5      nU(       a{  [        U[        5      (       a
  [	        USS9nUR                  S5       HG  n[        R                  U5        UR                  U5      nUb  M.  [        R                  SU< 35          g   UR                  5       nUR                  [        SS5        U$ )	zIGenerate 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   rm   r  kvalcheck_auth_messages         r0   rs  'GenericConsumer._createCheckAuthRequestd  s     	84&%((Vg6\\#&A++A. ;KKQ AB ' %\\^!!)V5KL!!r2   c                 J   UR                  [        SS5      nUR                  [        S5      nUbW  [        R                  SU< 35        U R                  c  [        R                  S5        OU R                  R                  X$5        US:X  a  g[        R                  S5        g	)
zjProcess the response message from a check_authentication
request, invalidating associations if requested.
is_validfalseinvalidate_handlez)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   ru  )GenericConsumer._processCheckAuthResponsey  s     ??9j'B$OOI7JK(KK$( )zz! ) * 

,,ZKvLLKLr2   c                     U R                   R                  UR                  5      nUb  UR                  S::  a:  U R	                  U5      nUb&  U R                   R                  UR                  U5        U$ )ai  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
r   )rJ   r,  r.   r-  _negotiateAssociationstoreAssociationrI   rZ   r   s      r0   r   GenericConsumer._getAssociation  sc     

))(*=*=>=EOOq0..x8E 

++H,?,?Gr2   c           
         U R                   R                  5       u  p# U R                  XU5      nU$ ! [         a  nU R	                  XQU5      nUbd  Uu  p# U R                  XU5      nUs SnA$ ! [         a9  n[
        R                  SUR                  < SU< SU< 35         SnA SnAgSnAff = f SnAgSnAff = f)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=)rp   getAllowedType_requestAssociationr8    _extractSupportedAssociationTyper  r   r.   )rI   rZ   
assoc_typer   r   rQ   supportedTypess          r0   r  %GenericConsumer._negotiateAssociation  s     $(??#A#A#C 
	,,X-9;E0 L-  	!!BBz+N)+9(
! 44X5ACE !L #   LL %//zKL  4  *	!sD   2 
B?B:A/(B:)B?/
B29+B-$B:-B22B::B?c                 H   UR                   S:w  d  UR                  R                  5       (       a2  [        R	                  SUR
                  < SUR                  < 35        g[        R	                  SU< SUR                  < 35        UR                  R                  [        S5      nUR                  R                  [        S5      nUb  Uc  [        R	                  S5        gU R                  R                  X45      (       d  S	n[        R	                  XTU4-  5        gX44$ )
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 r  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   rm   r   r  r   r.   r   r   r   rp   	isAllowed)rI   server_errorrZ   r  r   r=   s         r0   r  0GenericConsumer._extractSupportedAssociationType  s     ""&88##--//LL$$l&=&=?@ 
 	!<#:#:> 	?
 "))00LI
#++229nM!5LL C D**:DD4CLLj99:++r2   c                    U R                  XU5      u  pE U R                  XQR                  5      n U R                  Xd5      nU$ ! [        R                   a#  n[
        R                  SU< 35         SnAgSnAff = f! [         a1  n[
        R                  SUR                  < SU< 35         SnAgSnAf[         a1  n[
        R                  SUR                  < SU< 35         SnAgSnAff = f)zMake 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 r  z%Protocol error parsing response from )
_createAssociateRequestrt  r.   r   r:   r  r  _extractAssociationrh   r]   )	rI   rZ   r  r   assoc_sessionr   r;   rQ   r   s	            r0   r  #GenericConsumer._requestAssociation  s     #::,0	''.A.ABH
	,,XEE L! )) 	cLM	  	$$c+,  	'22C9 :	s:   A A? A<A77A<?
C3	'B55C3'C..C3c                 L   U R                   U   nU" 5       nSUS.nUR                  5       (       d	  [        US'   UR                  5       (       a  UR                  S:w  a  UR                  US'   UR	                  UR                  5       5        [        R                  " U5      nXW4$ )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   r  nsr   r   )session_typescompatibilityModer   r   r   r   r   fromOpenIDArgs)rI   rZ   r  r   session_type_classr  r   rm   s           r0   r  'GenericConsumer._createAssociateRequest  s    0 "//=*,  $

 ))++#DJ **,,**o=#0#=#=D M,,./((.%%r2   c                     UR                  [        S5      nUS:X  a  [        R                  S5        U$ US:X  d  Uc  SnU$ )ak  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   _getOpenID1SessionType&GenericConsumer._getOpenID1SessionType@  sS    " &,,ZH ?*NN - .  R<#7*Lr2   c                 *   UR                  [        S[        5      nUR                  [        S[        5      nUR                  [        S[        5      n [        U5      nUR                  5       (       a  U R                  U5      nOUR                  [        S[        5      nUR                  U:w  aC  UR                  5       (       a  US:X  a  [        5       nOSn	XR                  U4-  n
[        U
5      eX2R                  ;  a  S	n	[        XR                  U4-  5      e UR                  U5      n[        R                  " XdUU5      $ ! [         a  n[        SU< 35      eSnAff = f! [         a   nS
n	[        XR                  U4-  5      eSnAff = f)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
r  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   intr\   r]   r   r  r   r   r   r   r   r   fromExpiresIn)rI   r  r  r  r  expires_in_strr  rQ   r   r=   rm   secrets               r0   r  #GenericConsumer._extractAssociationf  s   ( $**9lJO
%,,Y-79 (..y,/9;	J^,J
 ##%%66~FL)00^1;=L %%5((** O3 !9 :
 C!;!;\ JJ#G,, >>>FC'A'A:&N NOO
	I"00@F
 ((6)35 	5U  	J# HII	JL  	I9C'A'A3&G GHH	Is0   E E( 
E%E  E%(
F2FF)rp   rJ   rt   )1ru   rv   rw   rx   ry   r   r   r~   r   r   r  rz   r   rP   rL   rW   rg   r   r   r   r   r   r  r1   rt  r   r   r   r  r  r  r  r  rM  rN  rX  rV  rh  r/  rs  ru  r   r  r  r  r  r  r  r{   r|   r2   r0   rD   rD   6  s   
$ $3 
 )=% 471M X&I4$	8(C=	6O: z*K7*AX
JF*J8!CF$1L '':;K9v(MT.L`B.&6H&"*,*$L',R@+&Z$LK5r2   rD   c                   j    \ rS rSrSrS rS rS rS rSS jr	SS	 jr
   SS
 jr   SS jrS rSrg)r   i  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                 t    X l         Xl        0 U l        [        UR	                  5       5      U l        SU l        g)z
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   rZ   r   r   rc  rm   
_anonymousr  s      r0   rL   AuthRequest.__init__  s2     
  x::<=r2   c                 r    U(       a*  U R                   R                  5       (       a  [        S5      eXl        g)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)rm   r   r\   r  )rI   is_anonymouss     r0   r[   AuthRequest.setAnonymous  s2     DLL2244 9 : : +Or2   c                 :    UR                  U R                  5        g)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)	toMessagerm   )rI   extension_requests     r0   addExtensionAuthRequest.addExtension  s     	##DLL1r2   c                 <    U R                   R                  XU5        g)ai  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)rm   r~  )rI   	namespacekeyrG  s       r0   addExtensionArgAuthRequest.addExtensionArg  s    2 	IE2r2   Nc           	      .   U(       a!  [         R                  " X R                  5      nOXU(       a  [        S5      eU R                  R                  5       (       a  [        S5      eU R                  (       a  [        S5      eU(       a  SnOSnU R                  R                  5       nUR                  5       (       a  SnOSnUR                  [        XaSUS	U05        U R                  (       d  U R                  R                  5       (       a  [        =pxO0U R                  R                  5       nU R                  R                  nUR                  [        S
U5        UR!                  5       (       a  UR                  ["        SU5        U R$                  (       aF  UR                  [        SU R$                  R&                  5        SU R$                  R&                  < 3n	OSn	[(        R+                  SU< SU R                  R,                  < SU	< 35        U$ )a  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   r3  r   r  zwith association zusing stateless mode.z
Generated z request to  )r   
appendArgsr   r\   rm   r   r   
updateArgsr   r  rZ   rW  r   rb  r   r~  r   r   r   handler  r  r.   )
rI   r  r   	immediater   rm   	realm_keyr   request_identityassoc_log_msgs
             r0   
getMessageAuthRequest.getMessage  s   : **96I6IJIIK K\\##%%MNN   > ? ? &D"D,,##%$II9D'
 	 }}++-- 1BA
-#'==#;#;#= !]]55
 NN9j2BC  ""z<D::NN9ndjj6G6GH59ZZ5F5FIM3MDMM44mE 	F r2   c                 p    U R                  XU5      nUR                  U R                  R                  5      $ )a  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  toURLrZ   r.   )rI   r  r   r  rm   s        r0   redirectURLAuthRequest.redirectURLY  s.    L //%I>}}T]]5566r2   c                 r    U R                  XU5      nUR                  U R                  R                  U5      $ )aE  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  toFormMarkuprZ   r.   )rI   r  r   r  form_tag_attrsrm   s         r0   
formMarkupAuthRequest.formMarkup  s1     //%I>##DMM$<$<nMMr2   c                 N    [         R                  " U R                  XX45      5      $ )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   
htmlMarkupAuthRequest.htmlMarkup  s'     %%OOEiHJ 	Jr2   c                 6    U R                   R                  5       $ )zsShould this OpenID authentication request be sent as a HTTP
redirect or as a POST (form submission)?

@rtype: bool
)rZ   r  r   s    r0   shouldSendRedirectAuthRequest.shouldSendRedirect  s     }}..00r2   )r  r   rZ   rm   r   )NF)NFN)ru   rv   rw   rx   ry   rL   r[   r  r  r  r  r  r  r  r{   r|   r2   r0   r   r     sO    	 +$236Rh'7V """&	N$ """&	J1r2   r   failurerb   rc   setup_neededc                   $    \ rS rSrSrS rS rSrg)Responsei  Nc                 H    Xl         Uc  S U l        g UR                  U l        g rt   )rZ   ri   r   rI   rZ   s     r0   setEndpointResponse.setEndpoint  s#      $D ( 3 3Dr2   c                 R    U R                   b  U R                   R                  5       $ g)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)rZ   getDisplayIdentifierr   s    r0   r  Response.getDisplayIdentifier  s$      ==$==5577r2   )rZ   ri   )ru   rv   rw   rx   r7   r  r  r{   r|   r2   r0   r  r    s    F4r2   r  c                   `    \ rS rSrSr\rSS jrS rS r	SS jr
S rS	 rS
 rS rS rS rSrg)r    i  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                 T    Xl         UR                  U l        X l        Uc  / nX0l        g rt   )rZ   r   ri   rm   r  )rI   rZ   rm   r  s       r0   rL   SuccessResponse.__init__  s-     !$// M*r2   c                 6    U R                   R                  5       $ )zFWas this authentication response an OpenID 1 authentication
response?
)rm   r   r   s    r0   r   SuccessResponse.isOpenID1  s     ||%%''r2   c                 R    U R                   R                  X5      U R                  ;   $ )zMReturn whether a particular key is signed, regardless of
its namespace alias
)rm   getKeyr  )rI   ns_urins_keys      r0   isSignedSuccessResponse.isSigned  s$     ||""62d6H6HHHr2   c                 j    U R                  X5      (       a  U R                  R                  XU5      $ U$ )zIReturn the specified signed field if available,
otherwise return default
)r  rm   r   )rI   r  r  defaults       r0   	getSignedSuccessResponse.getSigned  s/     ==((<<&&vw??Nr2   c                     U R                   R                  U5      nUR                  5        H9  nU R                  X5      (       a  M  [        R                  SU< SU< S35          g   U$ )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)rm   r@  keysr  r  r  )rI   r  msg_argsr  s       r0   getSignedNSSuccessResponse.getSignedNS  sY    
 <<''/==?C==--S"#  # r2   c                 h    U(       a  U R                  U5      $ U R                  R                  U5      $ )a?  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  rm   r@  )rI   namespace_urirequire_signeds      r0   extensionResponse!SuccessResponse.extensionResponse  s-     ##M22<<''66r2   c                 .    U R                  [        S5      $ )a8  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   getReturnToSuccessResponse.getReturnTo(  s     ~~i55r2   c                 4   U R                   UR                   :H  =(       ay    U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ rt   )rZ   ri   rm   r  r7   rI   others     r0   __eq__SuccessResponse.__eq__6  sw    %..0 .""e&8&88... ##u':'::. ,		/r2   c                     X:X  + $ rt   r|   r  s     r0   __ne__SuccessResponse.__ne__=  s    ""r2   c           	          SU R                   R                  < SU R                   R                  < SU R                  < SU R                  < S3	$ )Nr   r    id=z signed=r   )r   rv   ru   ri   r  r   s    r0   __repr__SuccessResponse.__repr__@  s6    NN%%t~~'>'>t113 	3r2   )rZ   ri   rm   r  rt   )ru   rv   rw   rx   ry   r$   r7   rL   r   r  r  r  r  r	  r  r  r  r{   r|   r2   r0   r    r      sA    ( F
+(I 7"6/#3r2   r    c                   ,    \ rS rSrSr\rSS jrS rSr	g)r#   iF  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                 J    U R                  U5        X l        X0l        X@l        g rt   )r  rm   r   r   )rI   rZ   rm   r   r   s        r0   rL   FailureResponse.__init__U  s    ""r2   c           	          SU R                   R                  < SU R                   R                  < SU R                  < SU R                  < S3	$ )Nr   r   r  z	 message=r   )r   rv   ru   ri   rm   r   s    r0   r  FailureResponse.__repr__[  s7    -1^^-F-F-1^^-D-D-1->->N 	Nr2   )r   rm   r   )NNN)
ru   rv   rw   rx   ry   r%   r7   rL   r  r{   r|   r2   r0   r#   r#   F  s    
 F#Nr2   r#   c                   "    \ rS rSrSr\rS rSrg)r"   ia  zA 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                 &    U R                  U5        g rt   )r  r  s     r0   rL   CancelResponse.__init__m  s    "r2   r|   N)	ru   rv   rw   rx   ry   r&   r7   rL   r{   r|   r2   r0   r"   r"   a  s     F#r2   r"   c                   &    \ rS rSrSr\rSS jrSrg)r!   iq  a  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                 2    U R                  U5        X l        g rt   )r  	setup_url)rI   rZ   r!  s      r0   rL   SetupNeededResponse.__init__  s    ""r2   )r!  rt   )	ru   rv   rw   rx   ry   r'   r7   rL   r{   r|   r2   r0   r!   r!   q  s     F#r2   r!   )Cry   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__	getLoggerru   r  r1   r,   objectr   r~   r   r   r   r   r\   r]   r   r8   rD   r   r%   r$   r&   r'   r  r    r#   r"   r!   r|   r2   r0   <module>r/     sW  zx   7 7 I I, , ,    # ; *  
		8	$4 4ANv ANHPv PD*)I *	-v 	--y -BJ B
m  +) +*{5f {5|s1& s1l 
	v >t3h t3nNh N6#X # #( #r2   