/// Requests a new GCS OAuth token.
Requests a new GCS OAuth token.
Requests a new GCS OAuth token .
async fn request_new_token(&self, source_key: &GcsSourceKey) -> Result<GcsToken, GcsError> {
        let expires_at = Utc::now() + Duration::minutes(58);
        let auth_jwt = get_auth_jwt(source_key, expires_at.timestamp() + 30)?;
        let request = self
            .client
            .post("https://www.googleapis.com/oauth2/v4/token")
            .form(&OAuth2Grant {
                grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer".into(),
                assertion: auth_jwt,
            });
        let response = request.send().await.map_err(|err| {
            log::debug!("Failed to authenticate against gcs: {}", err);
            GcsError::Auth(err)
        })?;
        let token = response
            .json::<GcsTokenResponse>()
            .await
            .map_err(GcsError::Auth)?;
        Ok(GcsToken {
            access_token: token.access_token,
            expires_at,
        })
    }
async fn request_new_token ( & self , source_key : & GcsSourceKey ) -> Result < GcsToken , GcsError > { let expires_at = Utc :: now ( ) + Duration :: minutes ( 58 ) ; let auth_jwt = get_auth_jwt ( source_key , expires_at . timestamp ( ) + 30 ) ? ; let request = self . client . post ( " " ) . form ( & OAuth2Grant { grant_type : " " . into ( ) , assertion : auth_jwt , } ) ; let response = request . send ( ) . await . map_err ( | err | { log :: debug ! ( " " err ) ; GcsError :: Auth ( err ) } ) ? ; let token = response . json :: < GcsTokenResponse > ( ) . await . map_err ( GcsError :: Auth ) ? ; Ok ( GcsToken { access_token : token . access_token , expires_at , } ) }
Requests a new GCS OAuth token.
Requests a new GCS OAuth token .
&self
source_key
&GcsSourceKey