Login

In order to perform operations with the Report Server you have to authenticate first. This can be done by sending a request to the Token endpoint with your credentials and as result get an access token.

Here is a sample code snippet which demonstrates how to login and get the token:

  var serverHost = "http://reportserver:83/";
  var serverApi = serverHost + "api/reportserver/";

  function login(username, password) {

    var accessToken = "";

    $.ajax({
      type: "POST",
      url: serverHost + "Token",
      async: false,
      data: {
        grant_type: "password",
        username: username,
        password: password
      }
    })
    .done(function (data, textStatus, jqXHR) {
      accessToken = data.access_token;
    })
    .fail(function (xhr, status, error) {
      window.alert(xhr.status + ": " + error);
    });

    return accessToken;
  }

Once you get the access token, you can store it in window.sessionStorage and later use it in subsequent requests.

For example:

  var serverTokenKey = "TelerikReportServerToken";

  $(document).ready(function () {
    var accessToken =
      login("telerik", "telerik");
    window.sessionStorage.setItem(serverTokenKey, accessToken);
  })

To use the "anonymous" user you have to first enable it from the Report Server management application.
In order to log in as an anonymous user you have to pass empty strings both for the username and the password.