a
    Šxd%  ã                   @   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__© úU/var/www/html/Ranjet/env/lib/python3.9/site-packages/openid/extensions/draft/pape2.pyr   1   s
    zRequest.__init__c                 C   s   t | jp| jd uƒS r
   )Úboolr   r   )r   r   r   r   Ú__bool__9   s    ÿzRequest.__bool__c                 C   s   || j vr| j  |¡ 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   Z
policy_urir   r   r   ÚaddPolicyURI=   s    

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   Zns_argsr   r   r   ÚgetExtensionArgsJ   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)ÚmessageZgetArgsr   ÚparseExtensionArgs)ÚclsÚrequestr   Úargsr   r   r   ÚfromOpenIDRequestV   s    
zRequest.fromOpenIDRequestc                 C   sŠ   g | _ | d¡}|rPt|tƒr*t|dd}| d¡D ]}|| j vr4| j  |¡ q4| d¡}d| _|r†zt|ƒ| _W n t	y„   Y n0 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   zutf-8)Úencodingr   r   N)
r   ÚgetÚ
isinstanceÚbytesr   Úsplitr   r   ÚintÚ
ValueError)r   r#   Úpolicies_strÚuriZmax_auth_age_strr   r   r   r    e   s    



zRequest.parseExtensionArgsc                 C   s   t 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]
        )ÚlistÚfilterr   Ú__contains__)r   Zsupported_typesr   r   r   ÚpreferredTypes†   s    ÿzRequest.preferredTypes)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úns_aliasr   r   r   r   r$   Úclassmethodr    r1   Ú__classcell__r   r   r   r   r   !   s   !r   c                       sP   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   r9   r:   r;   r   r   r   r   ¤   s    zResponse.__init__c                 C   s   || j vr| j  |¡ dS )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)r9   r   r   r   r   r   r   ±   s    

zResponse.addPolicyURIc                 C   s0   | ƒ }|  |j¡}|dur(| |¡ |S d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)ZgetSignedNSr   r    )r!   Z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yb   |rXtdƒ‚nd| _Y n 0 d|  krxdk r‚n n|| _|  d	¡}|r®t |¡r¢|| _n|r®td
ƒ‚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.
        r9   Únoner   r;   úCnist_auth_level must be an integer between zero and four, inclusiveNr   é   r:   ú#auth_time must be in RFC3339 format)	r&   r)   r9   r*   r+   r;   ÚTIME_VALIDATORÚmatchr:   )r   r#   Ústrictr,   Znist_level_strZ
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tddƒƒvrNtdƒ‚t| jƒ|d< | jdur„t	 
| j¡sztd	ƒ‚| j|d
< |S )r   r   r9   r=   r   Nr?   r>   r;   r@   r:   )Úlenr9   r   r;   r.   Úranger+   r   r:   rA   rB   r   r   r   r   r     s    ÿÿ


zResponse.getExtensionArgs)NNN)F)r2   r3   r4   r5   r6   r   r   r<   r    r7   r   r8   r   r   r   r   r      s      ý
'r   )r5   Ú__all__Zopenid.extensionr   Úrer   r   r   r   ÚcompilerA   r   r   r   r   r   r   Ú<module>   s    	ÿÿÿ
y 