Skip to content
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

Automatic refresh a Bearer ACCESS TOKEN in inputs.http #11279

Closed
JornDL opened this issue Jun 10, 2022 · 8 comments
Closed

Automatic refresh a Bearer ACCESS TOKEN in inputs.http #11279

JornDL opened this issue Jun 10, 2022 · 8 comments
Labels
plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins support Telegraf questions, may be directed to community site or slack

Comments

@JornDL
Copy link

JornDL commented Jun 10, 2022

Feature Request

Make it possible to refresh a Bearer ACCESS TOKEN in inputs.http

Opening a feature request kicks off a discussion.

Proposal:

To make this possible in inputs.http:

Current behavior:

[[inputs.http]]
urls = ["https://api.netatmo.com/api/gethomecoachsdata?device_id=MAC-ADDRESS"]
headers = {"accept" = "application/json"}
headers = {"Authorization" = "Bearer ACCESS TOKEN"}

This works fine as long as the Bearer ACCESS TOKEN has not expired

Desired behavior:

Automatic refresh of the Bearer ACCESS TOKEN so it does not expire

Use case:

All cases where the Bearer ACCESS TOKEN expires.

Example from Netatmo:

image

@JornDL JornDL added the feature request Requests for new plugin and for new features to existing plugins label Jun 10, 2022
@telegraf-tiger telegraf-tiger bot added the area/json json and json_v2 parser/serialiser related label Jun 10, 2022
@Hipska Hipska added the plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins label Jun 10, 2022
@Hipska
Copy link
Contributor

Hipska commented Jun 10, 2022

Hi @JornDL the bearer_token is read from file at every gather interval. So if you make sure that file is updated on time, telegraf will continue to work.

@JornDL
Copy link
Author

JornDL commented Jun 10, 2022

Hi @Hipska

Can you help me on how to do that, please.

@Hipska
Copy link
Contributor

Hipska commented Jun 10, 2022

Updating a file?

It seems like it isn't even needed when I look at your initial description. It appears that You want to use an Oauth2 service:

  ## OAuth2 Client Credentials. The options 'client_id', 'client_secret', and 'token_url' are required to use OAuth2.
  client_id = "clientid"
  client_secret = "secret"
  token_url = "https://api.netatmo.com/oauth2/token"
  # scopes = ["urn:opc:idm:__myscopes__"]

@Hipska Hipska closed this as completed Jun 10, 2022
@Hipska Hipska added the support Telegraf questions, may be directed to community site or slack label Jun 10, 2022
@telegraf-tiger
Copy link
Contributor

Hello! I recommend posting this question in our Community Slack or Community Page, we have a lot of talented community members there who could help answer your question more quickly. You can also learn more about Telegraf by enrolling at InfluxDB University for free!

Heads up, this issue will be automatically closed after 7 days of inactivity. Thank you!

@Hipska Hipska removed feature request Requests for new plugin and for new features to existing plugins area/json json and json_v2 parser/serialiser related labels Jun 10, 2022
@JornDL
Copy link
Author

JornDL commented Jun 19, 2022

Hi @Hipska

I don't think that you read all my first mail, because

To get access the user has to do a POST to receive an access token and refresh token from Netatmo.

As they they are only valid for a certain time period, the user has to renew them from time to time.

To gather data the user has to do a GET with just the device_id and the access token.

I had to write my own bash script to receive and renew my access tokens, as Telegraf inputs.http can't do it.
I found inspiration from this guy: https://mike-greene.com/blog/2019/1/21/analyzing-fitbit-data-with-telegraf-grafana

@svestenik
Copy link

This issue merits revisit, as there are other REST API's out there that expire tokens at regular intervals. Telegraf should have a mechanism for renewing the bearer token.

@PaJaSoft
Copy link

There are more APIs (e.g. WeatherXM) which work similarly and can't be used in HTTP input plugin by convenient way when Bearer token refreshing isn't supported...

@PaJaSoft
Copy link

PaJaSoft commented May 10, 2024

Can't reopen this issue, so create a new one here, feel free to jump-in and help me to convince developers that this is an important part of the HTTP plugin features set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins support Telegraf questions, may be directed to community site or slack
Projects
None yet
Development

No branches or pull requests

4 participants