grafana / strava-datasource

Strava datasource for Grafana dashboard
MIT License
188 stars 26 forks source link

Strava datasource cannot connect to Strava API - Bad Request or 401 Unauthorized #70

Open dorinand opened 1 year ago

dorinand commented 1 year ago

I installed strava plugin into Grafana. I tried to configure datasource with both options OAuth and Refresh token, bot none of them works.

OAuth

image

When I press Connect with STRASVA, new tab is opened with error:

{
  "message": "Bad Request",
  "errors": [
    {
      "resource": "Application",
      "field": "redirect_uri",
      "code": "invalid"
    }
  ]
}

Refresh token

image

This option show information, that Data source is working.

When I open New Dashboard and switch to my Strava datasource, I receive immediately 401 error:

image

From Strava API dashboard I can see, api calls have been made: image

natellium commented 1 year ago

Let me know if I should open a new issue, but mine seems pretty similar if not the same.

I'm using Cloud Grafana on the latest main (v9.5.0-52717pre (c5ed9391b6)) and the Strava plugin on version 1.5.1.

What I've experienced:

Screenshot 2023-02-22 at 09 33 21

Kodikodiko commented 1 year ago

hello! same here

vv020633 commented 1 year ago

Same here. Running Grafana in docker using the latest tag .

Much like doriand's case, I can see that API requests have made it to my Strava account, but obviously nothing is being retrieved.

quentinlegay commented 1 year ago

Hi, have you tried to clear your web browser cache ?

vv020633 commented 1 year ago

@quentinlegay just tried clearing my cache as well as trying a different browser and I'm met with the same result (401 unauthorized)

mdrocan commented 1 year ago

Having similar issues with Grafana 9.4.7 and and freshly installed Strava Datasource 1.5.1. On Strava side can see that queries are getting to my profile.

mdrocan commented 1 year ago

With a local installation, defining the IP address of the instance resolved the challenge, ie. not using "localhost" definition (like the documentation quickly reading states).

dorinand commented 1 year ago

@mdrocan Hi, can you describe where and what did you configured differently please?

mdrocan commented 1 year ago

@dorinand I added the correct intranet's IP address to Strava's API definition (https://www.strava.com/settings/api) , ie. "Authorization Callback Domain". Ie. I had 'localhost' defined there, like mentioned in https://github.com/grafana/strava-datasource/blob/master/docs/configuration.md, which didn't work. Instead the correct IP address works.

lennon101 commented 1 year ago

This still seems to be a bit broken (might be related to issue #75?). After adding the correct "Authorization Callback Domain" in the strava API settings - which is just my reverse proxy URL for the grafana instance running in docker - I am able to get to the strava authorization screen as shown below:

image

Clicking "Authorize" seems to complete successfully - no errors or logs appear. However, upon clicking "Save & test" I get:

image

Looking at the logs I have:

logger=plugin.grafana-strava-datasource t=2023-06-30T09:32:36.381055227+10:00 level=info msg="Starting background prefetcher"
logger=plugin.grafana-strava-datasource t=2023-06-30T09:32:36.422708919+10:00 level=info msg="Cache has been reset" datasource=Strava
logger=plugin.grafana-strava-datasource t=2023-06-30T09:32:36.813046512+10:00 level=error msg="Token exchange failed: 401 Unauthorized"
logger=plugin.grafana-strava-datasource t=2023-06-30T09:32:36.813098841+10:00 level=error msg="Strava API request error" error="Token exchange failed: 401 Unauthorized"

To add to the issue, I have tried the "Forward OAuth identity" as outlined in the docs, however the docs describe a toggle which is no longer available?

Restart grafana server, then activate Forward OAuth Identity toggle in data source config and press Save and test button.
alexanderzobnin commented 1 year ago

@lennon101 forward oauth identity only available in the latest plugin version 1.6.0.

alexanderzobnin commented 1 year ago

@mdrocan I updated configuration docs, hope it's more clear now.

alexanderzobnin commented 1 year ago

@natellium Unfortunately, there's an issue with Grafana cloud. Since instance starts in the new container every time, the only available long-term storage is a DB. But plugin do not have access to DB, so refresh token will be removed on instance restart.

mdrocan commented 1 year ago

@alexanderzobnin can't remember now in which way did I set it up in my current raspberry in the internal network, but yes it works for me.

alexanderzobnin commented 1 year ago

@mdrocan yes, in case you use grafana at raspberry pi, you need to configure callback domain to exact address you use to open grafana (raspberrypi.local or IP address, depends on how you access it).

iketiunn commented 1 year ago

@natellium Unfortunately, there's an issue with Grafana cloud. Since instance starts in the new container every time, the only available long-term storage is a DB. But plugin do not have access to DB, so refresh token will be removed on instance restart.

I also used this awesome plugin on Grafana Cloud and faced this problem. Thanks for the explanation.

OptimusPrimeLogan commented 1 year ago

I am still facing this issue in both Grafana cloud and and with a docker image as well. Image used: https://hub.docker.com/r/grafana/grafana-enterprise and the latest tag

lennon101 commented 1 year ago

@lennon101 forward oauth identity only available in the latest plugin version 1.6.0.

how do I check what version of the plugin I'm using? and how do I update to the latest version? @alexanderzobnin

alexanderzobnin commented 1 year ago

@lennon101 you can check it from Grafana - Administration - plugins in side navigation menu

lennon101 commented 1 year ago

Ok thanks. I'm now updated and running version 1.6.1 but the issue remains. I am clicking on OAuth --> connect with STRAVA --> which navigates me to the strava auth page --> I tap "authorize" and I am navigated back to Grafana where a pop-up appears in the top right hand corner saying: Token exchange failed: 401 Unauthorized.

System details: Grafana version: v10.1.4 (a676a96d91) running in a docker container Plugin version: 1.6.1

wilkadam commented 1 year ago

Any fix known? Version 1.3.0 works properly, but having the same 401 error when using newer versions.

dedsxc commented 1 year ago

Configured strava datasource 1.6.1 successfully on grafana v10.2.0

image

But when I try to retrieve a data I got a 401 unauthorized

image

config : {url: 'api/datasources/4/resources/strava-api', method: 'POST', headers: {…}, data: {…}, retry: 0, …} data : error : "Internal Server Error" message : "Error status: 401 Unauthorized" [[Prototype]] : Object message : "Error status: 401 Unauthorized" status : 500 statusText : "Internal Server Error" traceId : undefined [[Prototype]] : Object

alexanderzobnin commented 11 months ago

Could you try it with forward identity method? https://github.com/grafana/strava-datasource#forward-oauth-identity

strandbygaard commented 10 months ago

I'm facing same the same issue.

When I click Explore view, I get "Error Status: 401 Unauthorized" when exploring the Strava data source.

If I set "Forward OAuth identity" = true, and click "Save and Test", I also get a 401

If I choose "Auth Type" = "refresh token", and enter details from Strava API application (client id and secret + refresh token), then "Save and Test" always fails.

rofnur commented 10 months ago

I've also failed setting up strava connection with forward oauth identity enabled. Documentation says to configure [auth.generic_oauth] section in grafana but I don't have access to grafana config. At least I was not able to find one. The setup is identical to what @strandbygaard have

wilkadam commented 9 months ago

I was able to get it working, here is what I did: I am using grafana 10.2.0 and promethes:v2.47.2, both are running in docker. Firstly I removed completely the strava plugin and installed it again from here https://grafana.com/grafana/plugins/grafana-strava-datasource/?tab=installation using grafana-cli plugins install grafana-strava-datasource Then i followed this guy from this Youtube tutorial, only where he is configuring his connection to Strava and it worked! https://youtu.be/CgP9hs9UDzA?si=oMk1L-w4Bf75khTW&t=188

alexanderzobnin commented 8 months ago

I've updated plugin authentication, now it should work on Grafana Cloud without re-authentication after instance restart. Upgrade plugin to latest version.

hopsor commented 8 months ago

Hi, I just updated to the latest version (1.7.0) and I'm still having similar issues. Tried connect with strava button and apparently worked but when I go to explore data it warns me with the message that the refresh token is missing

alexanderzobnin commented 8 months ago

Ok, that's strange, I think I noticed a similar issue but after re-connecting everything was fine.

GKG-ctrl commented 7 months ago

Hi, Been at this for days.. I tested grafana cloud and it works like a charm. Everything works as expected. But I want to use my existing grafana using docker on ubuntu server. I am stuck with the following errors please help. Grafana v10.4.1 (d3ce857c0e) Strava plugin 1.70

logger=context userId=1 orgId=1 uname=admin t=2024-03-25T19:37:17.749686766Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=192.168.1.62 time_ms=2 duration=2.257232ms size=0 referer= handler=/api/live/ws status_source=server

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:21.026425305Z level=info msg="Starting background prefetcher"

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:21.026523831Z level=error msg="Error loading refresh token"

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:21.026555422Z level=error msg="Error fetching activities" error="error fetching activities: Refresh token not found, authorize datasource first"

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:21.924226662Z level=error msg="Error saving refresh token" err="Get \"/api/datasources/uid/fdgr8jy7j3caoa\": unsupported protocol scheme \"\""

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:22.022450062Z level=info msg="Cache has been reset" datasource=grafana-strava-datasource

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:22.116460359Z level=error msg="Error loading refresh token"

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:22.116534567Z level=error msg="Strava API request error" error="Refresh token not found, authorize datasource first"

logger=context userId=1 orgId=1 uname=admin t=2024-03-25T19:37:22.117265322Z level=error msg="Request Completed" method=POST path=/api/datasources/21/resources/strava-api status=500 remote_addr=192.168.1.62 time_ms=3 duration=3.804035ms size=97 referer="http://es-docker.jaya:3000/connections/datasources/edit/fdgr8jy7j3caoa?code=76ada3ac08fed6ca5df5c8131ba&scope=read%2Cactivity%3Aread_all%2Cprofile%3Aread_all%2Cread_all&state=" handler=/api/datasources/:id/resources/* status_source=downstream

GKG-ctrl commented 7 months ago

Update!!! plugin version 1.6.0 works!! although it complains about deprecated Angular Plugin!!

Hi, Been at this for days.. I tested grafana cloud and it works like a charm. Everything works as expected. But I want to use my existing grafana using docker on ubuntu server. I am stuck with the following errors please help. Grafana v10.4.1 (d3ce857c0e) Strava plugin 1.70

logger=context userId=1 orgId=1 uname=admin t=2024-03-25T19:37:17.749686766Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=192.168.1.62 time_ms=2 duration=2.257232ms size=0 referer= handler=/api/live/ws status_source=server

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:21.026425305Z level=info msg="Starting background prefetcher"

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:21.026523831Z level=error msg="Error loading refresh token"

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:21.026555422Z level=error msg="Error fetching activities" error="error fetching activities: Refresh token not found, authorize datasource first"

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:21.924226662Z level=error msg="Error saving refresh token" err="Get "/api/datasources/uid/fdgr8jy7j3caoa": unsupported protocol scheme """

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:22.022450062Z level=info msg="Cache has been reset" datasource=grafana-strava-datasource

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:22.116460359Z level=error msg="Error loading refresh token"

logger=plugin.grafana-strava-datasource t=2024-03-25T19:37:22.116534567Z level=error msg="Strava API request error" error="Refresh token not found, authorize datasource first"

logger=context userId=1 orgId=1 uname=admin t=2024-03-25T19:37:22.117265322Z level=error msg="Request Completed" method=POST path=/api/datasources/21/resources/strava-api status=500 remote_addr=192.168.1.62 time_ms=3 duration=3.804035ms size=97 referer="http://es-docker.jaya:3000/connections/datasources/edit/fdgr8jy7j3caoa?code=76ada3ac08fed6ca5df5c8131ba&scope=read%2Cactivity%3Aread_all%2Cprofile%3Aread_all%2Cread_all&state=" handler=/api/datasources/:id/resources/* status_source=downstream

alexanderzobnin commented 7 months ago

@GKG-ctrl seems like the problem is here:

Error saving refresh token" err="Get "/api/datasources/uid/fdgr8jy7j3caoa": unsupported protocol scheme ""

I'll take a look, maybe something was changed in latest grafana

alexanderzobnin commented 7 months ago

@GKG-ctrl what's your root_url config for local grafana? Seems like protocol is empty, so request is failing. I think I can add default http:// prefix if it's not set (grafana does it as well).

GKG-ctrl commented 7 months ago

@alexanderzobnin I am running grafana as a docker container so internally root_url= http://localhost:3000 on my normal LAN I user a custom hostname to access.

@GKG-ctrl what's your root_url config for local grafana? Seems like protocol is empty, so request is failing. I think I can add default http:// prefix if it's not set (grafana does it as well).

alexanderzobnin commented 7 months ago

@GKG-ctrl could you confirm that you have Grafana 10.1 or higher? I added default url just in case, but want to make sure there's no other issues.

alva-seal commented 7 months ago

I have the same error. I use the latest version of Grafana and also have it in a docker container.

alexanderzobnin commented 7 months ago

Ok, maybe docker is a source of problem. I'll test it out.

GKG-ctrl commented 7 months ago

Hi, Yes i am using docker and grafana 10.4.

regards

On Tue, Apr 2, 2024 at 1:23 PM Alexander Zobnin @.***> wrote:

Ok, maybe docker is a source of problem. I'll test it out.

— Reply to this email directly, view it on GitHub https://github.com/grafana/strava-datasource/issues/70#issuecomment-2031751774, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARFG7KEZWO5VD2BPYEL4SSLY3KIMFAVCNFSM6AAAAAAVAR2JO2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZRG42TCNZXGQ . You are receiving this because you were mentioned.Message ID: @.***>

alexanderzobnin commented 7 months ago

I've made some fixes and improvements in auth process, you can upgrade to 1.7.1 and try again. Not sure it fixes your error, I could not manage to replicate it exactly, but have some related fixes.

hopsor commented 7 months ago

Just updated to 1.7.1 and finally worked for me. Thank you so much!

GKG-ctrl commented 7 months ago

Thank you very much! This update worked .. the deprecated angular plugin error remains but that’s a minor issue . It’s working !! I tested on docker and also on homeassistant grafana addon and it also works!

alexanderzobnin commented 7 months ago

deprecated angular plugin error remains but that’s a minor issue

That's a bit strange, I'll double check it. Maybe it's a bug in Grafana, there's definitely no angular code in the plugin.