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

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

Open
dorinand opened this issue Feb 18, 2023 · 42 comments

Comments

@dorinand
Copy link

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
Copy link

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:

  • Authenticating with the refresh token doesn't work
  • Authenticating via OAuth works but after a few hours it stops and I have to authorise the datasource again

Screenshot 2023-02-22 at 09 33 21

@Kodikodiko
Copy link

hello! same here

@vv020633
Copy link

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

  • Authenticating with the refresh token opens up the redirect_uri page and Strava fails to connect
  • Authenticating via OAuth seems to connect, but the none of the dashboards seem to be able to connect to the datasource (all raising 401 errors)

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
Copy link
Contributor

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

@vv020633
Copy link

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

@mdrocan
Copy link

mdrocan commented Apr 15, 2023

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
Copy link

mdrocan commented Apr 15, 2023

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
Copy link
Author

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

@mdrocan
Copy link

mdrocan commented Apr 17, 2023

@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
Copy link

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
Copy link
Collaborator

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

@alexanderzobnin
Copy link
Collaborator

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

@alexanderzobnin
Copy link
Collaborator

@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
Copy link

mdrocan commented Aug 10, 2023

@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
Copy link
Collaborator

@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
Copy link

@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
Copy link

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
Copy link

lennon101 commented Sep 12, 2023

@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
Copy link
Collaborator

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

@lennon101
Copy link

lennon101 commented Oct 10, 2023

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
Copy link

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

@dedsxc
Copy link

dedsxc commented Oct 30, 2023

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
Copy link
Collaborator

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

@strandbygaard
Copy link

I'm facing same the same issue.

  • Grafana Cloud
  • Plugin v1.6.1
  • Forward OAuth identity = false
  • Plugin auth via OAuth => enter client id and secret, redirect to Strave and accept, back to Grafan and click "Save and Test" = "Data source is working. Authenticated as ..."

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
Copy link

rofnur commented Jan 2, 2024

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
Copy link

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
Copy link
Collaborator

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

@hopsor
Copy link

hopsor commented Mar 10, 2024

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
Copy link
Collaborator

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

@GKG-ctrl
Copy link

GKG-ctrl commented Mar 25, 2024

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
Copy link

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
Copy link
Collaborator

@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
Copy link
Collaborator

@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
Copy link

GKG-ctrl commented Apr 2, 2024

@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
Copy link
Collaborator

@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
Copy link

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

@alexanderzobnin
Copy link
Collaborator

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

@GKG-ctrl
Copy link

GKG-ctrl commented Apr 2, 2024 via email

@alexanderzobnin
Copy link
Collaborator

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
Copy link

hopsor commented Apr 5, 2024

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

@GKG-ctrl
Copy link

GKG-ctrl commented Apr 6, 2024

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
Copy link
Collaborator

alexanderzobnin commented Apr 9, 2024

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.

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