How to set user name and password in data source plugin?

I am developing a datasource plugin and want to use user name and password saved jasonData and secureJasonData respectively. I tried different ways and did not work.

“routes”: [

{

  "path": "graphdb",

  "url": "http://{{.JsonData.user }}:{{.SecureJsonData.password}}@{{ .JsonData.host }}:{{ .JsonData.port }}/db/neo4j/tx/commit/"

}

],

With above setting, I see following error in Grafana server(version 7.5) log:

t=2021-10-20T15:11:20-0400 lvl=info msg=“Authentication to data source failed” logger=data-proxy-log userId=1 orgId=1 uname=admin path=/api/datasources/proxy/15/graphdb remote_addr=[::1] referer=“http://grafana.staged-by-discourse.com/dashboard/new?inspect=23763571993&inspectTab=query&editPanel=2&orgId=1” body="{\r\n “errors” : [ {\r\n “code” : “Neo.ClientError.Security.Unauthorized”,\r\n “message” : “No authentication header supplied.”\r\n } ]\r\n}" statusCode=401

It works fine like below, but obviously I dont want to hard code…

“routes”: [

{

  "path": "graphdb",

  "url": "http://{{ .JsonData.host }}:{{ .JsonData.port }}/db/neo4j/tx/commit/",

  "headers": [{

    "name" : "Authorization",

    "content" : "Basic bmVvNGo6dGVzdA=="

  }]

}

],

I’m currently facing the same problem: The API key stored in the SecureJsonData object I need to authorize the API request is rejected by our API as being invalid. But when using the API key from the unencrypted JsonData object, everything works great.
I’m currently trying to figure out what exactly the grafana proxy is sending but from the looks of it, this functionality doesn’t work as advertised…

Did you manage to resolve your issue somehow?

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