
    #Ii                     ^    S SK r S SKrS SKJr   " S S\R
                  R                  5      rg)    N)AccessTokenc                      ^  \ rS rSrSrU 4S jrS r\S 5       r\S 5       r	S r
S rSS	 jrSS
 jrS rS r\S 5       rSrU =r$ )ApplicationOAuth   z
This class is used for identifying and authorizing users for Github Apps.
The reference can be found at https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps
c                 D   > UR                  S S9n[        TU ]	  XX45        g )N)auth)withAuthsuper__init__)self	requesterheaders
attributes	completed	__class__s        =/venv/lib/python3.13/site-packages/github/ApplicationOAuth.pyr   ApplicationOAuth.__init__$   s%    &&D&1	ZC    c                 P    U R                  SU R                  R                  05      $ )N	client_id)get__repr__
_client_idvaluer   s    r   __repr__ApplicationOAuth.__repr__)   s"    doo.C.C DEEr   c                 .    U R                   R                  $ N)r   r   r   s    r   r   ApplicationOAuth.client_id,   s    $$$r   c                 .    U R                   R                  $ r   )_client_secretr   r   s    r   client_secretApplicationOAuth.client_secret0   s    ""(((r   c                     [         R                  R                  U l        [         R                  R                  U l        g r   )githubGithubObjectNotSetr   r!   r   s    r   _initAttributes ApplicationOAuth._initAttributes4   s)     --44$1188r   c                     SU;   a  U R                  US   5      U l        SU;   a  U R                  US   5      U l        g g )Nr   r"   )_makeStringAttributer   r!   )r   r   s     r   _useAttributesApplicationOAuth._useAttributes8   sF    *$"77
;8OPDOj("&";";J<W"XD )r   c                 @   SU R                   0nUb   [        U[        5      (       d   U5       eXS'   Ub   [        U[        5      (       d   U5       eX$S'   Ub   [        U[        5      (       d   U5       eX4S'   [        R                  R                  U5      nSnU SU 3$ )z]
Return the URL you need to redirect a user to in order to authorize
your App.
:type: string
r   redirect_uristateloginz(https://github.com/login/oauth/authorize?)r   
isinstancestrurllibparse	urlencode)r   r/   r0   r1   
parametersbase_urls         r   get_login_urlApplicationOAuth.get_login_url>   s     "4>>2
#lC00>,>0)5~&eS))050)"'weS))050)"'w\\++J7
=1ZL))r   c           	         [        U[        5      (       d   U5       eUU R                  U R                  S.nUb  X#S'   U R                  " U R
                  R                  SSSS0US96 u  pE[        U R
                  UUSS	9$ )
z
:calls: `POST /login/oauth/access_token <https://docs.github.com/en/developers/apps/identifying-and-authorizing-users-for-github-apps>`_
:param code: string
:param state: string
)coder   r"   r0   POST+https://github.com/login/oauth/access_tokenAcceptapplication/jsonr   inputFr   r   r   r   r3   r4   r   r"   _checkError
_requesterrequestJsonAndCheckr   )r   r=   r0   post_parametersr   datas         r   get_access_token!ApplicationOAuth.get_access_tokenT   s     $$$*d*$!//
 ',G$((__00=!#56%	 1 
 oo	
 	
r   c                     SSK Jn  U" U R                  U R                  UR                  UR
                  UR                  UR                  UR                  U R                  S9$ )z
:param token: AccessToken
r   )AppUserAuth)r   r"   token
token_type
expires_atrefresh_tokenrefresh_expires_atr   )
github.AuthrN   r   r"   rO   typerQ   rR   rS   rG   )r   rO   rN   s      r   get_app_user_auth"ApplicationOAuth.get_app_user_autht   sT    
 	,nn,,++zz''--$77oo	
 		
r   c           	          [        U[        5      (       d   eU R                  U R                  SUS.nU R                  " U R
                  R                  SSSS0US96 u  p4[        U R
                  UUSS	9$ )
z
:calls: `POST /login/oauth/access_token <https://docs.github.com/en/developers/apps/identifying-and-authorizing-users-for-github-apps>`_
:param refresh_token: string
rR   )r   r"   
grant_typerR   r>   r?   r@   rA   rB   FrD   rE   )r   rR   rI   r   rJ   s        r   refresh_access_token%ApplicationOAuth.refresh_access_token   s    
 -----!//)*	
 ((__00=!#56%	 1 
 oo	
 	
r   c                     [        U[        5      (       a=  SU;   a7  US   S:X  a  [        R                  " SX5      e[        R                  " SX5      eX4$ )Nerrorbad_verification_code   )r3   dictr%   BadCredentialsExceptionGithubException)r   rJ   s     r   rF   ApplicationOAuth._checkError   sP    dD!!goG} 7744S$HH((d<<}r   )r   r!   )NNNr   )__name__
__module____qualname____firstlineno____doc__r   r   propertyr   r"   r(   r,   r:   rK   rV   rZ   staticmethodrF   __static_attributes____classcell__)r   s   @r   r   r      sp    
D
F % % ) )9Y*,
@
$
:  r   r   )r5   github.GithubObjectr%   github.AccessTokenr   r&   NonCompletableGithubObjectr    r   r   <module>rq      s*   0   *Lv**EE Lr   