From 04df92ab47119abcdafea0642b24462b13cdacdf Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Tue, 9 May 2023 11:47:20 +0200 Subject: [PATCH] Docs: Update backend plugin forwarding of headers (#67913) Co-authored-by: Will Browne Co-authored-by: Joseph Perez <45749060+josmperez@users.noreply.github.com> --- .../plugins/add-authentication-for-data-source-plugins.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/sources/developers/plugins/add-authentication-for-data-source-plugins.md b/docs/sources/developers/plugins/add-authentication-for-data-source-plugins.md index 829220f4408..aac94865702 100644 --- a/docs/sources/developers/plugins/add-authentication-for-data-source-plugins.md +++ b/docs/sources/developers/plugins/add-authentication-for-data-source-plugins.md @@ -291,7 +291,7 @@ To allow Grafana to pass the access token to the plugin, update the data source When configured, Grafana can forward authorization HTTP headers such as `Authorization` or `X-ID-Token` to a backend data source. This information is available across the `QueryData`, `CallResource` and `CheckHealth` requests. -To get Grafana to forward the headers, create a HTTP client using the [Grafana Plugin SDK](https://pkg.go.dev/github.com/grafana/grafana-plugin-sdk-go/backend/httpclient). This package exposes request information which can be subsequently forwarded downstream and/or used directly within the plugin. +To get Grafana to forward the headers, create a HTTP client using the [Grafana plugin SDK for Go](https://pkg.go.dev/github.com/grafana/grafana-plugin-sdk-go/backend/httpclient) and set the `ForwardHTTPHeaders` option to `true` (by default, it's set to `false`). This package exposes request information which can be subsequently forwarded downstream and/or used directly within the plugin. ```go func NewDatasource(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) { @@ -299,6 +299,9 @@ func NewDatasource(settings backend.DataSourceInstanceSettings) (instancemgmt.In if err != nil { return nil, fmt.Errorf("http client options: %w", err) } + + opts.ForwardHTTPHeaders = true + // Important to reuse the same client for each query, to avoid using all available connections on a host cl, err := httpclient.New(opts) if err != nil {