Skip to content

Commit d8dd5ae

Browse files
committed
revise readmes
1 parent 3ced3e9 commit d8dd5ae

116 files changed

Lines changed: 1297 additions & 5920 deletions

File tree

Some content is hidden

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

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ What kind of change does this Pull Request introduce?
4040
npm install
4141
```
4242

43-
* Test the code
44-
45-
<!-- Add steps to run the tests suite and/or manually test -->
46-
47-
```console
48-
49-
```
50-
5143
## What to check
5244

5345
ex: verify that the following are valid:

1-Authentication/1-sign-in/App/app.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,38 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License.
44
*/
5+
56
const express = require('express');
67
const session = require('express-session');
7-
const bodyParser = require('body-parser');
88
const path = require('path');
99

1010
const router = require('./routes/router');
11-
1211
const SERVER_PORT = process.env.PORT || 4000;
1312

14-
const app = express();
13+
// initialize express
14+
const app = express();
1515

1616
app.set('views', path.join(__dirname, './views'));
1717
app.set('view engine', 'ejs');
1818

1919
app.use('/css', express.static(path.join(__dirname, 'node_modules/bootstrap/dist/css')));
2020
app.use('/js', express.static(path.join(__dirname, 'node_modules/bootstrap/dist/js')));
2121

22-
app.use(bodyParser.urlencoded({extended: false}));
22+
app.use(express.urlencoded({ extended: false }));
2323

2424
app.use(express.static(path.join(__dirname, './public')));
2525

26-
app.use(session({secret: 'your-secret', resave: false, saveUninitialized: false}));
26+
app.use(express.json());
27+
28+
/**
29+
* Using express-session middleware. Be sure to familiarize yourself with available options
30+
* and set as desired. Visit: https://www.npmjs.com/package/express-session
31+
*/
32+
app.use(session({
33+
secret: 'ENTER_YOUR_SECRET_HERE',
34+
resave: false,
35+
saveUninitialized: false
36+
}));
2737

2838
app.use(router);
2939

1-Authentication/1-sign-in/App/controllers/mainController.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ exports.getHomePage = (req, res, next) => {
44
}
55

66
exports.getIdPage = (req, res, next) => {
7-
console.log(req.session.account);
87
const isAuthenticated = req.session.isAuthenticated;
98

109
const claims = {
File renamed without changes.

1-Authentication/1-sign-in/App/routes/router.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const express = require('express');
22

33
const mainController = require('../controllers/mainController');
44

5-
const config = require('../../auth.json');
5+
const config = require('../../appSettings.json');
66
const cache = require('../utils/cachePlugin');
77
const msalWrapper = require('msal-express-wrapper');
88

@@ -16,12 +16,12 @@ const router = express.Router();
1616
router.get('/', (req, res, next) => res.redirect('/home'));
1717
router.get('/home', mainController.getHomePage);
1818

19-
// // authentication routes
19+
// authentication routes
2020
router.get('/signin', authProvider.signIn);
2121
router.get('/signout', authProvider.signOut);
2222
router.get('/redirect', authProvider.handleRedirect);
2323

24-
// authenticated routes
24+
// secure routes
2525
router.get('/id', authProvider.isAuthenticated, mainController.getIdPage);
2626

2727
// 404

1-Authentication/1-sign-in/App/utils/cachePlugin.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const fs = require("fs");
2-
const cachePath = './cache.json' // replace this string with the path to your valid cache file.
2+
const cachePath = './App/data/cache.json' // replace this string with the path to your valid cache file.
3+
4+
/**
5+
* This implements ICachePlugin for persistent caching. For more information, visit:
6+
* https://azuread.github.io/microsoft-authentication-library-for-js/ref/interfaces/_azure_msal_common.icacheplugin.html
7+
*/
38

49
const beforeCacheAccess = async (cacheContext) => {
510
return new Promise(async (resolve, reject) => {
@@ -13,7 +18,7 @@ const beforeCacheAccess = async (cacheContext) => {
1318
}
1419
});
1520
} else {
16-
fs.writeFile(cachePath, cacheContext.tokenCache.serialize(), (err) => {
21+
fs.writeFile(cachePath, cacheContext.tokenCache.serialize(), (err) => {
1722
if (err) {
1823
reject();
1924
}
@@ -23,7 +28,7 @@ const beforeCacheAccess = async (cacheContext) => {
2328
};
2429

2530
const afterCacheAccess = async (cacheContext) => {
26-
if(cacheContext.cacheHasChanged){
31+
if (cacheContext.cacheHasChanged) {
2732
await fs.writeFile(cachePath, cacheContext.tokenCache.serialize(), (err) => {
2833
if (err) {
2934
console.log(err);

1-Authentication/1-sign-in/AppCreationScripts/AppCreationScripts.md

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
1-
# Registering the sample apps with the Microsoft identity platform and updating the configuration files using PowerShell
1+
# Registering sample apps with the Microsoft identity platform and updating the configuration files using PowerShell
22

33
## Overview
44

55
### Quick summary
66

7-
1. On Windows run PowerShell as **Administrator** and navigate to the root of the cloned directory
7+
1. On Windows, run PowerShell as **Administrator** and navigate to the root of the cloned directory
88
1. In PowerShell run:
99

1010
```PowerShell
1111
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
1212
```
1313

14-
1. Run the script to create your Azure AD application and configure the code of the sample application accordingly. (Other ways of running the scripts are described below)
14+
1. Run the script to create your Azure AD application and configure the code of the sample application accordingly.
1515

1616
```PowerShell
1717
cd .\AppCreationScripts\
1818
.\Configure.ps1
1919
```
2020

21-
1. Open the Visual Studio solution and click start
22-
2321
### More details
2422

25-
The following paragraphs:
26-
27-
- [Registering the sample apps with the Microsoft identity platform and updating the configuration files using PowerShell](#Registering-the-sample-apps-with-the-Microsoft-identity-platform-and-updating-the-configuration-files-using-PowerShell)
28-
- [Overview](#Overview)
29-
- [Quick summary](#Quick-summary)
30-
- [More details](#More-details)
31-
- [Goal of the provided scripts](#Goal-of-the-provided-scripts)
32-
- [Presentation of the scripts](#Presentation-of-the-scripts)
33-
- [Usage pattern for tests and DevOps scenarios](#Usage-pattern-for-tests-and-DevOps-scenarios)
34-
- [How to use the app creation scripts?](#How-to-use-the-app-creation-scripts)
35-
- [Pre-requisites](#Pre-requisites)
36-
- [Run the script and start running](#Run-the-script-and-start-running)
37-
- [Four ways to run the script](#Four-ways-to-run-the-script)
38-
- [Option 1 (interactive)](#Option-1-interactive)
39-
- [Option 2 (non-interactive)](#Option-2-non-interactive)
40-
- [Option 3 (Interactive, but create apps in a specified tenant)](#Option-3-Interactive-but-create-apps-in-a-specified-tenant)
41-
- [Option 4 (non-interactive, and create apps in a specified tenant)](#Option-4-non-interactive-and-create-apps-in-a-specified-tenant)
42-
- [Running the script on Azure Sovereign clouds](#Running-the-script-on-Azure-Sovereign-clouds)
23+
- [Goal of the provided scripts](#goal-of-the-provided-scripts)
24+
- [Presentation of the scripts](#presentation-of-the-scripts)
25+
- [Usage pattern for tests and DevOps scenarios](#usage-pattern-for-tests-and-DevOps-scenarios)
26+
- [How to use the app creation scripts?](#how-to-use-the-app-creation-scripts)
27+
- [Pre-requisites](#pre-requisites)
28+
- [Run the script and start running](#run-the-script-and-start-running)
29+
- [Four ways to run the script](#four-ways-to-run-the-script)
30+
- [Option 1 (interactive)](#option-1-interactive)
31+
- [Option 2 (non-interactive)](#option-2-non-interactive)
32+
- [Option 3 (Interactive, but create apps in a specified tenant)](#option-3-Interactive-but-create-apps-in-a-specified-tenant)
33+
- [Option 4 (non-interactive, and create apps in a specified tenant)](#option-4-non-interactive-and-create-apps-in-a-specified-tenant)
34+
- [Running the script on Azure Sovereign clouds](#running-the-script-on-Azure-Sovereign-clouds)
4335

4436
## Goal of the provided scripts
4537

@@ -51,13 +43,13 @@ These scripts are:
5143

5244
- `Configure.ps1` which:
5345
- creates Azure AD applications and their related objects (permissions, dependencies, secrets),
54-
- changes the configuration files in the C# and JavaScript projects.
46+
- changes the configuration files in the sample projects.
5547
- creates a summary file named `createdApps.html` in the folder from which you ran the script, and containing, for each Azure AD application it created:
5648
- the identifier of the application
5749
- the AppId of the application
5850
- the url of its registration in the [Azure portal](https://portal.azure.com).
5951

60-
- `Cleanup.ps1` which cleans-up the Azure AD objects created by `Configure.ps1`. Note that this script does not revert the changes done in the configuration files, though. You will need to undo the change from source control (from Visual Studio, or from the command line using, for instance, git reset).
52+
- `Cleanup.ps1` which cleans-up the Azure AD objects created by `Configure.ps1`. Note that this script does not revert the changes done in the configuration files, though. You will need to undo the change from source control (from Visual Studio, or from the command line using, for instance, `git reset`).
6153

6254
### Usage pattern for tests and DevOps scenarios
6355

@@ -81,15 +73,15 @@ The scripts install the required PowerShell module (AzureAD) for the current use
8173
8274
1. If you have never done it already, in the PowerShell window, install the AzureAD PowerShell modules. For this:
8375
84-
1. Open PowerShell as admin (On Windows, Search Powershell in the search bar, right click on it and select Run as administrator).
76+
1. Open PowerShell as admin (On Windows, Search Powershell in the search bar, right click on it and select **Run as administrator**).
8577
2. Type:
86-
78+
8779
```PowerShell
8880
Install-Module AzureAD
8981
```
9082
9183
or if you cannot be administrator on your machine, run:
92-
84+
9385
```PowerShell
9486
Install-Module AzureAD -Scope CurrentUser
9587
```
@@ -106,22 +98,22 @@ The scripts install the required PowerShell module (AzureAD) for the current use
10698
1. Open the Visual Studio solution, and in the solution's context menu, choose **Set Startup Projects**.
10799
1. select **Start** for the projects
108100
109-
You're done. this just works!
101+
You're done!
110102
111103
### Four ways to run the script
112104
113105
We advise four ways of running the script:
114106
115107
- Interactive: you will be prompted for credentials, and the scripts decide in which tenant to create the objects,
116108
- non-interactive: you will provide credentials, and the scripts decide in which tenant to create the objects,
117-
- Interactive in specific tenant: you will provide the tenant in which you want to create the objects and then you will be prompted for credentials, and the scripts will create the objects,
118-
- non-interactive in specific tenant: you will provide tenant in which you want to create the objects and credentials, and the scripts will create the objects.
109+
- Interactive in specific tenant: you will provide the tenant in which you want to create the objects and then you will be prompted for credentials, and the scripts will create the objects,
110+
- non-interactive in specific tenant: you will provide the tenant in which you want to create the objects and credentials, and the scripts will create the objects.
119111
120112
Here are the details on how to do this.
121113
122114
#### Option 1 (interactive)
123115
124-
- Just run ``. .\Configure.ps1``, and you will be prompted to sign-in (email address, password, and if needed MFA).
116+
- Just run ``.\Configure.ps1``, and you will be prompted to sign-in (email address, password, and if needed MFA).
125117
- The script will be run as the signed-in user and will use the tenant in which the user is defined.
126118
127119
Note that the script will choose the tenant in which to create the applications, based on the user. Also to run the `Cleanup.ps1` script, you will need to re-sign-in.
@@ -137,13 +129,13 @@ $mycreds = New-Object System.Management.Automation.PSCredential ("[login@tenantN
137129
. .\Configure.ps1 -Credential $mycreds
138130
```
139131

140-
Of course, in real life, you might already get the password as a `SecureString`. You might also want to get the password from KeyVault.
132+
Of course, in real life, you might already get the password as a `SecureString`. You might also want to get the password from **Azure Key Vault**.
141133

142134
#### Option 3 (Interactive, but create apps in a specified tenant)
143135

144136
if you want to create the apps in a particular tenant, you can use the following option:
145137

146-
- open the [Azure portal](https://portal.azure.com)
138+
- Open the [Azure portal](https://portal.azure.com)
147139
- Select the Azure Active directory you are interested in (in the combo-box below your name on the top right of the browser window)
148140
- Find the "Active Directory" object in this tenant
149141
- Go to **Properties** and copy the content of the **Directory Id** property
@@ -169,7 +161,7 @@ $tenantId = "yourTenantIdGuid"
169161

170162
### Running the script on Azure Sovereign clouds
171163

172-
All the four options listed above, can be used on any Azure Sovereign clouds. By default, the script targets `AzureCloud`, but it can be changed using the parameter `-AzureEnvironmentName`.
164+
All the four options listed above can be used on any Azure Sovereign clouds. By default, the script targets `AzureCloud`, but it can be changed using the parameter `-AzureEnvironmentName`.
173165

174166
The acceptable values for this parameter are:
175167

1-Authentication/1-sign-in/AppCreationScripts/Cleanup.ps1

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ param(
1111

1212

1313
if ($null -eq (Get-Module -ListAvailable -Name "AzureAD")) {
14-
Install-Module "AzureAD" -Scope CurrentUser
14+
Install-Module "AzureAD" -Scope CurrentUser
1515
}
1616
Import-Module AzureAD
1717
$ErrorActionPreference = "Stop"
@@ -59,9 +59,16 @@ Function Cleanup
5959
# Removes the applications
6060
Write-Host "Cleaning-up applications from tenant '$tenantName'"
6161

62-
Write-Host "Removing 'webApp' (ExpressWebApp-c1s1) if needed"
63-
Get-AzureADApplication -Filter "DisplayName eq 'ExpressWebApp-c1s1'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
64-
$apps = Get-AzureADApplication -Filter "DisplayName eq 'ExpressWebApp-c1s1'"
62+
Write-Host "Removing 'client' (msal-node-webapp) if needed"
63+
try
64+
{
65+
Get-AzureADApplication -Filter "DisplayName eq 'msal-node-webapp'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
66+
}
67+
catch
68+
{
69+
Write-Host "Unable to remove the 'msal-node-webapp' . Try deleting manually." -ForegroundColor White -BackgroundColor Red
70+
}
71+
$apps = Get-AzureADApplication -Filter "DisplayName eq 'msal-node-webapp'"
6572
if ($apps)
6673
{
6774
Remove-AzureADApplication -ObjectId $apps.ObjectId
@@ -70,11 +77,18 @@ Function Cleanup
7077
foreach ($app in $apps)
7178
{
7279
Remove-AzureADApplication -ObjectId $app.ObjectId
73-
Write-Host "Removed ExpressWebApp-c1s1.."
80+
Write-Host "Removed msal-node-webapp.."
7481
}
7582
# also remove service principals of this app
76-
Get-AzureADServicePrincipal -filter "DisplayName eq 'ExpressWebApp-c1s1'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
77-
83+
try
84+
{
85+
Get-AzureADServicePrincipal -filter "DisplayName eq 'msal-node-webapp'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
86+
}
87+
catch
88+
{
89+
Write-Host "Unable to remove ServicePrincipal 'msal-node-webapp' . Try deleting manually from Enterprise applications." -ForegroundColor White -BackgroundColor Red
90+
}
7891
}
7992

80-
Cleanup -Credential $Credential -tenantId $TenantId
93+
Cleanup -Credential $Credential -tenantId $TenantId
94+

0 commit comments

Comments
 (0)