Skip to content

Commit 1d056a6

Browse files
Merge pull request microsoft#97 from microsoft/dev
feat: merging dev changes to main branch
2 parents 7d90cc6 + ccb7d5a commit 1d056a6

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

src/frontend/frontend_server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
@app.get("/config.js", response_class=PlainTextResponse)
2929
def get_config():
3030
backend_url = html.escape(os.getenv("BACKEND_API_URL", "http://localhost:8000"))
31-
return f'const BACKEND_API_URL = "{backend_url}";'
31+
auth_enabled = html.escape(os.getenv("AUTH_ENABLED", "True"))
32+
return f'''
33+
const BACKEND_API_URL = "{backend_url}";
34+
const AUTH_ENABLED = "{auth_enabled}";
35+
'''
3236

3337

3438
# Redirect root to app.html

src/frontend/wwwroot/app.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
const closeModalButtons = document.querySelectorAll(".modal-close-button");
77
const myTasksMenu = document.getElementById("myTasksMenu");
88
const tasksStats = document.getElementById("tasksStats");
9+
10+
if(AUTH_ENABLED !== undefined) {
11+
setStoredData('authEnabled', AUTH_ENABLED.toString().toLowerCase());
12+
}
913

1014
//if (!getStoredData('apiEndpoint'))setStoredData('apiEndpoint', apiEndpoint);
1115
// Force rewrite of apiEndpoint
@@ -51,8 +55,17 @@
5155
try {
5256
const response = await fetch('/.auth/me');
5357
if (!response.ok) {
54-
console.log("No identity provider found. Access to chat will be blocked.");
55-
return null;
58+
if(getStoredData('authEnabled') === 'false'){
59+
//Authentication is disabled. Will use mock user
60+
return {
61+
name: 'Local User',
62+
authenticated: true
63+
}
64+
}
65+
else{
66+
console.log("No identity provider found. Access to chat will be blocked.");
67+
return null;
68+
}
5669
}
5770
const payload = await response.json();
5871

src/frontend/wwwroot/utils.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ window.GetAuthDetails = async () => {
1919

2020
// Check if the request is successful
2121
if (!authResponse.ok) {
22+
if(getStoredData('authEnabled') === 'false') {
23+
//Authentication is disabled. Will use mock user
24+
console.log("Authentication Disabled. Using mock user details.");
25+
26+
const headers = getMockUserHeaders();
27+
28+
return headers;
29+
}
2230
console.log("Failed to fetch authentication details. Access to chat will be blocked.");
2331
return null;
2432
}
@@ -47,25 +55,30 @@ window.GetAuthDetails = async () => {
4755
// This code runs locally so setup mock headers
4856
console.log("Running locally. Skipping authentication details fetch.");
4957

58+
const headers = getMockUserHeaders();
59+
60+
return headers;
61+
}
62+
63+
function getMockUserHeaders() {
5064
const mockUserDetails = {
5165
client_principal: 'mock-client-principal-id',
5266
user_claims: [
53-
{ typ: 'http://schemas.microsoft.com/identity/claims/objectidentifier', val: '12345678-abcd-efgh-ijkl-9876543210ab' }, // Mock Object ID
54-
{ typ: 'name', val: 'Local User' }, // Mock Name
55-
{ typ: 'email', val: '[email protected]' }, // Mock Email (optional claim)
67+
{ typ: 'http://schemas.microsoft.com/identity/claims/objectidentifier', val: '12345678-abcd-efgh-ijkl-9876543210ab' }, // Mock Object ID
68+
{ typ: 'name', val: 'Local User' }, // Mock Name
69+
{ typ: 'email', val: '[email protected]' }, // Mock Email (optional claim)
5670
],
5771
identity_provider: 'mock-identity-provider', // Mock Identity Provider
58-
};
59-
60-
const headers = {
72+
};
73+
74+
const headers = {
6175
'Content-Type': 'application/json',
6276
'X-Ms-Client-Principal': mockUserDetails.client_principal || '',
6377
'X-Ms-Client-Principal-Id': mockUserDetails.user_claims?.find(claim => claim.typ === 'http://schemas.microsoft.com/identity/claims/objectidentifier')?.val || '',
6478
'X-Ms-Client-Principal-Name': mockUserDetails.user_claims?.find(claim => claim.typ === 'name')?.val || '',
6579
'X-Ms-Client-Principal-Idp': mockUserDetails.identity_provider || '',
66-
};
67-
68-
return headers;
80+
};
81+
return headers;
6982
}
7083
};
7184

0 commit comments

Comments
 (0)