fn check_auth(&mut self) -> Result<()> {
        let auth_valid = {
            let access_until = self.0.read().oauth_context.access_until;
            let has_token = self.0.read().oauth_context.access_token.is_some();
            // Refresh token before expiry
            has_token && access_until.signed_duration_since(Utc::now()) < Duration::seconds(60)
        };

        if !auth_valid {
            // Get write-lock
            let mut lock = self.0.write();

            // Now that we're alone check again, as there could be multiple of these requests in parallel and this thread could have been blocked waiting for a lock all the time
            if lock.oauth_context
                   .access_until
                   .signed_duration_since(Utc::now())
               < Duration::seconds(60)
            {
                info!("Refreshing auth token.");
                let client_id = lock.oauth_context.client_id.clone();
                let secret_key = lock.oauth_context.secret_key.clone();

                let mut body = HashMap::new();
                body.insert("grant_type", "refresh_token");
                body.insert("refresh_token", &lock.oauth_context.refresh_token);

                // Load auth, acquire write lock, check again, then write new data
                let response = lock.http
                                   .post("https://login.eveonline.com/v2/oauth/token")
                                   .basic_auth(client_id, Some(secret_key))
                                   .form(&body)
                                   .send()?;

                let auth_data: types::TokenResponse = unwrap_json(response)?;

                lock.oauth_context.access_token = Some(auth_data.access_token);
                lock.oauth_context.access_until =
                    Utc::now() + Duration::seconds(auth_data.expires_in);
            }
        }

        Ok(())
    }
/// Check if auth info is valid, refesh `access_token` if needed
Check if auth info is valid, refesh `access_token` if needed
Check if auth info is valid refesh ` access_token ` if needed
fn check_auth(&mut self) -> Result<()> {
        let auth_valid = {
            let access_until = self.0.read().oauth_context.access_until;
            let has_token = self.0.read().oauth_context.access_token.is_some();
            // Refresh token before expiry
            has_token && access_until.signed_duration_since(Utc::now()) < Duration::seconds(60)
        };
        if !auth_valid {
            // Get write-lock
            let mut lock = self.0.write();
            // Now that we're alone check again, as there could be multiple of these requests in parallel and this thread could have been blocked waiting for a lock all the time
            if lock.oauth_context
                   .access_until
                   .signed_duration_since(Utc::now())
               < Duration::seconds(60)
            {
                info!("Refreshing auth token.");
                let client_id = lock.oauth_context.client_id.clone();
                let secret_key = lock.oauth_context.secret_key.clone();
                let mut body = HashMap::new();
                body.insert("grant_type", "refresh_token");
                body.insert("refresh_token", &lock.oauth_context.refresh_token);
                // Load auth, acquire write lock, check again, then write new data
                let response = lock.http
                                   .post("https://login.eveonline.com/v2/oauth/token")
                                   .basic_auth(client_id, Some(secret_key))
                                   .form(&body)
                                   .send()?;
                let auth_data: types::TokenResponse = unwrap_json(response)?;
                lock.oauth_context.access_token = Some(auth_data.access_token);
                lock.oauth_context.access_until =
                    Utc::now() + Duration::seconds(auth_data.expires_in);
            }
        }
        Ok(())
    }
fn check_auth ( & mut self ) -> Result < ( ) > { let auth_valid = { let access_until = self . 0 . read ( ) . oauth_context . access_until ; let has_token = self . 0 . read ( ) . oauth_context . access_token . is_some ( ) ; // Refresh token before expiry has_token && access_until . signed_duration_since ( Utc :: now ( ) ) < Duration :: seconds ( 60 ) } ; if ! auth_valid { // Get write-lock let mut lock = self . 0 . write ( ) ; // Now that we're alone check again, as there could be multiple of these requests in parallel and this thread could have been blocked waiting for a lock all the time if lock . oauth_context . access_until . signed_duration_since ( Utc :: now ( ) ) < Duration :: seconds ( 60 ) { info ! ( " " ) ; let client_id = lock . oauth_context . client_id . clone ( ) ; let secret_key = lock . oauth_context . secret_key . clone ( ) ; let mut body = HashMap :: new ( ) ; body . insert ( " " , " " ) ; body . insert ( " " , & lock . oauth_context . refresh_token ) ; // Load auth, acquire write lock, check again, then write new data let response = lock . http . post ( " " ) . basic_auth ( client_id , Some ( secret_key ) ) . form ( & body ) . send ( ) ? ; let auth_data : types :: TokenResponse = unwrap_json ( response ) ? ; lock . oauth_context . access_token = Some ( auth_data . access_token ) ; lock . oauth_context . access_until = Utc :: now ( ) + Duration :: seconds ( auth_data . expires_in ) ; } } Ok ( ( ) ) }
Check if auth info is valid, refesh `access_token` if needed
Check if auth info is valid refesh ` access_token ` if needed
&mut self
&mut self