grafana / grafana-infinity-datasource

CSV, JSON, GraphQL, XML and HTML datasource for grafana.
https://grafana.com/docs/plugins/yesoreyeram-infinity-datasource
Apache License 2.0
761 stars 102 forks source link

[Bug] oauth2 does not reauthenticate after credentials time out #781

Open misilot opened 8 months ago

misilot commented 8 months ago

Describe the bug

oauth2 credentials are not refreshed with the refresh_token, or a new access_token is not requested after getting 401 error.

Steps to reproduce

Setup Datasource with OAuth2 and wait try and use it after the token expires.

Sample Data

Error:

grafana-1  | logger=plugin.yesoreyeram-infinity-datasource t=2024-02-29T22:56:33.595876483Z level=info msg="performing QueryData in infinity datasource" dsName="Sensource Traffic" filterExpression= settings.OAuth2Settings.OAuth2Type=client_credentials uql= url=https://vea.sensourceinc.com/api/sensor parser=simple pluginID=yesoreyeram-infinity-datasource root_selector= source=url summarizeExpression= endpoint=queryData uname="Library SysAdmin" dsUID=fb59f297-8028-4b2b-8a7e-6a4c550b51cc settings.AuthenticationMethod=oauth2 type=json
grafana-1  | logger=plugin.yesoreyeram-infinity-datasource t=2024-02-29T22:56:33.607778125Z level=error msg="error while performing the infinity query" dsUID=fb59f297-8028-4b2b-8a7e-6a4c550b51cc pluginID=yesoreyeram-infinity-datasource uname="Library SysAdmin" dsName="Sensource Traffic" endpoint=queryData msg="401 Unauthorized"
grafana-1  | logger=context userId=1 orgId=1 uname=admin t=2024-02-29T22:56:33.609358772Z level=info msg="Request Completed" method=POST path=/api/ds/query status=400 remote_addr=68.102.21.228 time_ms=21 duration=21.737161ms size=8113 referer="https://dashboard/d/cf59f75b-4812-4675-bf18-4d1a625c2126/sensource?editIndex=0&editview=templating&orgId=1" handler=/api/ds/query

Version Details:

Additional context

Add any other context about the problem here.

yesoreyeram commented 8 months ago

Hiya.. sorry you are having trouble. We have be using oauth2 with several other providers without issue. Can you help us exact steps to reproduce with some endpoint which we can access.?

jcpalumbo commented 6 months ago

Same issue here. The connection is made when doing the "Test and Save" via the health check screen. Then after the connection times out or I manually revoke the connection on the Salesforce side the 401 happen.
@yesoreyeram do you still need access to an endpoint where this is happening?

yesoreyeram commented 5 months ago

@jcpalumbo - Yes James. Still I need access to some endpoint where I should be able to reproduce the issue.

jcpalumbo commented 5 months ago

From what I can tell in my case Salesforce does not use a refresh token with the Client Credentials flow. Once the token expires you need to just get another token using the client id and secret. I should be able setup a sandbox connection for you to test if this makes since.

gmarsay commented 4 months ago

Same problem, I get a 401 once my token is revoked