o
    Lf                     @   sR   d dl mZ d dlmZ d dlmZmZ G dd deZG dd deZegZ	dS )	    )reverse)	urlencode)ProviderProviderAccountc                       s   e Zd Z fddZ  ZS )SAMLAccountc                    s
   t   S N)superto_str)self	__class__ n/var/www/html/humari/django-venv/lib/python3.10/site-packages/allauth/socialaccount/providers/saml/provider.pyr	      s   
zSAMLAccount.to_str)__name__
__module____qualname__r	   __classcell__r   r   r   r   r      s    r   c                       sr   e Zd ZdZdZeZdgddgdgddgd	gd
gdZ fddZdd Z	dd Z
dd Zdd Zdd Z  ZS )SAMLProvidersamlSAMLz,urn:oasis:names:tc:SAML:attribute:subject-idz!urn:oid:0.9.2342.19200300.100.1.3zBhttp://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddressz'http://schemas.auth0.com/email_verifiedz?http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givennamezurn:oid:2.5.4.42zurn:oid:2.5.4.4z!http://schemas.auth0.com/nickname)uidemailemail_verified
first_name	last_nameusernamec                    s.   t  j|i | | jjp| jjp| j| _d S r   )r   __init__appname	client_id)r
   argskwargsr   r   r   r   '   s   zSAMLProvider.__init__c                 K   s,   t dd| jjid}|r|d t| }|S )N
saml_loginorganization_slug)r!   ?)r   r   r   r   )r
   requestr!   urlr   r   r   get_login_url+   s   zSAMLProvider.get_login_urlc                 C   s   |  S r   )get_attributes)r
   datar   r   r   extract_extra_data1   s   zSAMLProvider.extract_extra_datac                 C   s$   |  |d}|du r| }|S )u  http://docs.oasis-open.org/security/saml-subject-id-attr/v1.0/csprd01/saml-subject-id-attr-v1.0-csprd01.html

        Quotes:

        "While the Attributes defined in this profile have as a goal the
        explicit replacement of the <saml:NameID> element as a means of subject
        identification, it is certainly possible to compose them with existing
        NameID usage provided the same subject is being identified. This can
        also serve as a migration strategy for existing applications."


        "SAML does not define an identifier that meets all of these
        requirements well. It does standardize a kind of NameID termed
        “persistent” that meets some of them in the particular case of so-called
        “pairwise” identification, where an identifier varies by relying
        party. It has seen minimal adoption outside of a few contexts, and fails
        at the “compact” and “simple to handle” criteria above, on top of the
        disadvantages inherent with all NameID usage."

        Overall, our strategy is to prefer a uid resulting from explicit
        attribute mappings, and only if there is no such uid fallback to the
        NameID.
        r   N)_extractget
get_nameid)r
   r)   r   r   r   r   extract_uid4   s   zSAMLProvider.extract_uidc                 C   s   |  |}|dd  |S )Nr   )r+   pop)r
   r)   retr   r   r   extract_common_fieldsQ   s   
z"SAMLProvider.extract_common_fieldsc                 C   s   | j j}| }i }|d| j}| D ])\}}t|tr!|g}|D ]}||d }	|	d ur=t|	dkr=|	d ||<  nq#q|d}
|
rP|
	 dv }
|
|d< |dsa|
 dkra| |d< |S )Nattribute_mappingr   r   )true1tyyesr   z6urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress)r   settingsr(   r,   default_attribute_mappingitems
isinstancestrlenlowerget_nameid_formatr-   )r
   r)   provider_configraw_attributes
attributesr2   keyprovider_keysprovider_keyattribute_listr   r   r   r   r+   V   s4   

zSAMLProvider._extract)r   r   r   idr   r   account_classr9   r   r'   r*   r.   r1   r+   r   r   r   r   r   r      s2    r   N)
django.urlsr   django.utils.httpr   $allauth.socialaccount.providers.baser   r   r   r   provider_classesr   r   r   r   <module>   s    
j