Support custom OAuth response for datasource plugin

I’m building a datasource plugin and use routes in my plugin.json to define the API endpoint with a tokenAuth section describing OAuth authentication.

This is not working because Grafana expects the answer for an authentication to for example list the refresh token as “refresh_token” whereas my endpoint returns “refreshToken”. What can I do?

That sounds non-standard - what are you using for your OAuth and why is it returning refreshToken?

I agree, it’s non-standard. Unfortunately I have no influence over it, it’s a proprietary API. That’s why we can’t have nice things, I guess. Or can I?

We don’t have a way to configure the names of the oauth fields.

It is possible to do it another way but it will be a lot of extra work. We recently added a new hook to Grafana that allows you to have a backend component (written in Go) in your datasource. You can authenticate however you want on the backend - so you could copy the relevant Go code from Grafana into your backend component and tweak it.


I don’t really have a good example of custom auth. I know some custom plugins have done it.

In the sample datasource:

You would do it in the MakeHttpRequest function.

The Stackdriver datasource sort of does some custom auth:

And this is the code in Grafana that does auth for plugin routes and handles refresh tokens (and which Stackdriver calls manually):

We use a library for oauth which expects refresh_token so one way to do it would be to provide your own access token implementation and translate refreshToken to refresh_token:

Hope that helps.

1 Like

Okay, that makes sense. Then we’ll probably take this route. Thanks a lot for your help.