Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/frontend/frontend_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
@app.get("/config.js", response_class=PlainTextResponse)
def get_config():
backend_url = html.escape(os.getenv("BACKEND_API_URL", "http://localhost:8000"))
return f'const BACKEND_API_URL = "{backend_url}";'
auth_enabled = html.escape(os.getenv("AUTH_ENABLED", "True"))
return f'''
const BACKEND_API_URL = "{backend_url}";
const AUTH_ENABLED = "{auth_enabled}";
'''


# Redirect root to app.html
Expand Down
17 changes: 15 additions & 2 deletions src/frontend/wwwroot/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
const closeModalButtons = document.querySelectorAll(".modal-close-button");
const myTasksMenu = document.getElementById("myTasksMenu");
const tasksStats = document.getElementById("tasksStats");

if(AUTH_ENABLED !== undefined) {
setStoredData('authEnabled', AUTH_ENABLED.toString().toLowerCase());
}

//if (!getStoredData('apiEndpoint'))setStoredData('apiEndpoint', apiEndpoint);
// Force rewrite of apiEndpoint
Expand Down Expand Up @@ -51,8 +55,17 @@
try {
const response = await fetch('/.auth/me');
if (!response.ok) {
console.log("No identity provider found. Access to chat will be blocked.");
return null;
if(getStoredData('authEnabled') === 'false'){
//Authentication is disabled. Will use mock user
return {
name: 'Local User',
authenticated: true
}
}
else{
console.log("No identity provider found. Access to chat will be blocked.");
return null;
}
}
const payload = await response.json();

Expand Down
31 changes: 22 additions & 9 deletions src/frontend/wwwroot/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ window.GetAuthDetails = async () => {

// Check if the request is successful
if (!authResponse.ok) {
if(getStoredData('authEnabled') === 'false') {
//Authentication is disabled. Will use mock user
console.log("Authentication Disabled. Using mock user details.");

const headers = getMockUserHeaders();

return headers;
}
console.log("Failed to fetch authentication details. Access to chat will be blocked.");
return null;
}
Expand Down Expand Up @@ -47,25 +55,30 @@ window.GetAuthDetails = async () => {
// This code runs locally so setup mock headers
console.log("Running locally. Skipping authentication details fetch.");

const headers = getMockUserHeaders();

return headers;
}

function getMockUserHeaders() {
const mockUserDetails = {
client_principal: 'mock-client-principal-id',
user_claims: [
{ typ: 'http://schemas.microsoft.com/identity/claims/objectidentifier', val: '12345678-abcd-efgh-ijkl-9876543210ab' }, // Mock Object ID
{ typ: 'name', val: 'Local User' }, // Mock Name
{ typ: 'email', val: '[email protected]' }, // Mock Email (optional claim)
{ typ: 'http://schemas.microsoft.com/identity/claims/objectidentifier', val: '12345678-abcd-efgh-ijkl-9876543210ab' }, // Mock Object ID
{ typ: 'name', val: 'Local User' }, // Mock Name
{ typ: 'email', val: '[email protected]' }, // Mock Email (optional claim)
],
identity_provider: 'mock-identity-provider', // Mock Identity Provider
};
const headers = {
};

const headers = {
'Content-Type': 'application/json',
'X-Ms-Client-Principal': mockUserDetails.client_principal || '',
'X-Ms-Client-Principal-Id': mockUserDetails.user_claims?.find(claim => claim.typ === 'http://schemas.microsoft.com/identity/claims/objectidentifier')?.val || '',
'X-Ms-Client-Principal-Name': mockUserDetails.user_claims?.find(claim => claim.typ === 'name')?.val || '',
'X-Ms-Client-Principal-Idp': mockUserDetails.identity_provider || '',
};

return headers;
};
return headers;
}
};

Expand Down
Loading