
    F                         S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  \R                  " \5      r " S S	\R                  5      rg)
zTwo factor Oauth2Credentials.    N)_helpers)client)	transport)errors)reauthc                   `   ^  \ rS rSrSrU 4S jr\S 5       r\S 5       rS r	  S	S jr
SrU =r$ )
Oauth2WithReauthCredentials!   a(  Credentials object that extends OAuth2Credentials with reauth support.

This class provides the same functionality as OAuth2Credentials, but adds
the support for reauthentication and rapt tokens. These credentials should
behave the same as OAuth2Credentials when the credentials don't use rauth.
c                 \   > UR                  SS5      U l        [        [        U ]  " U0 UD6  g)zjCreate an instance of Oauth2WithReauthCredentials.

A Oauth2WithReauthCredentials has an extra rapt_token.
rapt_tokenN)popr   superr	   __init__)selfargskwargs	__class__s      5platform/bq/third_party/google_reauth/reauth_creds.pyr   $Oauth2WithReauthCredentials.__init__)   s,    
 !**\48)494J6J    c           
         [         R                  " [        R                  " U5      5      nUR	                  S5      (       aW  [        US   [        R                  5      (       d5   [        R                  R                  US   [        R                  5      US'   0 nS H  nUR	                  US5      nUc  M  XSU'   M      U " US   US   US   US   US   US   US	   40 UD6nUS
   Ul        U$ ! [         a    SUS'    Ngf = f)z
Overrides.token_expiryN)
revoke_uriid_tokenid_token_jwttoken_responsescopestoken_info_urir   access_token	client_idclient_secretrefresh_token	token_uri
user_agentinvalid)jsonloadsr   _from_bytesget
isinstancedatetimestrptimer   EXPIRY_FORMAT
ValueErrorr%   )cls	json_datadatar   paramvalueretvals          r   	from_json%Oauth2WithReauthCredentials.from_json1   s"    zz(..y9:XXn%%^ 4h6G6GHH,'/'8'8'A'A(&*>*>(@^$
 $E HHUD)E  %u$ 
~

{





~

{

|
	
 	
 i-  ,'+^$,s   $4C. .D ?D c                 D    UR                  5       nU R                  U5      $ )zAInstantiate a Oauth2WithReauthCredentials from OAuth2Credentials.)to_jsonr5   )r/   originalr&   s      r   from_OAuth2Credentials2Oauth2WithReauthCredentials.from_OAuth2CredentialsS   s!     !}}T""r   c                 2  ^ U R                  5       n[        R                  S5        U4S jn U R                  " [        R
                  " UU R                  U R                  U R                  U R                  U R                  [        U R                  5      US96   g! [        R                  [        R                  4 aV  nSU l        U R"                  (       a  U R"                  R%                  U 5        [&        R                  " XDR(                  S9eSnAff = f)a.  Refresh the access_token using the refresh_token.

Args:
    http: An object to be used to make HTTP requests.
    rapt_refreshed: If we did or did not already refreshed the rapt
                    token.

Raises:
    oauth2client_4_0.client.HttpAccessTokenRefreshError: if the refresh
        fails.
zRefreshing access_tokenc                 f   > [         R                  " TXX#S9u  pE[        R                  " U5      nXE4$ )N)methodbodyheaders)r   requestr   r(   )urir>   r?   r@   responsecontenthttps         r   http_requestEOauth2WithReauthCredentials._do_refresh_request.<locals>.http_requesti   s9     ) 1 1c!,H **73G$$r   )raptr   r@   T)statusN)!_generate_refresh_request_headers_LOGGERinfo_updater   refresh_access_tokenr    r!   r"   r#   r   listr   r   ReauthAccessTokenRefreshErrorHttpAccessTokenRefreshErrorr%   store
locked_putr   rI   )r   rE   r@   rF   es    `   r   _do_refresh_request/Oauth2WithReauthCredentials._do_refresh_requestY   s     88:./	%	ILL&55 NN&&&&NN,#% & 44224 	IDLzz

%%d+44QxxHH	Is   A-B $D ADDc                    U(       a  Xl         X l        X0l        U(       a  UOU R                  U l        U(       a;  [        R
                  " [        U5      S9nU[        R                  " 5       -   U l	        OS U l	        X`l
        U(       a  [        R                  " U5      OS U l        SU l        U R                  (       a  U R                  R                  U 5        g g )N)secondsF)r   r   r   r"   r+   	timedeltaintr   _UTCNOWr   r   _extract_id_tokenr   r%   rR   rS   )r   rH   rD   r   r"   
expires_inr   deltas           r   rM   #Oauth2WithReauthCredentials._update   s    "O%(*M0B0B 	&&s:?E %(8 8D $D$2:F$$X. 	 ::JJ!!$' r   )r   r   r   r%   r   r"   r   r   )NNN)__name__
__module____qualname____firstlineno____doc__r   classmethodr5   r:   rU   rM   __static_attributes____classcell__)r   s   @r   r	   r	   !   sR    K  B # #
&IP BF*.( (r   r	   )rd   r+   r&   loggingoauth2client_4_0r   r   r   google_reauthr   r   	getLoggerr`   rK   OAuth2Credentialsr	    r   r   <module>rn      sJ     $    % # &     

H
%s(&":": s(r   