
    #Ii:                     X   S SK r S SKrS SKrS SKJrJrJr  S SKJrJrJ	r	  S SK
r
S SKJr  S SKJr  S SKJrJr  Sr\" \S9r " S	 S
\ R(                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\\S   5      r " S S\\S   5      rg)    N)datetime	timedeltatimezone)DictOptionalUnion)Consts)InstallationAuthorization)	RequesterWithRequester   )secondsc                       \ rS rSrSr\\R                  S\4S j5       5       r	\\R                  S\4S j5       5       r
Srg)Auth*   zK
This class is the base class of all authentication methods for Requester.
returnc                     g)zp
The type of the auth token as used in the HTTP Authorization header, e.g. Bearer or Basic.
:return: token type
N selfs    1/venv/lib/python3.13/site-packages/github/Auth.py
token_typeAuth.token_type/        	    c                     g)zI
The auth token as used in the HTTP Authorization header.
:return: token
Nr   r   s    r   token
Auth.token8   r   r   r   N)__name__
__module____qualname____firstlineno____doc__propertyabcabstractmethodstrr   r   __static_attributes__r   r   r   r   r   *   sY     C    s   r   r   c                       \ rS rSrSrS\S\4S jr\S\4S j5       r\S\4S j5       r	\S\4S	 j5       r
\S\4S
 j5       rSrg)LoginB   zG
This class is used to authenticate Requester with login and password.
loginpasswordc                     [        U[        5      (       d   e[        U5      S:  d   e[        U[        5      (       d   e[        U5      S:  d   eXl        X l        g Nr   )
isinstancer'   len_login	_password)r   r,   r-   s      r   __init__Login.__init__G   sT    %%%%%5zA~~(C((((8}q   !r   r   c                     U R                   $ N)r2   r   s    r   r,   Login.loginP       {{r   c                     U R                   $ r7   )r3   r   s    r   r-   Login.passwordT   s    ~~r   c                     g)NBasicr   r   s    r   r   Login.token_typeX       r   c                     [         R                  " U R                   SU R                   3R	                  5       5      R                  S5      R                  SS5      $ )N:utf-8
 )base64	b64encoder,   r-   encodedecodereplacer   s    r   r   Login.token\   sH     

|1T]]O<CCEFVG_WT2	
r   )r2   r3   N)r   r    r!   r"   r#   r'   r4   r$   r,   r-   r   r   r(   r   r   r   r*   r*   B   s    "c "S " s   #   C   
s 
 
r   r*   c                   V    \ rS rSrSrS\4S jr\S\4S j5       r\S\4S j5       r	Sr
g	)
Tokene   zL
This class is used to authenticate Requester with a single constant token.
r   c                 `    [        U[        5      (       d   e[        U5      S:  d   eXl        g r/   r0   r'   r1   _tokenr   r   s     r   r4   Token.__init__j   *    %%%%%5zA~~r   r   c                     gNr   r   r   s    r   r   Token.token_typeo   r?   r   c                     U R                   $ r7   rP   r   s    r   r   Token.tokens   r9   r   rX   N)r   r    r!   r"   r#   r'   r4   r$   r   r   r(   r   r   r   rL   rL   e   sI    c 
 C   s  r   rL   c                   0    \ rS rSrSr\S\4S j5       rSrg)JWTx   z
This class is the base class to authenticate with a JSON Web Token (JWT).
https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app
r   c                     g)NBearerr   r   s    r   r   JWT.token_type~   s    r   r   N)	r   r    r!   r"   r#   r$   r'   r   r(   r   r   r   r[   r[   x   s"    
 C  r   r[   c                   "   \ rS rSrSr\R                  \R                  \R                  4S\	\
\4   S\S\
S\
S\4
S jjr\S	\	\
\4   4S
 j5       r\S	\4S j5       r\S	\4S j5       r  SS\
S\\\\4      S\\   S	S4S jjrSS	\4S jjrSrg)AppAuth   z
This class is used to authenticate Requester as a GitHub App.
https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app
app_idprivate_key
jwt_expiryjwt_issued_atjwt_algorithmc                    [        U[        [        45      (       d   U5       e[        U[        5      (       a  [        U5      S:  d   S5       e[        U[        5      (       d   e[        U5      S:  d   S5       e[        U[        5      (       d   U5       e[        R
                  Us=::  a  [        R                  ::  d   U5       e   U5       eXl        X l        X0l	        X@l
        XPl        g )Nr   zapp_id must not be emptyzprivate_key must not be empty)r0   intr'   r1   r	   MIN_JWT_EXPIRYMAX_JWT_EXPIRY_app_id_private_key_jwt_expiry_jwt_issued_at_jwt_algorithm)r   rc   rd   re   rf   rg   s         r   r4   AppAuth.__init__   s     &3*--5v5-fc""v;?>$>>?+s++++;!#D%DD#*c**6J6*$$
Kf6K6KKWZWKWZWK'%++r   r   c                     U R                   $ r7   )rl   r   s    r   rc   AppAuth.app_id   s    ||r   c                     U R                   $ r7   )rm   r   s    r   rd   AppAuth.private_key   s       r   c                 "    U R                  5       $ r7   )
create_jwtr   s    r   r   AppAuth.token   s      r   Ninstallation_idtoken_permissions	requesterAppInstallationAuthc                     [        XX#5      $ )z
Creates a github.Auth.AppInstallationAuth instance for an installation.
:param installation_id: installation id
:param token_permissions: optional permissions
:param requester: optional requester with app authentication
:return:
)r|   )r   ry   rz   r{   s       r   get_installation_authAppAuth.get_installation_auth   s     #4:KWWr   c                    UbU  [        U[        5      (       d   U5       e[        R                  Us=::  a  [        R                  ::  d    U5       e   U5       e[        [
        R
                  " 5       5      nX R                  -   X!b  UOU R                  -   U R                  S.n[        R                  " X0R                  U R                  S9n[        U[        5      (       a  UR                  S5      $ U$ )z
Create a signed JWT
https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app

:return string: jwt
)iatexpiss)key	algorithmrB   )r0   ri   r	   rj   rk   timero   rn   rl   jwtrG   rd   rp   bytesrH   )r   
expirationnowpayload	encrypteds        r   rw   AppAuth.create_jwt   s     !j#..:
:.%%Lv7L7LLLL $))+,,,(>*DDTDTU<<

 JJ))T5H5H
	 i''##G,,r   )rl   rp   rn   ro   rm   NNr7   )r   r    r!   r"   r#   r	   DEFAULT_JWT_EXPIRYDEFAULT_JWT_ISSUED_ATDEFAULT_JWT_ALGORITHMr   ri   r'   r4   r$   rc   rd   r   r   r   r   r~   rw   r(   r   r   r   ra   ra      s    !33#99#99,c3h, , 	,
 , ,, c3h   !S ! ! !s ! ! 7;)-	XX $DcN3X I&	X
 
XS  r   ra   c                   >    \ rS rSrSrS\4S jr\S\4S j5       rSr	g)	AppAuthToken   z
This class is used to authenticate Requester as a GitHub App with a single constant JWT.
https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app
r   c                 `    [        U[        5      (       d   e[        U5      S:  d   eXl        g r/   rO   rQ   s     r   r4   AppAuthToken.__init__   rS   r   r   c                     U R                   $ r7   rX   r   s    r   r   AppAuthToken.token   r9   r   rX   N)
r   r    r!   r"   r#   r'   r4   r$   r   r(   r   r   r   r   r      s.    
c 
 s  r   r   c            
       |  ^  \ rS rSr% SrSSKJr  Sr\\   \	S'   Sr
\\   \	S'     SS\S	\S
\\\\4      S\\   4U 4S jjjrS\SS 4U 4S jjr\S\\\4   4S j5       r\S\4S j5       r\S\4S j5       r\S\\\\4      4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       rS\4S jrSrU =r$ )r|      z
This class is used to authenticate Requester as a GitHub App Installation.
https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation
r   GithubIntegrationN!_AppInstallationAuth__integration0_AppInstallationAuth__installation_authorizationapp_authry   rz   r{   c                   > [         TU ]  5         [        U[        5      (       d   U5       e[        U[        5      (       d   U5       eUb  [        U[
        5      (       d   U5       eXl        X l        X0l        Ub  U R                  U5        g g r7   )
superr4   r0   ra   ri   dict	_app_auth_installation_id_token_permissionswithRequester)r   r   ry   rz   r{   	__class__s        r   r4   AppInstallationAuth.__init__   s     	(G,,6h6,/3//@@/ (Jt-
 -
 		 
 " /"3 y) !r   r   c                    > [         TU ]  UR                  U R                  5      5        SSKJn  U" U R                  UR                  S9U l        U $ )Nr   r   )authbase_url)r   r   withAuthr   github.GithubIntegrationr   r   r   )r   r{   r   r   s      r   r   !AppInstallationAuth.withRequester	  sF    i00@A>.''

 r   c                 .    U R                   R                  $ r7   )r   rc   r   s    r   rc   AppInstallationAuth.app_id  s    ~~$$$r   c                 .    U R                   R                  $ r7   )r   rd   r   s    r   rd   AppInstallationAuth.private_key  s    ~~)))r   c                     U R                   $ r7   )r   r   s    r   ry   #AppInstallationAuth.installation_id  s    $$$r   c                     U R                   $ r7   )r   r   s    r   rz   %AppInstallationAuth.token_permissions!  s    &&&r   c                     grU   r   r   s    r   r   AppInstallationAuth.token_type%  r?   r   c                     U R                   b  U R                  (       a  U R                  5       U l         U R                   R                  $ r7   )r   _is_expired_get_installation_authorizationr   r   s    r   r   AppInstallationAuth.token)  s9    ,,48H8H040T0T0VD-00666r   c                     U R                   c   eU R                   R                  [        -
  nU[        R                  " [
        R                  5      R                  S S9:  $ )N)tzinfo)r   
expires_at!TOKEN_REFRESH_THRESHOLD_TIMEDELTAr   r   r   utcrI   )r   token_expires_ats     r   r   AppInstallationAuth._is_expired/  sX    00<<<--88/0 	
  (,,x||"<"D"DD"D"QQQr   c                     U R                   c   S5       eU R                   R                  U R                  U R                  S9$ )Nz4Method withRequester(Requester) must be called first)permissions)r   get_access_tokenr   r   r   s    r   r   3AppInstallationAuth._get_installation_authorization9  sP    *	BA	B*!!22!!// 3 
 	
r   )__installation_authorization__integrationr   r   r   r   ) r   r    r!   r"   r#   r   r   r   r   __annotations__r   r
   ra   ri   r   r'   r   r4   r   r$   r   rc   rd   ry   rz   r   r   boolr   r   r(   __classcell__r   s   @r   r|   r|      su    ; 26M8-.5HL (+D"EL 7;)-** * $DcN3	*
 I&* *,
y 
5J 
 %c3h % % *S * * % % % '8DcN#; ' ' C   7s 7 7
 RT R R
1J 
 
r   r|   c                     ^  \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \\   \S'   \\   \S'   \\   \S	'   \\   \S
'   SSK	J
r
  \
\S'        SS\S\S\S\\   S\\   S\\   4S jjr\S\4S j5       r\S\4S j5       rS\SS 4U 4S jjr\S\4S j5       rS r\S\\   4S j5       r\S\\   4S j5       r\S\\   4S j5       rSrU =r$ ) AppUserAuthiC  z
This class is used to authenticate Requester as a GitHub App on behalf of a user.
https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-with-a-github-app-on-behalf-of-a-user

_client_id_client_secretrP   _type_scope_expires_at_refresh_token_refresh_expires_atr   ApplicationOAuth_AppUserAuth__app	client_idclient_secretr   r   r   r{   c	                    [        U[        5      (       d   e[        U5      S:  d   e[        U[        5      (       d   e[        U5      S:  d   e[        U[        5      (       d   e[        U5      S:  d   eUb(  [        U[        5      (       d   e[        U5      S:  d   e[        U[        5      (       d   eUb(  [        U[        5      (       d   e[        U5      S:  d   eUb  [        U[        5      (       d   eUb(  [        U[        5      (       d   e[        U5      S:  d   eUb  [        U[        5      (       d   eXl        X l        X0l        U=(       d    SU l        XPl        X`l	        Xpl
        Ub  U R                  U5        g g )Nr   bearer)r0   r'   r1   r   r   r   rP   r   r   r   r   r   )	r   r   r   r   r   r   refresh_tokenrefresh_expires_atr{   s	            r   r4   AppUserAuth.__init__W  s    )S))))9~!!!-----=!A%%%%%%%%5zA~~!j#....z?Q&&&%%%%%!j#....z?Q&&&!j(3333$mS1111}%))))0(;;;;#++8
%+#5  y) !r   r   c                     U R                   $ r7   )r   r   s    r   r   AppUserAuth.token_type  s    zzr   c                 \    U R                   (       a  U R                  5         U R                  $ r7   )r   _refreshrP   r   s    r   r   AppUserAuth.token  s    MMO{{r   c                    > [         TU ]  UR                  S 5      5        SSKJn  U" [         TU ]  0 U R                  U R                  S.SS9U l        U $ )Nr   r   )r   r   F)headers
attributes	completed)	r   r   r   github.ApplicationOAuthr   r{   r   r   r   )r   r{   r   r   s      r   r   AppUserAuth.withRequester  sX    i0067 	=%G!__!%!4!4 	

 r   c                     U R                   S L=(       a1    U R                   [        R                  " [        R                  5      :  $ r7   )r   r   r   r   r   r   s    r   r   AppUserAuth._is_expired  s:    t+ 
0@0@8<<LLD
 1
 	
r   c                    U R                   c  [        S5      eU R                  b=  U R                  [        R                  " [
        R                  5      :  a  [        S5      eU R                  R                  U R                   5      nUR                  U l
        UR                  U l        UR                  U l        UR                  U l        UR"                  U l         UR$                  U l        g )NzGCannot refresh expired token because no refresh token has been providedz?Cannot refresh expired token because refresh token also expired)r   RuntimeErrorr   r   r   r   r   r   refresh_access_tokenr   rP   typer   scoper   r   r   r   r   rQ   s     r   r   AppUserAuth._refresh  s    &Y  $$0((8<<+EEQ 
 

//0C0CD kkZZ
kk ++#11#(#;#; r   c                     U R                   $ r7   )r   r   s    r   r   AppUserAuth.expires_at  s    r   c                     U R                   $ r7   )r   r   s    r   r   AppUserAuth.refresh_token  s    """r   c                     U R                   $ r7   )r   r   s    r   r   AppUserAuth.refresh_expires_at  s    '''r   )	__appr   r   r   r   r   r   rP   r   )NNNNN)r   r    r!   r"   r#   r'   r   r   r   r   r   r   r4   r$   r   r   r   r   r   r   r   r   r   r(   r   r   s   @r   r   r   C  s{   
 OKJSM(##SM!!(++ 9 %))-)-)*)* )* 	)*
 SM)* X&)* I&)*V C   s  
y ] & 
T 
 

<0  HX.     #x} # # (HX$6 ( (r   r   )r%   rE   r   r   r   r   typingr   r   r   r   githubr	    github.InstallationAuthorizationr
   github.Requesterr   r   &ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDSr   ABCr   r*   rL   r[   ra   r   r|   r   r   r   r   <module>r     s   .    2 2 ( ( 
  F 5 *, &$-2% !
377 0 
D  
FD &$ Pc Pf3  Z
$.C D Z
zD($m4 D(r   