Fix: Handle withCredentials option properly for loki datasource (#36914)

The loki datasource was not passing the credentials info to the fetch()
API when loki was in Browser access mode.

This is similar to:
https://github.com/grafana/grafana/pull/23380
This commit is contained in:
Fabrice 2021-07-20 08:05:12 -07:00 committed by GitHub
parent 4f315bf48f
commit aa3a46272f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,6 +87,12 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
const baseUrl = this.instanceSettings.url;
const params = data ? serializeParams(data) : '';
const url = `${baseUrl}${apiUrl}${params.length ? `?${params}` : ''}`;
if (this.instanceSettings.withCredentials || this.instanceSettings.basicAuth) {
options = { ...options, withCredentials: true };
if (this.instanceSettings.basicAuth) {
options.headers = { ...options.headers, Authorization: this.instanceSettings.basicAuth };
}
}
const req = {
...options,
url,