o
    gëfr$  ã                   @   sj   d Z g d¢ZddlmZ ddlZdZdZdZdZe 	d	¡Z
G d
d„ deƒZee_G dd„ deƒZee_dS )z‡An implementation of the OpenID Provider Authentication Policy
Extension 1.0

@see: http://openid.net/developers/specs/

@since: 2.1.0
)ÚRequestÚResponseÚns_uriÚAUTH_PHISHING_RESISTANTÚAUTH_MULTI_FACTORÚAUTH_MULTI_FACTOR_PHYSICALé    )Ú	ExtensionNz+http://specs.openid.net/extensions/pape/1.0zEhttp://schemas.openid.net/pape/policies/2007/06/multi-factor-physicalz<http://schemas.openid.net/pape/policies/2007/06/multi-factorzBhttp://schemas.openid.net/pape/policies/2007/06/phishing-resistantz$^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$c                       s^   e Zd ZdZdZd‡ fdd„	Zdd„ Zdd	„ Zd
d„ Zdd„ Z	e
e	ƒZ	dd„ Zdd„ Z‡  ZS )r   a´  A Provider Authentication Policy request, sent from a relying
    party to a provider

    @ivar preferred_auth_policies: The authentication policies that
        the relying party prefers
    @type preferred_auth_policies: [str]

    @ivar max_auth_age: The maximum time, in seconds, that the relying
        party wants to allow to have elapsed before the user must
        re-authenticate
    @type max_auth_age: int or NoneType
    ÚpapeNc                    s&   t t| ƒ ¡  |sg }|| _|| _d S ©N)Úsuperr   Ú__init__Úpreferred_auth_policiesÚmax_auth_age)Úselfr   r   ©Ú	__class__© ú^/var/www/html/humari/django-venv/lib/python3.10/site-packages/openid/extensions/draft/pape2.pyr   0   s
   
zRequest.__init__c                 C   s   t | jp| jd uƒS r
   )Úboolr   r   )r   r   r   r   Ú__nonzero__8   s   ÿzRequest.__nonzero__c                 C   ó   || j vr| j  |¡ dS dS )a•  Add an acceptable authentication policy URI to this request

        This method is intended to be used by the relying party to add
        acceptable authentication types to the request.

        @param policy_uri: The identifier for the preferred type of
            authentication.
        @see: http://openid.net/specs/openid-provider-authentication-policy-extension-1_0-01.html#auth_policies
        N)r   Úappend©r   Ú
policy_urir   r   r   ÚaddPolicyURI<   ó   

ÿzRequest.addPolicyURIc                 C   s,   dd  | j¡i}| jdurt| jƒ|d< |S )ú/@see: C{L{Extension.getExtensionArgs}}
        r   ú Nr   )Újoinr   r   Ústr©r   Úns_argsr   r   r   ÚgetExtensionArgsI   s
   ÿ
zRequest.getExtensionArgsc                 C   s.   | ƒ }|j  |j¡}|i krdS | |¡ |S )zaInstantiate a Request object from the arguments in a
        C{checkid_*} OpenID message
        N)ÚmessageÚgetArgsr   ÚparseExtensionArgs)ÚclsÚrequestr   Úargsr   r   r   ÚfromOpenIDRequestU   s   
zRequest.fromOpenIDRequestc                 C   sx   g | _ | d¡}|r| d¡D ]}|| j vr| j  |¡ q| d¡}d| _|r:zt|ƒ| _W dS  ty9   Y dS w dS )a  Set the state of this request to be that expressed in these
        PAPE arguments

        @param args: The PAPE arguments without a namespace

        @rtype: None

        @raises ValueError: When the max_auth_age is not parseable as
            an integer
        r   r   r   N)r   ÚgetÚsplitr   r   ÚintÚ
ValueError)r   r(   Úpolicies_strÚuriÚmax_auth_age_strr   r   r   r%   d   s    

€
ÿýzRequest.parseExtensionArgsc                 C   s   t | jj|ƒS )aŸ  Given a list of authentication policy URIs that a provider
        supports, this method returns the subsequence of those types
        that are preferred by the relying party.

        @param supported_types: A sequence of authentication policy
            type URIs that are supported by a provider

        @returns: The sub-sequence of the supported types that are
            preferred by the relying party. This list will be ordered
            in the order that the types appear in the supported_types
            sequence, and may be empty if the provider does not prefer
            any of the supported authentication types.

        @returntype: [str]
        )Úfilterr   Ú__contains__)r   Úsupported_typesr   r   r   ÚpreferredTypesƒ   s   ÿzRequest.preferredTypes)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úns_aliasr   r   r   r"   r)   Úclassmethodr%   r4   Ú__classcell__r   r   r   r   r       s    r   c                       sT   e Zd ZdZdZ		d‡ fdd„	Zdd„ Zdd	„ Zddd„Ze	eƒZdd„ Z
‡  ZS )r   z[A Provider Authentication Policy response, sent from a provider
    to a relying party
    r	   Nc                    s0   t t| ƒ ¡  |r|| _ng | _|| _|| _d S r
   )r   r   r   Úauth_policiesÚ	auth_timeÚnist_auth_level)r   r<   r=   r>   r   r   r   r       s   
zResponse.__init__c                 C   r   )a—  Add a authentication policy to this response

        This method is intended to be used by the provider to add a
        policy that the provider conformed to when authenticating the user.

        @param policy_uri: The identifier for the preferred type of
            authentication.
        @see: http://openid.net/specs/openid-provider-authentication-policy-extension-1_0-01.html#auth_policies
        N)r<   r   r   r   r   r   r   «   r   zResponse.addPolicyURIc                 C   s,   | ƒ }|  |j¡}|dur| |¡ |S dS )a9  Create a C{L{Response}} object from a successful OpenID
        library response
        (C{L{openid.consumer.consumer.SuccessResponse}}) response
        message

        @param success_response: A SuccessResponse from consumer.complete()
        @type success_response: C{L{openid.consumer.consumer.SuccessResponse}}

        @rtype: Response or None
        @returns: A provider authentication policy response from the
            data that was supplied with the C{id_res} response or None
            if the provider sent no signed PAPE response arguments.
        N)ÚgetSignedNSr   r%   )r&   Úsuccess_responser   r(   r   r   r   ÚfromSuccessResponse¸   s   
zResponse.fromSuccessResponseFc                 C   s¶   |  d¡}|r|dkr| d¡| _|  d¡}|r@zt|ƒ}W n ty0   |r+tdƒ‚d| _Y nw d|  kr;dk r@n n|| _|  d	¡}|rWt |¡rQ|| _dS |rYtd
ƒ‚dS dS )a  Parse the provider authentication policy arguments into the
        internal state of this object

        @param args: unqualified provider authentication policy
            arguments

        @param strict: Whether to raise an exception when bad data is
            encountered

        @returns: None. The data is parsed into the internal fields of
            this object.
        r<   Únoner   r>   úCnist_auth_level must be an integer between zero and four, inclusiveNr   é   r=   ú#auth_time must be in RFC3339 format)	r*   r+   r<   r,   r-   r>   ÚTIME_VALIDATORÚmatchr=   )r   r(   Ústrictr.   Únist_level_strÚ
nist_levelr=   r   r   r   r%   Ó   s,   


û


üzResponse.parseExtensionArgsc                 C   s„   t | jƒdkrddi}ndd | j¡i}| jdur,| jtddƒvr%tdƒ‚t| jƒ|d< | jdur@t 	| j¡s;td	ƒ‚| j|d
< |S )r   r   r<   rB   r   NrD   rC   r>   rE   r=   )
Úlenr<   r   r>   Úranger-   r   r=   rF   rG   r    r   r   r   r"   û   s   ÿÿ


zResponse.getExtensionArgs)NNN)F)r5   r6   r7   r8   r9   r   r   rA   r%   r:   r"   r;   r   r   r   r   r   ™   s    ÿ
&r   )r8   Ú__all__Úopenid.extensionr   Úrer   r   r   r   ÚcompilerF   r   r   r   r   r   r   Ú<module>   s     	ÿÿÿ
v
|