
    f                     j    d dl mZ d dlmZ d dlmZ d dlmZmZ  G d de      Z	 G d de      Z
e
gZy	)
    )HttpResponseRedirect)reverse)	urlencode)ProviderProviderAccountc                       e Zd Zy)SAMLAccountN)__name__
__module____qualname__     h/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/allauth/socialaccount/providers/saml/provider.pyr	   r	      s    r   r	   c                   v     e Zd 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Z	d Z
d Zd Zd Zd ZddZ xZS )SAMLProvidersamlSAMLTz,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                     t        |   |i | | j                  j                  xs$ | j                  j                  xs | j                  | _        y N)super__init__appname	client_id)selfargskwargs	__class__s      r   r   zSAMLProvider.__init__(   s<    $)&)HHMMDTXX%7%7D499	r   c                 r    t        dd| j                  j                  i      }|r|dz   t        |      z   }|S )N
saml_loginorganization_slug)r#   ?)r   r   r    r   )r!   requestr#   urls       r   get_login_urlzSAMLProvider.get_login_url,   s9    l,?ASAS+TU)i//C
r   c                 "    |j                         S r   )get_attributes)r!   datas     r   extract_extra_datazSAMLProvider.extract_extra_data2   s    ""$$r   c                 j    | j                  |      j                  d      }||j                         }|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   )_extractget
get_nameid)r!   r.   r   s      r   extract_uidzSAMLProvider.extract_uid5   s3    0 mmD!%%e,;//#C
r   c                 L    | j                  |      }|j                  dd        |S )Nr   )r1   pop)r!   r.   rets      r   extract_common_fieldsz"SAMLProvider.extract_common_fieldsR   s#    mmD!t
r   c                 2   | j                   j                  }|j                         }i }|j                  d| j                        }|j                         D ]L  \  }}t        |t              r|g}|D ]/  }|j                  |d       }	|	t        |	      dkD  s'|	d   ||<    L N |j                  d      }
|
r|
j                         dv }
|
|d<   |j                  d      s8|j                         dk(  s|j                  dd      r|j                         |d<   |S )	Nattribute_mappingr   r   )true1tyyesr   z6urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddressuse_nameid_for_emailF)r   settingsr-   r2   default_attribute_mappingitems
isinstancestrlenlowerget_nameid_formatr3   )r!   r.   provider_configraw_attributes
attributesr:   keyprovider_keysprovider_keyattribute_listr   s              r   r1   zSAMLProvider._extractW   s4   ((++,,.
+//!?!?
 #4"9"9"; 	C--!. - !/!3!3L$!G!-#n2E2I&4Q&7JsO		 $(89+1137UUN+9J'( ~~g&""$GH ""#95A"&//"3Jwr   c                     ddl m}  |||       }|j                  d      } | j                  ||||fd|j	                         i| t        |      S )Nr   )
build_auth )	return_tostate_id)*allauth.socialaccount.providers.saml.utilsrQ   loginstash_redirect_stateget_last_request_idr   )	r!   r)   processnext_urlr.   r#   rQ   authredirects	            r   r\   zSAMLProvider.redirectw   si    I'4( :::+!!!		

 --/	
 	
 $H--r   )NN)r
   r   r   idr   supports_redirectr	   account_classrB   r   r+   r/   r4   r8   r1   r\   __classcell__)r$   s   @r   r   r      s    	BDM ;
 0P

 6
 N

 
 0
%!.E%:
@.r   r   N)django.httpr   django.urlsr   django.utils.httpr   $allauth.socialaccount.providers.baser   r   r	   r   provider_classesr   r   r   <module>rf      s6    ,  ' J	/ 	z.8 z.z !> r   