Datasource Plugin and Oauth2 route

Hi, I’m trying to create a datasource plugin.
The source requires Oauth, I’m able to get a token when I curl the end point

curl -X POST“https://<controller address>/controller/api/oauth/access_token” -d ‘grant_type=client_credentials&client_id=<apiClientName>@<accountName>&client_secret=<clientSecret>’

I’ve hardcoded a route for testing like this:

    ],
    "routes": [
      {
        "path": "controller",
        "url": "https://<controller address>",
        "tokenAuth": {
          "url": "https://<controller address>/controller/api/oauth/access_token",
          "params": {
            "grant_type": "client_credentials",
            "client_id": "<apiClientName>@<accountName>",
            "client_secret": "<clientSecret>"
          }
        }
      }
    ],

When my testDatasource function runs, I get an HTTP Error bad request and in the logs I see this.
t=2021-09-17T15:26:46+0000 lvl=info msg="Authentication to data source failed" logger=data-proxy-log userId=1 orgId=1 uname=admin path=/api/datasources/proxy/14/controller/rest/applications remote_addr=172.17.0.1 referer=http://grafana.staged-by-discourse.com/datasources/edit/14/ body="" statusCode=401

I’ve tried setting my log level to debug/trace but I’m not getting more info. Any ideas how to get more info about the oauth request being made and confirming it was actually made? I don’t see anything in the logs about getting an Oauth token.

I’ve tried running a mock oauth2 container beside my local grafana and can confirm from the logs in that container that the token auth never attempts. The only request Grafana makes is to whatever url is in the testDatasource() function.

Oauth Container I’m testing with

Got this working, I’ve blindly put the route info inside the info block.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.