Skip to content

Commit 582162c

Browse files
committed
merging
2 parents 86789ac + 2a5fa2a commit 582162c

File tree

188 files changed

+90009
-1761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+90009
-1761
lines changed

1-Authentication/0-sign-in-vanillajs/App/package-lock.json

Lines changed: 5388 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ciam-sign-in-javascript",
33
"version": "1.0.0",
4-
"description": "Vanilla JavaScript single-page application using MSAL.js to authenticate users against Azure AD Customer Identity Access Management (Azure AD for Customers)",
4+
"description": "Vanilla JavaScript single-page application using MSAL.js to authenticate users against Microsoft Entra External ID",
55
"main": "server.js",
66
"scripts": {
77
"start": "node server.js",
@@ -10,13 +10,13 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13-
"@azure/msal-browser": "^2.37.0",
14-
"express": "^4.18.2",
13+
"@azure/msal-browser": "^3.16.0",
14+
"express": "^4.19.2",
1515
"morgan": "^1.10.0"
1616
},
1717
"devDependencies": {
18-
"jest": "^29.5.0",
19-
"jest-environment-jsdom": "^29.5.0",
20-
"supertest": "^6.3.3"
18+
"jest": "^29.7.0",
19+
"jest-environment-jsdom": "^29.7.0",
20+
"supertest": "^7.0.0"
2121
}
2222
}

1-Authentication/0-sign-in-vanillajs/App/public/authConfig.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
const msalConfig = {
77
auth: {
88
clientId: 'Enter_the_Application_Id_Here', // This is the ONLY mandatory field that you need to supply.
9-
authority: 'https://Enter_the_Tenant_Subdomain_Here.ciamlogin.com/', // Replace the placeholder with your tenant subdomain
10-
redirectUri: '/', // You must register this URI on Azure Portal/App Registration. Defaults to window.location.href e.g. http://localhost:3000/
9+
authority: 'https://Enter_the_Tenant_Subdomain_Here.ciamlogin.com/', // Replace the placeholder with your tenant subdomain
10+
redirectUri: 'http://localhost:3000/redirect', // You must register this URI on Microsoft Entra admin center/App Registration. Defaults to window.location.href e.g. http://localhost:3000/
1111
navigateToLoginRequestUrl: true, // If "true", will navigate back to the original request location before processing the auth code response.
1212
},
1313
cache: {
@@ -65,4 +65,4 @@ if (typeof exports !== 'undefined') {
6565
msalConfig: msalConfig,
6666
loginRequest: loginRequest,
6767
};
68-
}
68+
}
Lines changed: 99 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,99 @@
1-
// Create the main myMSALObj instance
2-
// configuration parameters are located at authConfig.js
3-
const myMSALObj = new msal.PublicClientApplication(msalConfig);
4-
5-
let username = "";
6-
7-
function selectAccount () {
8-
9-
/**
10-
* See here for more info on account retrieval:
11-
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-common/docs/Accounts.md
12-
*/
13-
14-
const currentAccounts = myMSALObj.getAllAccounts();
15-
16-
if (!currentAccounts || currentAccounts.length < 1) {
17-
return;
18-
} else if (currentAccounts.length > 1) {
19-
// Add your account choosing logic here
20-
console.warn("Multiple accounts detected.");
21-
} else if (currentAccounts.length === 1) {
22-
username = currentAccounts[0].username
23-
welcomeUser(currentAccounts[0].username);
24-
updateTable(currentAccounts[0]);
25-
}
26-
}
27-
28-
function handleResponse(response) {
29-
30-
/**
31-
* To see the full list of response object properties, visit:
32-
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/request-response-object.md#response
33-
*/
34-
35-
if (response !== null) {
36-
username = response.account.username
37-
welcomeUser(username);
38-
updateTable(response.account);
39-
} else {
40-
selectAccount();
41-
42-
/**
43-
* If you already have a session that exists with the authentication server, you can use the ssoSilent() API
44-
* to make request for tokens without interaction, by providing a "login_hint" property. To try this, comment the
45-
* line above and uncomment the section below.
46-
*/
47-
48-
// myMSALObj.ssoSilent(silentRequest).
49-
// then((response) => {
50-
// welcomeUser(response.account.username);
51-
// updateTable(response.account);
52-
// }).catch(error => {
53-
// console.error("Silent Error: " + error);
54-
// if (error instanceof msal.InteractionRequiredAuthError) {
55-
// signIn();
56-
// }
57-
// });
58-
}
59-
}
60-
61-
function signIn() {
62-
63-
/**
64-
* You can pass a custom request object below. This will override the initial configuration. For more information, visit:
65-
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/request-response-object.md#request
66-
*/
67-
68-
myMSALObj.loginPopup(loginRequest)
69-
.then(handleResponse)
70-
.catch(error => {
71-
console.error(error);
72-
});
73-
}
74-
75-
function signOut() {
76-
77-
/**
78-
* You can pass a custom request object below. This will override the initial configuration. For more information, visit:
79-
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/request-response-object.md#request
80-
*/
81-
82-
// Choose which account to logout from by passing a username.
83-
const logoutRequest = {
84-
account: myMSALObj.getAccountByUsername(username),
85-
mainWindowRedirectUri: '/signout'
86-
};
87-
88-
myMSALObj.logoutPopup(logoutRequest);
89-
}
90-
91-
selectAccount();
1+
// Create the main myMSALObj instance
2+
// configuration parameters are located at authConfig.js
3+
let myMSALObj;
4+
5+
msal.PublicClientApplication.createPublicClientApplication(msalConfig)
6+
.then((obj) => {
7+
myMSALObj = obj;
8+
})
9+
.catch((error) => {
10+
console.error("Error creating MSAL PublicClientApplication:", error);
11+
});
12+
13+
let username = "";
14+
15+
function selectAccount () {
16+
17+
/**
18+
* See here for more info on account retrieval:
19+
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-common/docs/Accounts.md
20+
*/
21+
22+
const currentAccounts = myMSALObj.getAllAccounts();
23+
24+
if (!currentAccounts || currentAccounts.length < 1) {
25+
return;
26+
} else if (currentAccounts.length > 1) {
27+
// Add your account choosing logic here
28+
console.warn("Multiple accounts detected.");
29+
} else if (currentAccounts.length === 1) {
30+
username = currentAccounts[0].username
31+
welcomeUser(currentAccounts[0].username);
32+
updateTable(currentAccounts[0]);
33+
}
34+
}
35+
36+
function handleResponse(response) {
37+
38+
/**
39+
* To see the full list of response object properties, visit:
40+
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/request-response-object.md#response
41+
*/
42+
43+
if (response !== null) {
44+
username = response.account.username
45+
welcomeUser(username);
46+
updateTable(response.account);
47+
} else {
48+
selectAccount();
49+
50+
/**
51+
* If you already have a session that exists with the authentication server, you can use the ssoSilent() API
52+
* to make request for tokens without interaction, by providing a "login_hint" property. To try this, comment the
53+
* line above and uncomment the section below.
54+
*/
55+
56+
// myMSALObj.ssoSilent(silentRequest).
57+
// then((response) => {
58+
// welcomeUser(response.account.username);
59+
// updateTable(response.account);
60+
// }).catch(error => {
61+
// console.error("Silent Error: " + error);
62+
// if (error instanceof msal.InteractionRequiredAuthError) {
63+
// signIn();
64+
// }
65+
// });
66+
}
67+
}
68+
69+
function signIn() {
70+
71+
/**
72+
* You can pass a custom request object below. This will override the initial configuration. For more information, visit:
73+
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/request-response-object.md#request
74+
*/
75+
loginRequest.redirectUri = "/redirect";
76+
myMSALObj.loginPopup(loginRequest)
77+
.then(handleResponse)
78+
.catch(error => {
79+
console.error(error);
80+
});
81+
}
82+
83+
function signOut() {
84+
85+
/**
86+
* You can pass a custom request object below. This will override the initial configuration. For more information, visit:
87+
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/request-response-object.md#request
88+
*/
89+
90+
// Choose which account to logout from by passing a username.
91+
const logoutRequest = {
92+
account: myMSALObj.getAccount({ username: username }),
93+
mainWindowRedirectUri: '/signout'
94+
};
95+
96+
myMSALObj.logoutPopup(logoutRequest);
97+
}
98+
99+
selectAccount();

0 commit comments

Comments
 (0)