Skip to content

json_query does not send token in HTTP request #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
noreplyavailable opened this issue Aug 6, 2023 · 5 comments
Closed

json_query does not send token in HTTP request #126

noreplyavailable opened this issue Aug 6, 2023 · 5 comments

Comments

@noreplyavailable
Copy link

  • Rust Version: stable-x86_64-pc-windows-msvc | rustc 1.71.0 (8ede3aae2 2023-07-12)
  • Runtime version: Tokio 1.29.1
  • OS Version: Windows 10 21H2
  • InfluxDB version: 2.7 - Docker

Running the following code:

    pub async fn read_measurement(&self, query_str: &str) -> Result<(), Error> {
        let read_query = ReadQuery::new(query_str);
        let mut result = self.client.json_query(read_query).await?;

        result.deserialize_next::<Measurement>()?
            .series.into_iter()
            .map(|mut value| {
                println!("{:?}", value);
        }).len(); // temporary

        Ok(())
    }

Will result with this error:
thread 'main' panicked at 'called Result::unwrap() on an Err value: AuthorizationError', src\main.rs:51:81

Which would make sense because looking at the raw packet using Wireshark shows that no token is being included in the HTTP request:
image

Causing an Unauthorized response:
image


As apposed to write requests which work fine:
image
image

And regular read requests which also work fine (using query instead of query_json):
image
image

Code used for read:

    pub async fn read(&self, query_str: &str) -> Result<String, Error> {
        let read_query = ReadQuery::new(query_str);
        Ok(self.client.query(read_query).await?)
    }
@msrd0
Copy link
Collaborator

msrd0 commented Aug 7, 2023

Can you share the code that creates your self.client? Did you try calling with_token on the client with the token from your successful request?

@noreplyavailable
Copy link
Author

    pub async fn new(host: &str, db_name: &str, token: &str) -> Result<Self, Error> {
        let client = Client::new(
            format!("http://{}", host), 
            db_name
        ).with_token(token);

        client.ping().await?; // make sure connection is there

        Ok(InfluxDbConnection{
            client
        })

    }

@msrd0
Copy link
Collaborator

msrd0 commented Aug 25, 2023

Possibly related to #123 - CC @Empty2k12

@skreger-datahaven
Copy link

I'm having the same issue using InfluxDB Cloud Serverless (version 3). I was wondering if it's a major version incompatibility (V3) but apparently the token implementation isn't working correctly.

@msrd0
Copy link
Collaborator

msrd0 commented Sep 8, 2023

Should be fixed by #128

@msrd0 msrd0 closed this as completed Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants