Skip to content

Commit 0be84dc

Browse files
committed
Update to allow the site to work with Windows Auth and also when published to an application in IIS.
1 parent ae62bb9 commit 0be84dc

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

src/Serilog.Ui.Web/Extensions/AuthorizationOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class AuthorizationOptions
1616
public enum AuthenticationType
1717
{
1818
Cookie,
19-
Jwt
19+
Jwt,
20+
Windows
2021
}
2122
}

src/Serilog.Ui.Web/wwwroot/dist/main.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,40 +103,50 @@ const routePrefix = {
103103
}
104104

105105
const init = (config) => {
106-
if (config.authType === "Cookie") {
106+
if (config.authType === "Jwt") {
107+
initTokenUi();
108+
} else {
107109
$("#jwtModalBtn").remove();
108110
sessionStorage.removeItem("serilogui_token");
109-
} else {
110-
initTokenUi();
111111
}
112112

113113
routePrefix.setUrl = config.routePrefix;
114-
fetchData();
114+
fetchData(config.authType);
115115
}
116116

117-
const fetchData = () => {
117+
const fetchData = (authType) => {
118118
const tbody = $("#logTable tbody");
119119
const page = $("#page").val();
120120
const count = $("#count").children("option:selected").val();
121121
const level = $("#level").children("option:selected").val();
122122
const searchTerm = escape($("#search").val());
123-
const url = `/${routePrefix.url}/api/logs?page=${page}&count=${count}&level=${level}&search=${searchTerm}`;
123+
const url = `${location.pathname.replace("/index.html", "")}/api/logs?page=${page}&count=${count}&level=${level}&search=${searchTerm}`;
124124
const token = sessionStorage.getItem("serilogui_token");
125-
$.ajaxSetup({ headers: { 'Authorization': token } });
126-
$.get(url, function (data) {
127-
$("#totalLogs").html(data.total);
128-
$("#showingItemsStart").html(data.page);
129-
$("#showingItemsEnd").html(data.count);
130-
$(tbody).empty();
131-
data.logs.forEach(function (log) {
132-
let exception = "";
133-
if (log.exception != undefined) {
134-
exception =
135-
`<a href="#" title="Click to view" class="modal-trigger" data-type="text">
125+
let xf = null;
126+
if (authType !== "Windows")
127+
$.ajaxSetup({ headers: { 'Authorization': token } });
128+
else {
129+
xf = {
130+
withCredentials: true
131+
};
132+
}
133+
$.get({
134+
url: url,
135+
xhrFields: xf,
136+
success: function (data) {
137+
$("#totalLogs").html(data.total);
138+
$("#showingItemsStart").html(data.page);
139+
$("#showingItemsEnd").html(data.count);
140+
$(tbody).empty();
141+
data.logs.forEach(function (log) {
142+
let exception = "";
143+
if (log.exception != undefined) {
144+
exception =
145+
`<a href="#" title="Click to view" class="modal-trigger" data-type="text">
136146
View <span style="display: none">${log.exception}</span>
137147
</a>`;
138-
}
139-
const row = `<tr class="${log.level}">
148+
}
149+
const row = `<tr class="${log.level}">
140150
<td class="text-center">${log.rowNo}</td>
141151
<td class="text-center"><span class="log-level text-white ${levelClass(log.level)}">${log.level}</span></td>
142152
<td class="text-center">${formatDate(log.timestamp)}</td>
@@ -153,9 +163,10 @@ const fetchData = () => {
153163
</a>
154164
</td>
155165
</tr>`;
156-
$(tbody).append(row);
157-
});
158-
paging(data.total, data.count, data.currentPage);
166+
$(tbody).append(row);
167+
});
168+
paging(data.total, data.count, data.currentPage);
169+
}
159170
}).fail(function (error) {
160171
if (error.status === 403) {
161172
console.log(error);

0 commit comments

Comments
 (0)