/// Use the refresh token to get a new access token.
Use the refresh token to get a new access token.
Use the refresh token to get a new access token .
async fn refresh_access_token(&self, https_client: &HttpsClient) -> Result<()> {
        match &self.refresh_token {
            Some(refresh_token) => {
                let req_body = RefreshTokenRequest {
                    client_id: GSUTIL_CLIENT_ID,
                    client_secret: GSUTIL_CLIENT_SECRET,
                    refresh_token: refresh_token,
                    grant_type: "refresh_token",
                };
                let body = serde_json::to_vec(&req_body)?;
                let req = Request::builder()
                    .method(Method::POST)
                    .uri(OAUTH_REFRESH_TOKEN_ENDPOINT)
                    .body(Body::from(body))?;
                let res = https_client.request(req).await?;
                if res.status().is_success() {
                    let bytes = hyper::body::to_bytes(res.into_body()).await?;
                    let info: OauthTokenResponse = serde_json::from_slice(&bytes)?;
                    let mut access_token = self.access_token.lock().await;
                    *access_token = info.access_token;
                    Ok(())
                } else {
                    bail!("Unable to gain new access token.");
                }
            }
            None => bail!("A refresh token is required to gain new access token."),
        }
    }
async fn refresh_access_token ( & self , https_client : & HttpsClient ) -> Result < ( ) > { match & self . refresh_token { Some ( refresh_token ) => { let req_body = RefreshTokenRequest { client_id : GSUTIL_CLIENT_ID , client_secret : GSUTIL_CLIENT_SECRET , refresh_token : refresh_token , grant_type : " " , } ; let body = serde_json :: to_vec ( & req_body ) ? ; let req = Request :: builder ( ) . method ( Method :: POST ) . uri ( OAUTH_REFRESH_TOKEN_ENDPOINT ) . body ( Body :: from ( body ) ) ? ; let res = https_client . request ( req ) . await ? ; if res . status ( ) . is_success ( ) { let bytes = hyper :: body :: to_bytes ( res . into_body ( ) ) . await ? ; let info : OauthTokenResponse = serde_json :: from_slice ( & bytes ) ? ; let mut access_token = self . access_token . lock ( ) . await ; * access_token = info . access_token ; Ok ( ( ) ) } else { bail ! ( " " ) ; } } None => bail ! ( " " ) , } }
Use the refresh token to get a new access token.
Use the refresh token to get a new access token .
&self
https_client
&HttpsClient