pub async fn new_with_code(https_client: &HttpsClient, auth_code: &str) -> Result<Self> {
        if auth_code.is_empty() {
            bail!("Empty auth code passed to new_with_code. Please report this as a bug.");
        }
        // Add POST parameters to exchange the auth_code for a refresh_token
        // and possibly an access_token.
        let body = form_urlencoded::Serializer::new(String::new())
            .append_pair("code", auth_code)
            .append_pair("redirect_uri", "urn:ietf:wg:oauth:2.0:oob")
            .append_pair("client_id", GSUTIL_CLIENT_ID)
            .append_pair("client_secret", GSUTIL_CLIENT_SECRET)
            .append_pair("grant_type", "authorization_code")
            .finish();
        // Build the request and send it.
        let req = Request::builder()
            .method(Method::POST)
            .header("Content-Type", "application/x-www-form-urlencoded")
            .uri(EXCHANGE_AUTH_CODE_URL)
            .body(Body::from(body))?;
        let res = https_client.request(req).await?;

        // If the response was successful, extract the new tokens.
        if res.status().is_success() {
            let bytes = hyper::body::to_bytes(res.into_body()).await?;
            let info: ExchangeAuthCodeResponse = serde_json::from_slice(&bytes)?;
            let access_token = Mutex::new(info.access_token.unwrap_or("".to_string()));
            Ok(Self {
                _api_base: Url::parse(API_BASE).expect("parse API_BASE"),
                storage_base: Url::parse(STORAGE_BASE).expect("parse STORAGE_BASE"),
                refresh_token: Some(info.refresh_token),
                access_token,
            })
        } else {
            bail!("Unable to gain new access token.");
        }
    }
/// Allow access to public and private GCS data.
///
/// The `https_client` will be used to exchange the auth code for a refresh
/// token.
/// The `auth_code` must not be an empty string (this will generate an Err
/// Result.
Allow access to public and private GCS data.
The `https_client` will be used to exchange the auth code for a refresh
token.
The `auth_code` must not be an empty string (this will generate an Err
Result.
Allow access to public and private GCS data . The ` https_client ` will be used to exchange the auth code for a refresh token . The ` auth_code ` must not be an empty string ( this will generate an Err Result .
pub async fn new_with_code(https_client: &HttpsClient, auth_code: &str) -> Result<Self> {
        if auth_code.is_empty() {
            bail!("Empty auth code passed to new_with_code. Please report this as a bug.");
        }
        // Add POST parameters to exchange the auth_code for a refresh_token
        // and possibly an access_token.
        let body = form_urlencoded::Serializer::new(String::new())
            .append_pair("code", auth_code)
            .append_pair("redirect_uri", "urn:ietf:wg:oauth:2.0:oob")
            .append_pair("client_id", GSUTIL_CLIENT_ID)
            .append_pair("client_secret", GSUTIL_CLIENT_SECRET)
            .append_pair("grant_type", "authorization_code")
            .finish();
        // Build the request and send it.
        let req = Request::builder()
            .method(Method::POST)
            .header("Content-Type", "application/x-www-form-urlencoded")
            .uri(EXCHANGE_AUTH_CODE_URL)
            .body(Body::from(body))?;
        let res = https_client.request(req).await?;
        // If the response was successful, extract the new tokens.
        if res.status().is_success() {
            let bytes = hyper::body::to_bytes(res.into_body()).await?;
            let info: ExchangeAuthCodeResponse = serde_json::from_slice(&bytes)?;
            let access_token = Mutex::new(info.access_token.unwrap_or("".to_string()));
            Ok(Self {
                _api_base: Url::parse(API_BASE).expect("parse API_BASE"),
                storage_base: Url::parse(STORAGE_BASE).expect("parse STORAGE_BASE"),
                refresh_token: Some(info.refresh_token),
                access_token,
            })
        } else {
            bail!("Unable to gain new access token.");
        }
    }
pub async fn new_with_code ( https_client : & HttpsClient , auth_code : & str ) -> Result < Self > { if auth_code . is_empty ( ) { bail ! ( " " ) ; } // Add POST parameters to exchange the auth_code for a refresh_token // and possibly an access_token. let body = form_urlencoded :: Serializer :: new ( String :: new ( ) ) . append_pair ( " " , auth_code ) . append_pair ( " " , " " ) . append_pair ( " " , GSUTIL_CLIENT_ID ) . append_pair ( " " , GSUTIL_CLIENT_SECRET ) . append_pair ( " " , " " ) . finish ( ) ; // Build the request and send it. let req = Request :: builder ( ) . method ( Method :: POST ) . header ( " " , " " ) . uri ( EXCHANGE_AUTH_CODE_URL ) . body ( Body :: from ( body ) ) ? ; let res = https_client . request ( req ) . await ? ; // If the response was successful, extract the new tokens. if res . status ( ) . is_success ( ) { let bytes = hyper :: body :: to_bytes ( res . into_body ( ) ) . await ? ; let info : ExchangeAuthCodeResponse = serde_json :: from_slice ( & bytes ) ? ; let access_token = Mutex :: new ( info . access_token . unwrap_or ( " " . to_string ( ) ) ) ; Ok ( Self { _api_base : Url :: parse ( API_BASE ) . expect ( " " ) , storage_base : Url :: parse ( STORAGE_BASE ) . expect ( " " ) , refresh_token : Some ( info . refresh_token ) , access_token , } ) } else { bail ! ( " " ) ; } }
Allow access to public and private GCS data.
Allow access to public and private GCS data .
https_client
&HttpsClient
auth_code
&str
https_client
&HttpsClient
auth_code
&str