diff --git a/src/Serilog.Ui.Web/Extensions/AuthorizationOptions.cs b/src/Serilog.Ui.Web/Extensions/AuthorizationOptions.cs index c7c2c25c..4f6a8350 100644 --- a/src/Serilog.Ui.Web/Extensions/AuthorizationOptions.cs +++ b/src/Serilog.Ui.Web/Extensions/AuthorizationOptions.cs @@ -16,6 +16,7 @@ public class AuthorizationOptions public enum AuthenticationType { Cookie, - Jwt + Jwt, + Windows } } \ No newline at end of file diff --git a/src/Serilog.Ui.Web/wwwroot/dist/main.js b/src/Serilog.Ui.Web/wwwroot/dist/main.js index aafe4071..44f48b36 100644 --- a/src/Serilog.Ui.Web/wwwroot/dist/main.js +++ b/src/Serilog.Ui.Web/wwwroot/dist/main.js @@ -95,6 +95,8 @@ }); })(jQuery); +let authType; + const routePrefix = { url: "", set setUrl(route) { @@ -103,13 +105,15 @@ const routePrefix = { } const init = (config) => { - if (config.authType === "Cookie") { + if (config.authType === "Jwt") { + initTokenUi(); + } else { $("#jwtModalBtn").remove(); sessionStorage.removeItem("serilogui_token"); - } else { - initTokenUi(); } + authType = config.authType; + routePrefix.setUrl = config.routePrefix; fetchData(); } @@ -120,23 +124,33 @@ const fetchData = () => { const count = $("#count").children("option:selected").val(); const level = $("#level").children("option:selected").val(); const searchTerm = escape($("#search").val()); - const url = `/${routePrefix.url}/api/logs?page=${page}&count=${count}&level=${level}&search=${searchTerm}`; + const url = `${location.pathname.replace("/index.html", "")}/api/logs?page=${page}&count=${count}&level=${level}&search=${searchTerm}`; const token = sessionStorage.getItem("serilogui_token"); - $.ajaxSetup({ headers: { 'Authorization': token } }); - $.get(url, function (data) { - $("#totalLogs").html(data.total); - $("#showingItemsStart").html(data.page); - $("#showingItemsEnd").html(data.count); - $(tbody).empty(); - data.logs.forEach(function (log) { - let exception = ""; - if (log.exception != undefined) { - exception = - ` + let xf = null; + if (authType !== "Windows") + $.ajaxSetup({ headers: { 'Authorization': token } }); + else { + xf = { + withCredentials: true + }; + } + $.get({ + url: url, + xhrFields: xf, + success: function (data) { + $("#totalLogs").html(data.total); + $("#showingItemsStart").html(data.page); + $("#showingItemsEnd").html(data.count); + $(tbody).empty(); + data.logs.forEach(function (log) { + let exception = ""; + if (log.exception != undefined) { + exception = + ` View ${log.exception} `; - } - const row = ` + } + const row = ` ${log.rowNo} ${log.level} ${formatDate(log.timestamp)} @@ -153,9 +167,10 @@ const fetchData = () => { `; - $(tbody).append(row); - }); - paging(data.total, data.count, data.currentPage); + $(tbody).append(row); + }); + paging(data.total, data.count, data.currentPage); + } }).fail(function (error) { if (error.status === 403) { console.log(error);