We tried to use webview to access a dashboard with http header, but it couldn't return proper content

  • What Grafana version and what operating system are you using?
    Grafana 8.5.0. Android R and iOS 15.4

  • What are you trying to achieve?
    I’m using a webview to load the dashboard url with the http header.

  • How are you trying to achieve it?
    In iOS, i’m using URLRequest to add Authorization before URL loading

let webView = WKWebView()
var request = URLRequest(url: url, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData)
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Bearer xxxxx", forHTTPHeaderField: "Authorization")

In Android, i’m using HashMap to add Authorization before URL loading

private Map<String, String> extraHeaders =  new HashMap<String, String>();
extraHeaders.put("Accept", "application/json");
extraHeaders.put("Content-Type", "application/json");
extraHeaders.put("Authorization", "Bearer xxxx");
mWebView.loadUrl( url, extraHeaders);
  • What happened?
    It always return “Access denied to this dashboard”. But it’s fine if we use the Chrome to browse the URL with header. We have no idea why the webview from Android and iOS cannot accesss properly.

  • What did you expect to happen?
    We expect to see the proper dashboard after giving the http header.

  • Can you copy/paste the configuration(s) that you are having problems with?
    The dashbaord is not set up by us. So we don’t have the configurations.

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • Did you follow any online instructions? If so, what is the URL?

Finllay, we found the problem. Because there are a lots request in Grafana. So we couldn’t kust write a header for the original URL. That the reason why we couldn’t log in successfully.
For example, there are some URLs in the page.Like picture or data. We have to write the header as well so that the page can be work properly.