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

Refresh token not found error #31

Open
NRKirby opened this issue Mar 3, 2021 · 41 comments
Open

Refresh token not found error #31

NRKirby opened this issue Mar 3, 2021 · 41 comments

Comments

@NRKirby
Copy link

NRKirby commented Mar 3, 2021

Hi,

This looks to be a great plugin but I am having trouble connecting to the Strava API.

I am running a grafana server locally in a docker container but I am getting the following error:

Refresh token not found, authorize datasource first

I have done the following:

  • Install the plugin in the docker container with the following command grafana-cli plugins install grafana-strava-datasource
  • Restart the docker container
  • Create a directory /var/lib/grafana/strava
  • Define an environment variable export GF_STRAVA_DS_DATA_PATH=/var/lib/grafana/strava/
  • Add a datasource specifying the Client ID and Client Secret from an app created in my Strava account
  • I get the following messages

image

Do you know how I can solve this issue please?

@tdosek
Copy link

tdosek commented Mar 13, 2021

I have the same problem using grafana 7.3.6 installed from Fedora RPM

I've set the env variables in /etc/environment to make sure they're available to all users (including nologin ones like grafana).
Created the directory and set correct permissions:
drwxr-xr-x. 5 grafana grafana system_u:object_r:var_lib_t:s0 4096 12. mar 18.01 plugins
drwx------. 2 grafana grafana system_u:object_r:var_lib_t:s0 4096 12. mar 09.43 png
drwxr-xr-x. 2 grafana grafana system_u:object_r:var_lib_t:s0 4096 12. mar 18.10 strava

When I attempt to authorize the app and save the token I get the following error in logs:
t=2021-03-13T15:41:21+0100 lvl=dbug msg="Querying for data source via SQL store" logger=datasources id=4 orgId=1
t=2021-03-13T15:41:21+0100 lvl=dbug msg="Initializing new data source instance" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-03-13T15:41:21+0100 lvl=dbug msg="Auth request" logger=plugins.backend pluginId=grafana-strava-datasource req=map[authCode:466b8b41635668d22a27571df7655a24c12382d3]
t=2021-03-13T15:41:22+0100 lvl=dbug msg="Got new refresh token" logger=plugins.backend pluginId=grafana-strava-datasource refresh token=99ed46a1f073026bc1e45fa7954e14a5eac8ff8b
t=2021-03-13T15:41:22+0100 lvl=dbug msg="2021-03-13T15:41:22.067+0100 [DEBUG] strava-ds-cache: Saving key to file: key=refreshToken path=/4-refreshToken" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-03-13T15:41:22+0100 lvl=eror msg="Error saving refresh token" logger=plugins.backend pluginId=grafana-strava-datasource EXTRA_VALUE_AT_END="open /4-refreshToken: permission denied"

As usually I tried blaming SELinux first, but that does not seem to be the problem since the very same issue happens with it being turned off. Altering folder permissions has not worked as well.

Callback domain is set to my IP. It'd seem everything is configured just as it should be. :(

@clanzett
Copy link

Same here...

@yihong0618
Copy link
Contributor

yihong0618 commented Apr 13, 2021

You can delete the plugin and re auth.

  1. delete this data source plugin
  2. add it add auth from strava again
  3. click Save and test

@alexanderzobnin
Copy link
Collaborator

That might be an access issue, check for details in logs.

@memphisraines87
Copy link

Same problem, When i pressed Save & Test, same error:
image

Log:
t=2021-05-20T17:17:23+0300 lvl=dbug msg="Querying for data source via SQL store" logger=datasources id=8 orgId=1
t=2021-05-20T17:17:23+0300 lvl=dbug msg="Loading refresh token from file" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-05-20T17:17:23+0300 lvl=dbug msg="2021-05-20T17:17:23.137+0300 [DEBUG] strava-ds-cache: Loading key from file: key=refreshToken path=/8-refreshToken" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-05-20T17:17:23+0300 lvl=eror msg="open /8-refreshToken: no such file or directory" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-05-20T17:17:23+0300 lvl=eror msg="Strava API request error" logger=plugins.backend pluginId=grafana-strava-datasource error="Refresh token not found, authorize datasource first"
t=2021-05-20T17:17:23+0300 lvl=eror msg="Request Completed" logger=context userId=2 orgId=1 uname=skc method=POST path=/api/datasources/8/resources/strava-api status=500 remote_addr=192.168.2.7 time_ms=14 size=97 referer="http://192.168.2.230:3000/datasources/edit/8/?state=&code=8d6f543a28159d89c89cae24e5b7a83ec04d782b&scope=read,activity:read_all,profile:read_all,read_all"

I make:
mkdir /var/lib/grafana/strava
export GF_STRAVA_DS_DATA_PATH=/var/lib/grafana/strava

Also i make
export GF_STRAVA_DS_DATA_PATH=/tmp

Not work!

Strava API page:
image

I try various versions of grafana, but nothing changed. Grafana server on Debian, ubuntu, same error.

@yihong0618
Copy link
Contributor

You can delete the plugin and re auth.

  1. delete this data source plugin
  2. add it add auth from strava again
  3. click Save and test

@memphisraines87 have you tried this?

@josevnz
Copy link

josevnz commented May 21, 2021

Hello,

This is to confirm the plugin doesn't work. I tried the suggestions posted by other users on this bug-report but none worked.

In my case I'm running Grafana from a Docker container and I tried to set the following

  • raspberrypi
  • raspberrypi.home
  • localhost
  • 172.17.0.4 (ip from inside the docker container)
  • 70e6d9731a76 (name from inside the docker container)

Yet I got this error when I was on the setup page:

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

I ended adding the following to my /etc/hosts, which got me further:

josevnz@raspberrypi:~$ cat /etc/hosts
127.0.0.1 localhost raspberrypi

And then I got asked if I wanted to authorize the plug-in. But then when I got redirected back there was the same initial setup page, blank.

So it seems than Grafana and this Strava do not understand each other. Overly complicated setup :-(

It is possible to feed the refresh Token to Grafana? Force-feed the data required for the plugin to work?

@memphisraines87
Copy link

You can delete the plugin and re auth.

  1. delete this data source plugin
  2. add it add auth from strava again
  3. click Save and test

@memphisraines87 have you tried this?

Yes, I tried, nothing changes.

And then I got asked if I wanted to authorize the plug-in. But then when I got redirected back there was the same initial setup page, blank.

Same problem, after redirect, all fields blank. Manually copy code from redirect URL also doesn't work.

@alexanderzobnin
Copy link
Collaborator

I think the reason might be file access issues. Are you sure grafana user has write access to the dir GF_STRAVA_DS_DATA_PATH? Did you hit Connect with Strava button? After redirecting, auth code should be in the page URL.

@alexanderzobnin
Copy link
Collaborator

In order to debug, check logs after clicking Connect with Strava button and then saving data source after authorizing. There should be something like:

DBUG[05-24|09:54:16] Received command to update data source   logger=datasources url=
DBUG[05-24|09:54:16] Querying for data source via SQL store   logger=datasources id=69 orgId=1
DBUG[05-24|09:54:16] Initializing new data source instance    logger=plugins.backend pluginId=grafana-strava-datasource
DBUG[05-24|09:54:16] Auth request                             logger=plugins.backend pluginId=grafana-strava-datasource req=map[authCode:xxxxxx]
DBUG[05-24|09:54:17] Got new refresh token                    logger=plugins.backend pluginId=grafana-strava-datasource refresh token=xxxxx
DBUG[05-24|09:54:17] 2021-05-24T09:54:17.342+0300 [DEBUG] strava-ds-cache: Saving key to file: key=refreshToken path=/home/alex/development/go/src/github.com/grafana/grafana/data/strava/69-refreshToken logger=plugins.backend pluginId=grafana-strava-datasource
DBUG[05-24|09:54:17] Querying for data source via SQL store   logger=datasources id=69 orgId=1
DBUG[05-24|09:54:17] Strava API query                         logger=plugins.backend pluginId=grafana-strava-datasource url="https://www.strava.com/api/v3/athlete/activities?limit=2&page=1&per_page=2"

In case of file access error:

2021-05-24T09:57:56.720+0300 [DEBUG] strava-ds-cache: Saving key to file: key=refreshToken path=/home/alex/development/go/src/github.com/grafana/grafana/data/strava/69-refreshToken logger=plugins.backend pluginId=grafana-strava-datasource
EROR[05-24|09:57:56] Error saving refresh token               logger=plugins.backend pluginId=grafana-strava-datasource EXTRA_VALUE_AT_END="open /home/alex/development/go/src/github.com/grafana/grafana/data/strava/69-refreshToken: permission denied"

Also, check redirect URLs. When you click Connect with Strava button, you should be redirected to strava and URL should be like:

https://www.strava.com/oauth/authorize?client_id=<your client ID>&response_type=code&redirect_uri=http://localhost:3000/datasources/edit/000000069&approval_prompt=force&scope=read_all,profile:read_all,activity:read_all

Check redirect_uri and make sure it points to your Grafana instance. If it's not a localhost, then domain should match one configured in the Strava application. Click authorize. You'll be redirected to the data source config page. Check the page URL. It should be like:

http://localhost:3000/datasources/edit/000000069?state=&code=<auth code>&scope=read,activity:read_all,profile:read_all,read_all

Make sure URL contains code. Plugin reads this auth code from URL and then exchange it for refresh token, then saves in the file for further usage.

@josevnz Error {"message":"Bad Request","errors":[{"resource":"Application","field":"redirect_uri","code":"invalid"}]} means you havent' set Authorization Callback Domain properly to your Grafana domain, as described in configuration docs.

@alexanderzobnin
Copy link
Collaborator

@tdosek You get Error saving refresh token" logger=plugins.backend pluginId=grafana-strava-datasource EXTRA_VALUE_AT_END="open /4-refreshToken: permission denied error that clearly says your Grafana haven't write access to the file. Config GF_STRAVA_DS_DATA_PATH to path where Grafana has write access.

@alexanderzobnin
Copy link
Collaborator

@NRKirby looks like you forgot to hit Connect with Strava button.

@bullboa
Copy link

bullboa commented May 24, 2021

I am getting this problem as well.
Just tried using a free account on grafana.com.
I installed the plugin, created an API Application on strava.com. Copied Client ID and Client Secret and pasted in the datasource configuration.
When I hit Save & Test I get "Refresh token not found, authorize datasource first".
When I then hit Connect with Strava I get a 400 saying

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

Any ideas?

@alexanderzobnin
Copy link
Collaborator

@bullboa the same issue as above - since you're on the grafana.com domain, you have to configure strava app domain callback to match it, like

Screenshot from 2021-05-24 19-58-27

@memphisraines87
Copy link

memphisraines87 commented May 24, 2021

All steps:

  • New Clear VPS
  • Fresh install Ubuntu 16.04
  • Fresh install Grafana 7.5.7
  • Callback Domain is IP address of my vps without port 3000
  • export GF_STRAVA_DS_DATA_PATH=/var/lib/grafana/strava
  • chmod -R 777 /var/lib/grafana/strava
  • chown -R grafana:grafana /var/lib/grafana/strava

Not work. Same error all time. Again all fields are empty.
After pressed "Connect with strava" no new records in log. Grafana redirects to strava, i pressed Allow, and redirects back to grafana.
After redirect , i get this URL in address bar
http://184.102.219.81:3000/datasources/edit/1/?state=&code=29b7d39797eabb4335921cef50309594cfe4775b&scope=read,activity:read_all,profile:read_all,read_all
After i pressed Save & Test, this records:


t=2021-05-24T21:10:25+0300 lvl=eror msg="Strava API request error" logger=plugins.backend pluginId=grafana-strava-datasource error="Auth error, status: 400 Bad Request"
t=2021-05-24T21:10:25+0300 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=POST path=/api/datasources/1/resources/auth status=500 remote_addr=109.63.170.155 time_ms=659 size=81 referer="http://184.102.219.81:3000/datasources/edit/1/?state=&code=29b7d39797eabb4335921cef50309594cfe4775b&scope=read,activity:read_all,profile:read_all,read_all"
t=2021-05-24T21:10:25+0300 lvl=eror msg="open /1-refreshToken: no such file or directory" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-05-24T21:10:25+0300 lvl=eror msg="Strava API request error" logger=plugins.backend pluginId=grafana-strava-datasource error="Refresh token not found, authorize datasource first"
t=2021-05-24T21:10:25+0300 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=POST path=/api/datasources/1/resources/strava-api status=500 remote_addr=109.63.170.155 time_ms=5 size=97 referer="http://184.102.219.81:3000/datasources/edit/1/?state=&code=29b7d39797eabb4335921cef50309594cfe4775b&scope=read,activity:read_all,profile:read_all,read_all"

@yihong0618
Copy link
Contributor

@bullboa the same issue as above - since you're on the grafana.com domain, you have to configure strava app domain callback to match it, like

Screenshot from 2021-05-24 19-58-27

@alexanderzobnin
Maybe this line caused the error, I had this before, I deleted the plugin than like your steps.
It worked.
image

@yihong0618
Copy link
Contributor

@alexanderzobnin

One idea, can we not auth, just use cliend_id, token, refresh_token to get the activities like other repo, using api.
like https://github.com/strava/go.strava

That may be simple for users.

@alexanderzobnin
Copy link
Collaborator

@yihong0618 Using refresh token from the application page might be a good idea if you're using plugin only for your personal access. But in general, one Strava application can be used for accessing multiple users. In this case each user will have its own refresh token. This is why I went recommended way for Strava authentication. I think I can add support for specifying refresh token for access your own data only.

@yihong0618
Copy link
Contributor

Got it.

@alexanderzobnin
Copy link
Collaborator

@memphisraines87 I'll take a look at the code, maybe there's a bug somewhere, sice error is happening while accessing /auth endpoint.

@sharkoz
Copy link

sharkoz commented May 28, 2021

Same problem here. I created the refreshtoken file manually, chmod 777 it, but it is never written.

The POST to https://.../api/datasources/2/resources/auth gives me a 500 error with message : {"error":"Internal Server Error","message":"Auth error, status: 401 Unauthorized"}

I get the correct callback URL, but with a slash between my datasource ID and the ?state... it's the only difference I see with your explanation earlier :
https://.../datasources/edit/2/?state=&code=MYCODE&scope=read,activity:read_all,profile:read_all,read_all

Here is my full log after clicking 'Connect to strava', 'authorize' and 'save and test' :

t=2021-05-28T10:20:11+0000 lvl=dbug msg="Received command to update data source" logger=datasources url=
t=2021-05-28T10:20:11+0000 lvl=dbug msg="Querying for data source via SQL store" logger=datasources id=2 orgId=1
t=2021-05-28T10:20:11+0000 lvl=dbug msg="Initializing new data source instance" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-05-28T10:20:11+0000 lvl=dbug msg="Auth request" logger=plugins.backend pluginId=grafana-strava-datasource req=map[authCode:bfc3a5bc1e0c9c2281fd083bb48]
t=2021-05-28T10:20:16+0000 lvl=eror msg="Strava API request error" logger=plugins.backend pluginId=grafana-strava-datasource error="Auth error, status: 401 Unauthorized"
t=2021-05-28T10:20:16+0000 lvl=eror msg="Request Completed" logger=context userId=0 orgId=1 uname= method=POST path=/api/datasources/2/resources/auth status=500 remote_addr=192.168.1.XX time_ms=4473 size=82 referer="https://.../datasources/edit/2/?state=&code=bfc3a5bc1e0c9c2281fd083bb48&scope=read,activity:read_all,profile:read_all,read_all"
t=2021-05-28T10:20:16+0000 lvl=dbug msg="Querying for data source via SQL store" logger=datasources id=2 orgId=1
t=2021-05-28T10:20:16+0000 lvl=dbug msg="Loading refresh token from file" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-05-28T10:20:16+0000 lvl=dbug msg="2021-05-28T10:20:16.148Z [DEBUG] strava-ds-cache: Loading key from file: key=refreshToken path=/var/lib/grafana/strava/2-refreshToken" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-05-28T10:20:16+0000 lvl=dbug msg="Refresh token loaded from file" logger=plugins.backend pluginId=grafana-strava-datasource refresh token=
t=2021-05-28T10:20:20+0000 lvl=eror msg="Auth error, status: 401 Unauthorized" logger=plugins.backend pluginId=grafana-strava-datasource
t=2021-05-28T10:20:20+0000 lvl=eror msg="Strava API request error" logger=plugins.backend pluginId=grafana-strava-datasource error="Auth error, status: 401 Unauthorized"
t=2021-05-28T10:20:20+0000 lvl=eror msg="Request Completed" logger=context userId=0 orgId=1 uname= method=POST path=/api/datasources/2/resources/strava-api status=500 remote_addr=192.168.1.XX time_ms=4435 size=82 referer="https://.../datasources/edit/2/?state=&code=bfc3a5bc1e0c9c2281fd083bb48&scope=read,activity:read_all,profile:read_all,read_all"

@yujia21
Copy link

yujia21 commented Jun 8, 2021

Hello, I followed the same steps as @memphisraines87 above after fresh install of grafana 8.0.0 and got the same error, manually creating /.1_refreshToken and giving grafana rights to access that file made it work.

Even though I did export GF_STRAVA_DS_DATA_PATH=/var/lib/grafana/strava it seems like that variable is not taken into account when saving the refresh tokens.

@sharkoz
Copy link

sharkoz commented Jun 8, 2021

I finally made it work after deleting and recreating the datasource from the grafana UI

@beirtipol
Copy link

Here's a top tip: When you double click on the client secret on strava.com/settings/api to copy it, there's an extra space at the end of the client secret so if you paste that extra space in to the datasource UI, you'll get a 401 error and spend half an hour wondering what's gone wrong

@alexanderzobnin
Copy link
Collaborator

I added new option for the authentication. Now you can use refresh token from the application page. This is mostly workaround for people who cannot connect with default option. This way has some limitations - you can only log in by yourself (using default option you can authenticate any Strava user). Also, remember that refresh token can change and old value won't work anymore:

Please expect that this value can change anytime you retrieve a new access token. Once a new refresh token code has been returned, the older code will no longer work.

I ran into some issues while testing - when I used default auth after refresh token, it stopped working and returned 401.

Screenshot from 2021-12-23 17-40-02

@yihong0618
Copy link
Contributor

@alexanderzobnin that is cool

@alexanderzobnin
Copy link
Collaborator

Please, try to check refresh token auth and let me know if issue still persists.

@ebiiim
Copy link

ebiiim commented Jan 9, 2022

Thanks for the super cool plugin!

Just FYI:

I tried the "Connect with Strava" button but got 401. I got the log below so there may be a problem with permissions.

t=2022-01-09T14:24:21+0000 lvl=eror msg="open /var/lib/grafana/strava/1-refreshToken: no such file or directory" logger=plugin.initializer pluginID=grafana-strava-datasource

I deployed Grafana 8.3.3 with the Kubernetes manifest on docs and did mkdir -p /var/lib/grafana/strava with initContainers.

In my case, manually creating 1-refreshToken worked fine.

kubectl exec -it $PODNAME -- /bin/sh
echo $REFRESH_TOKEN > /var/lib/grafana/strava/1-refreshToken
# then click "Save & Test" button

However, since the plugin is also running as grafana user (this is same with the user I used to create 1-refreshToken) so I have no idea why DSCache.Save fails...

@gbmd
Copy link

gbmd commented May 22, 2022

I can confirm the issue...
running grafana 8.5.1 (installed via aptitude)
removed strava plugin, created directory /var/lib/grafana/strava, set environment variable via /etc/environment (so "grafana" user can access it, too)
chown'ed it to grafana, restarted grafana-server

token still gets written to /number-refreshToken

I could workaroung by creating an empty file /number-refreshToken and chown'ing it to the grafana user. before hitting "save and test"

@alexanderzobnin
Copy link
Collaborator

I changed a fallback for data directory, now if GF_STRAVA_DS_DATA_PATH is not set, files will be created in default OS cache directory (under strava-datasource subfolder). Hope, I will fix issues when token is writing into the file in the root directory. Changes were made in 22a87da and 7eaddba.

@alexanderzobnin
Copy link
Collaborator

I think this issue should be fixed in latest release. Please, test it out and let me know if I can close this one.

@Urbansson
Copy link

Hey, I'm still getting errors trying to work with the strava datasource.

When I add it it says everything is fine, but when trying to use it I get:
Error status: 401 Unauthorized
With the following logs

logger=plugin.grafana-strava-datasource t=2022-09-12T09:49:48.67219754Z level=error msg="Strava API request error" error="Error status: 401 Unauthorized"
logger=context traceID=00000000000000000000000000000000 userId=2 orgId=1 uname=<redacted> t=2022-09-12T09:49:48.673140533Z level=error msg="Request Completed" method=POST path=/api/datasources/5/resources/strava-api status=500 remote_addr=10.1.0.41 time_ms=249 duration=249.390115ms size=76 referer="https://grafana.private/explore?left=%7B%22datasource%22% │

Looking in the logs when adding the data source i get the following:

logger=plugin.grafana-strava-datasource t=2022-09-12T09:46:44.184867085Z level=info msg="Starting background prefetcher"
logger=plugin.grafana-strava-datasource t=2022-09-12T09:46:44.196263286Z level=info msg="Cache has been reset" datasource=Strava
logger=plugin.grafana-strava-datasource t=2022-09-12T09:46:44.725947909Z level=error msg="Error fetching activities" error="error fetching activities: Error status: 401 Unauthorized"

But in the gui it reports as a success:
image

I'm running on grafana version v9.1.2 (3c13120cde)

@Urbansson
Copy link

Okay, so after adding trying to add the data source multiple times it finally worked.

First i added the client id and the secret and pressed Save & Test.
After that I pressed the Connect with Strava Button.
Finally I added the Refresh token and it worked.

Seems like there is some improvements that still can be done to make the connect flow easier, but it works!

@ernestre
Copy link

I understand that this is an old issue, but maybe this will help someone.

For some reason in the current latest version 1.7.0 I was getting the same 401, 400s, refresh tokens errors as mentioned by others. When I switched to version 1.6.1 everything started working 🤔 .

Grafana version: v10.4.0 (03f502a94d)

I'm deploying grafana with docker compose like so:

  grafana:
    image: grafana/grafana-enterprise
    container_name: grafana
    restart: unless-stopped
    ports:
     - '3000:3000'
    networks:
      - monitoring
    environment:
      - GF_INSTALL_PLUGINS=grafana-strava-datasource 1.6.1

Steps during dashboard creation

  1. Auth type: OAuth
  2. Copy paste Client ID and Client Secret from strava.com into grafana
  3. Click Connect with STRAVA
  4. Redirect to strava and back to grafana
  5. If Client ID and Client Secret are empty i copy and paste them again
  6. Click Save & test
  7. 🎉

Strava Application details

  • Website: 127.0.0.1:3000
  • Authorization Callback Domain: 127.0.0.1:3000

@alexanderzobnin
Copy link
Collaborator

@ernestre that's a bit strange - I've got no issues with 1.7.0. Could you show exact error you had?

@ernestre
Copy link

ernestre commented Apr 3, 2024

Yep, sure.

logger=context userId=1 orgId=1 uname=admin t=2024-04-03T18:15:43.661196084Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=172.21.0.1 time_ms=1 duration=1.264643ms size=0 referer= handler=/api/live/ws status_source=server
logger=plugin.grafana-strava-datasource t=2024-04-03T18:15:49.030527242Z level=info msg="Starting background prefetcher"
logger=plugin.grafana-strava-datasource t=2024-04-03T18:15:49.030552284Z level=error msg="Error loading refresh token"
logger=plugin.grafana-strava-datasource t=2024-04-03T18:15:49.030567213Z level=error msg="Error fetching activities" error="error fetching activities: Refresh token not found, authorize datasource first"
logger=plugin.grafana-strava-datasource t=2024-04-03T18:15:49.482018355Z level=error msg="Error saving refresh token" err="Get \"/api/datasources/uid/bdhn536yupc74c\": unsupported protocol scheme \"\""
logger=plugin.grafana-strava-datasource t=2024-04-03T18:15:49.508612543Z level=info msg="Cache has been reset" datasource=grafana-strava-datasource
logger=plugin.grafana-strava-datasource t=2024-04-03T18:15:49.517502037Z level=error msg="Error loading refresh token"
logger=plugin.grafana-strava-datasource t=2024-04-03T18:15:49.51753414Z 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-04-03T18:15:49.517847513Z level=error msg="Request Completed" method=POST path=/api/datasources/1/resources/strava-api status=500 remote_addr=172.21.0.1 time_ms=2 duration=2.493297ms size=97 referer="http://localhost:3000/connections/datasources/edit/bdhn536yupc74c?code=4fef8e2f40602f26d40bec225f481ad4443a8c1d&scope=read%2Cact
ivity%3Aread_all%2Cprofile%3Aread_all%2Cread_all&state=" handler=/api/datasources/:id/resources/* status_source=downstream

image

Also there's no Auth Type selection in 1.7.0 compared to 1.6.1, not sure if that's expected.

image

Some logs from 1.6.1 when clicking Connect with strava

logger=context userId=1 orgId=1 uname=admin t=2024-04-03T18:24:22.272728351Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=172.22.0.1 time_ms=1 duration=1.392762ms size=0 referer= handler=/api/live/ws status_source=server

And then after clicking save & test

logger=plugin.grafana-strava-datasource t=2024-04-03T18:25:07.520185524Z level=info msg="Starting background prefetcher"
logger=plugin.grafana-strava-datasource t=2024-04-03T18:25:07.520404774Z level=error msg="Error loading token from file" err="open /var/lib/grafana/strava-datasource/3-refreshToken: no such file or directory"
logger=plugin.grafana-strava-datasource t=2024-04-03T18:25:07.520474472Z level=error msg="Error fetching activities" error="error fetching activities: Refresh token not found, authorize datasource first"
logger=plugin.grafana-strava-datasource t=2024-04-03T18:25:07.830487166Z level=info msg="Cache has been reset" datasource=grafana-strava-datasource

Strangely there are similar errors in 1.6.1 but after clicking save I get a green success message and dashboards are working

@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.

@alexanderzobnin
Copy link
Collaborator

Also, make sure externalServiceAccounts feature is enabled:
https://github.com/grafana/strava-datasource?tab=readme-ov-file#enable-externalserviceaccounts-feature

@alva-seal
Copy link

It did indeed let me authenticate and vie my data, thanks

@ernestre
Copy link

ernestre commented Apr 6, 2024

Also, make sure externalServiceAccounts feature is enabled: https://github.com/grafana/strava-datasource?tab=readme-ov-file#enable-externalserviceaccounts-feature

This was the thing I was missing in 1.7.0 😅 after enabling externalServiceAccounts feature everything started working as expected.

In 1.7.1 everything works also with that env variable and without it, Thanks !

@alexanderzobnin
Copy link
Collaborator

yes, this flag is important for self-hosted grafana. In Grafana Cloud it's enabled by default, so I just forgot to mention it in the docs. Now it's fixed.

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