
                             S r SSK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  SSKJr  S	rS
rSr\R"                  " \5      r " S S\R(                  5      rg)zTwo factor Oauth2Credentials.    N)_helpers)client)	transport)reauth)reauth_errors)http_clientinvalid_grantinvalid_raptrapt_requiredc                   b   ^  \ rS rSrSrU 4S jr\S 5       r\S 5       rS 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                 T   > SU;   a  US   U l         US	 [        [        U ]  " U0 UD6  g)zjCreate an instance of Oauth2WithReauthCredentials.

A Oauth2WithReauthCredentials has an extra rapt_token.
rapt_tokenN)r   superr   __init__)selfargskwargs	__class__s      4lib/third_party/oauth2client/contrib/reauth_creds.pyr   $Oauth2WithReauthCredentials.__init__/   s6    
 6!"<0$/\")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)
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_json9   s!    zz(..y9:HH^$$T.183D3DEE(#+#4#4#=#=>"F$8$8$:D 
 $E ((5$'%!5M$ 
~

{





~

{

|
	
 	
 i-  (#'D (s   $4C. .D ?D c                 D    UR                  5       nU R                  U5      $ )zAInstantiate a Oauth2WithReauthCredentials from OAuth2Credentials.)to_jsonr9   )r3   originalr*   s      r   from_OAuth2Credentials2Oauth2WithReauthCredentials.from_OAuth2Credentials[   s!     !}}T""r   c                     SU R                   U R                  U R                  U R                  S.n[        R
                  R                  U5      nU$ )r   r&   )
grant_typer$   r%   r&   rapt)r$   r%   r&   r   urllibparse	urlencode)r   
parametersbodys      r   _generate_refresh_request_body:Oauth2WithReauthCredentials._generate_refresh_request_bodya   sI     *!//!//OO

 ||%%j1r   c           
      @   0 n [         R                  " U5      nU(       d  UR	                  S5      [
        :X  a  UR	                  S5      [        :X  d  UR	                  S5      [        :X  au  [        R                  " [        USU5      U R                  U R                  U R                  U R                  [        U R                   5      S9U l        U R%                  USS9  g [&        R)                  SR+                  U5      5        SR+                  UR,                  5      nSU;   aE  US   nS	U;   a  US
US	   -   -  nSU l        U R0                  b  U R0                  R3                  U 5        [4        R6                  " XcR,                  S9e! [        [        4 a     GNf = f)Nerrorerror_subtyperequest)r!   T)rapt_refreshedz$Failed to retrieve access token: {0}zInvalid response {0}.error_descriptionz: )status)r*   r+   	TypeErrorr2   r-   REAUTH_NEEDED_ERROR REAUTH_NEEDED_ERROR_INVALID_RAPT!REAUTH_NEEDED_ERROR_RAPT_REQUIREDr   GetRaptTokengetattrr$   r%   r&   r'   listr!   r   _do_refresh_requestloggerinfoformatrP   r)   store
locked_putr   HttpAccessTokenRefreshError)r   httprN   respcontentd	error_msgs          r   _handle_refresh_error1Oauth2WithReauthCredentials._handle_refresh_errorm   sh   
 	

7#A 155>5H#HUU?#'GGUU?#'HH$11i.""""DKK(DO $$T$$? 	:AA'JK+224;;?	a<'
I"a'TA&9$:::	DLzz%

%%d+77
KK) 	)9 :& 		s   F	 	FFc                 F   U R                  5       nU R                  5       n[        R                  S5        [        R
                  " XR                  SX4S9u  pV[        R                  " U5      nUR                  [        R                  :w  a  U R                  XXV5        g[        R                  " U5      nXpl        US   U l        UR#                  SU R$                  5      U l        SU;   a>  [&        R(                  " [+        US   5      S9nU[,        R.                  " 5       -   U l        OSU l        S	U;   a)  [,        R2                  " US	   5      U l        US	   U l        OSU l        SU l        S
U l        U R:                  (       a  U R:                  R=                  U 5        gg)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:
    HttpAccessTokenRefreshError: When the refresh fails.
zRefreshing access_tokenPOST)methodrG   headersNr#   r&   
expires_in)secondsr   F)rH   !_generate_refresh_request_headersrY   rZ   r   rM   r'   r   r,   rP   r   OKrd   r*   r+   r    r#   r-   r&   r/   	timedeltaintr   _UTCNOWr   _extract_id_tokenr   r   r)   r\   r]   )	r   r_   rN   rG   ri   r`   ra   rb   deltas	            r   rX   /Oauth2WithReauthCredentials._do_refresh_request   sV    002d668gkk+,''
v&md $$W-g		&

$
$T4
I

**W
aN+d55$2D2DEd		$$S<-AB%#fnn&66$
"$
	q 221Z=A$-
m$
$-"$
 dl	
**


% 
r   )r#   r   r   r)   r   r&   r   r    )F)__name__
__module____qualname____firstlineno____doc__r   classmethodr9   r>   rH   rd   rX   __static_attributes____classcell__)r   s   @r   r   r   '   sL    K  B # #

%)N+& +&r   r   )rx   r/   r*   loggingrC   oauth2clientr   r   r   oauth2client.contribr   r   	six.movesr   rR   rS   rT   	getLoggerrt   rY   OAuth2Credentialsr    r   r   <module>r      sb    $     !  " ' . ! & #1  $3 !			8	$X&&":": X&r   