
    qh.                         S r SSKJr  SSKJr  SSKJr  SSKJr   " S S	\5      r	 " S
 S\	5      r
 " S S\
5      r " S S\
5      r " S S\	5      rg)zn
Github OAuth2 backend, docs at:
    https://python-social-auth.readthedocs.io/en/latest/backends/github.html
    )urljoin)	HTTPError   )
AuthFailed   )
BaseOAuth2c                   d    \ rS rSrSrSrSrSrSrSr	Sr
S	rS	r/ S
QrS\4S jrS rS rSS jrSrg)GithubOAuth2   z#Github OAuth authentication backendgithubzhttps://api.github.com/z(https://github.com/login/oauth/authorizez+https://github.com/login/oauth/access_token,FT))idr   )
expires_inexpires)loginr   )refresh_tokenr   returnc                     U R                   $ N)API_URL)selfs    M/var/www/html/env/lib/python3.13/site-packages/social_core/backends/github.pyapi_urlGithubOAuth2.api_url    s    ||    c                     U R                  UR                  S5      5      u  p#nUR                  S5      UR                  S5      =(       d    SUUUS.$ )z'Return user details from Github accountnamer   email )usernamer   fullname
first_name	last_name)get_user_namesget)r   responser!   r"   r#   s        r   get_user_detailsGithubOAuth2.get_user_details#   sP    *.*=*=hll6>R*S'i W-\\'*0b $"
 	
r   c                    U R                  U5      nUR                  S5      (       d   U R                  US5      nU(       a{  US   nU Vs/ s H2  n[        U[        5      (       a  UR                  S5      (       d  M0  UPM4     nnU(       a  US   n[        U[        5      (       a  UR                  SS5      nXdS'   U$ ! [        [        [        4 a    / n Nf = fs  snf )Loads user data from servicer   z/emailsr   primaryr   )
_user_datar%   r   
ValueError	TypeError
isinstancedict)	r   access_tokenargskwargsdataemailsr   eprimary_emailss	            r   	user_dataGithubOAuth2.user_data.   s    |,xx  yA q	%"%!Z4-@-@AEE)DTAv  " "*1-EeT**!IIgr2E %W z95 
"s   B? /C>C?CCNc                     [        U R                  5       SR                  U=(       d    S5      5      nU R                  USSU 30S9$ )Nzuser{}r   Authorizationtoken headers)r   r   formatget_json)r   r1   pathurls       r   r,   GithubOAuth2._user_dataC   s@    dllnhoodjb&AB}}S?f\N<S*T}UUr    r   )__name__
__module____qualname____firstlineno____doc__r   r   AUTHORIZATION_URLACCESS_TOKEN_URLSCOPE_SEPARATORREDIRECT_STATESTATE_PARAMETERSEND_USER_AGENT
EXTRA_DATAstrr   r'   r8   r,   __static_attributes__rD   r   r   r
   r
      sR    -D'GBDONOOJ 	
*Vr   r
   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )GithubMemberOAuth2H   r   c                    > [         TU ]  " U/UQ70 UD6nSSU 30n U R                  U R                  U5      US9  U$ ! [         a1  nUR
                  R                  S:w  a  [        U S5      e SnAU$ SnAff = f)r*   r;   r<   r=      'User doesn't belong to the organizationN)superr8   request
member_urlr   r&   status_coder   )r   r1   r2   r3   r8   r>   err	__class__s          r   r8   GithubMemberOAuth2.user_dataK   s    G%lDTDVD	"f\N$;<	RLL3WLE   	R ||''3. 'PQQ /	Rs   ? 
A:	&A55A:c                     [        S5      e)NzImplement in subclass)NotImplementedErrorr   r8   s     r   r[   GithubMemberOAuth2.member_urlX   s    !"9::r   rD   )	rE   rF   rG   rH   no_member_stringr8   r[   rR   __classcell__r^   s   @r   rT   rT   H   s    ; ;r   rT   c                   &    \ rS rSrSrSrSrS rSrg)GithubOrganizationOAuth2\   z6Github OAuth2 authentication backend for organizationsz
github-orgrX   c           	          [        U R                  5       SR                  U R                  S5      UR	                  S5      S95      $ )Nzorgs/{org}/members/{username}NAMEr   )orgr    r   r   r?   settingr%   rb   s     r   r[   #GithubOrganizationOAuth2.member_urlb   sB    LLN+22LL(9==3I 3 
 	
r   rD   N	rE   rF   rG   rH   rI   r   rd   r[   rR   rD   r   r   rh   rh   \   s    @D@
r   rh   c                   &    \ rS rSrSrSrSrS rSrg)GithubTeamOAuth2k   z.Github OAuth2 authentication backend for teamszgithub-teamzUser doesn't belong to the teamc           	          [        U R                  5       SR                  U R                  S5      UR	                  S5      S95      $ )Nz"teams/{team_id}/members/{username}IDr   )team_idr    rm   rb   s     r   r[   GithubTeamOAuth2.member_urlq   sB    LLN077T*Y]]75K 8 
 	
r   rD   Nrp   rD   r   r   rr   rr   k   s    8D8
r   rr   c                   0   ^  \ rS rSrSrSrU 4S jrSrU =r$ )GithubAppAuthz   z'GitHub App OAuth authentication backendz
github-appc                    > U R                   R                  S5      (       a!  U R                   R                  S5      (       a  g[        TU ]  5       $ )aE  
Scenario 1: user clicks an icon/button on your website and initiates
            social login. This works exacltly like standard OAuth and we
            have `state` and `redirect_uri`.

Scenario 2: user starts from http://github.com/apps/your-app and clicks
            'Install & Authorize' button! They still get a temporary
            `code` (used to fetch `access_token`) but there's no `state`
            or `redirect_uri` here.

Note: Scenario 2 only happens when your GitHub App is configured
      with `Request user authorization (OAuth) during installation`
      turned on! This causes GitHub to redirect the person back to
      `/complete/github/`. If the above setting is turned off then
      GitHub will redirect to another URL called Setup URL and the
      person may need to login first before they can continue!
installation_idsetup_actionN)r4   r%   rY   validate_state)r   r^   s    r   r~   GithubAppAuth.validate_state   s<    $ 99==*++		n0M0Mw%''r   rD   )	rE   rF   rG   rH   rI   r   r~   rR   re   rf   s   @r   ry   ry   z   s    1D( (r   ry   N)rI   urllib.parser   requestsr   
exceptionsr   oauthr   r
   rT   rh   rr   ry   rD   r   r   <module>r      sY   
 !  # 7V: 7Vt; ;(
1 

) 
(L (r   