Skip to content

Commit 4850dbd

Browse files
pamelafoxrayluo
andauthored
Style fixes and Python best practices (#91)
* Import issues * Black reformatting * Dont use flask-session package * Add sample * Use .env in b2c * Reimport os * Updates per comments * Trailing comma * Readme and Powershell updates * Update README.md Co-authored-by: Ray Luo <[email protected]> * readme updates * Address B2C issues * TENANT_ID vs TENANT_NAME * Update app_config.py Co-authored-by: Ray Luo <[email protected]> * Tenant name for b2c * Flask-session instead of Flask-session2 * Updated scripts --------- Co-authored-by: Ray Luo <[email protected]>
1 parent 9672145 commit 4850dbd

File tree

14 files changed

+436
-726
lines changed

14 files changed

+436
-726
lines changed

.env.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FLASK_DEBUG=True
2+
# Expects a full tenant name such as "contoso.onmicrosoft.com", or its GUID
3+
TENANT_ID=<tenant id>
4+
CLIENT_ID=<client id>
5+
CLIENT_SECRET=<client secret>

.env.sample.b2c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FLASK_DEBUG=True
2+
# Expects the display name such as "contoso"
3+
TENANT_NAME=<tenant name>
4+
CLIENT_ID=<client id>
5+
CLIENT_SECRET=<client secret>
6+
SIGNUPSIGNIN_USER_FLOW=B2C_1_profile_editing
7+
EDITPROFILE_USER_FLOW=B2C_1_reset_password
8+
RESETPASSWORD_USER_FLOW=B2C_1_signupsignin1
Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1-
# Registering the sample apps with Microsoft Identity Platform and updating the configuration files using PowerShell scripts
1+
# Registering sample apps with the Microsoft identity platform and updating configuration files using PowerShell
22

33
## Overview
44

55
### Quick summary
66

7-
1. On Windows run PowerShell 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:
9+
910
```PowerShell
1011
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
1112
```
12-
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)
13+
14+
1. Run the script to create your Azure AD application and configure the code of the sample application accordingly.
15+
1316
```PowerShell
14-
.\AppCreationScripts\Configure.ps1
17+
cd .\AppCreationScripts\
18+
.\Configure.ps1 -TenantId "your test tenant's id" -AzureEnvironmentName "[Optional] - Azure environment, defaults to 'Global'"
1519
```
16-
1. Open the Visual Studio solution and click start
1720

1821
### More details
1922

20-
The following paragraphs:
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 (Interactive, but create apps in a specified tenant)](#option-3-Interactive-but-create-apps-in-a-specified-tenant)
32+
- [Running the script on Azure Sovereign clouds](#running-the-script-on-Azure-Sovereign-clouds)
2133

22-
- [Present the scripts](#presentation-of-the-scripts) and explain their [usage patterns](#usage-pattern-for-tests-and-devops-scenarios) for test and DevOps scenarios.
23-
- Explain the [pre-requisites](#pre-requisites)
24-
- Explain [four ways of running the scripts](#four-ways-to-run-the-script):
25-
- [Interactively](#option-1-interactive) to create the app in your home tenant
26-
- [Passing credentials](#option-2-non-interactive) to create the app in your home tenant
27-
- [Interactively in a specific tenant](#option-3-interactive-but-create-apps-in-a-specified-tenant)
28-
- [Passing credentials in a specific tenant](#option-4-non-interactive-and-create-apps-in-a-specified-tenant)
29-
30-
## Goal of the scripts
34+
## Goal of the provided scripts
3135

3236
### Presentation of the scripts
3337

@@ -36,92 +40,83 @@ This sample comes with two PowerShell scripts, which automate the creation of th
3640
These scripts are:
3741

3842
- `Configure.ps1` which:
39-
- creates Azure AD applications and their related objects (permissions, dependencies, secrets),
40-
- changes the configuration files in the C# and JavaScript projects.
43+
- creates Azure AD applications and their related objects (permissions, dependencies, secrets, app roles),
44+
- changes the configuration files in the sample projects.
4145
- 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:
4246
- the identifier of the application
4347
- the AppId of the application
4448
- the url of its registration in the [Azure portal](https://portal.azure.com).
4549

46-
- `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).
50+
- `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`).
4751

4852
### Usage pattern for tests and DevOps scenarios
4953

5054
The `Configure.ps1` will stop if it tries to create an Azure AD application which already exists in the tenant. For this, if you are using the script to try/test the sample, or in DevOps scenarios, you might want to run `Cleanup.ps1` just before `Configure.ps1`. This is what is shown in the steps below.
5155

52-
## How to use the app creation scripts ?
56+
## How to use the app creation scripts?
5357

5458
### Pre-requisites
5559

5660
1. Open PowerShell (On Windows, press `Windows-R` and type `PowerShell` in the search window)
57-
2. Navigate to the root directory of the project.
58-
3. Until you change it, the default [Execution Policy](https:/go.microsoft.com/fwlink/?LinkID=135170) for scripts is usually `Restricted`. In order to run the PowerShell script you need to set the Execution Policy to `RemoteSigned`. You can set this just for the current PowerShell process by running the command:
61+
1. Navigate to the root directory of the project.
62+
1. Until you change it, the default [Execution Policy](https:/go.microsoft.com/fwlink/?LinkID=135170) for scripts is usually `Restricted`. In order to run the PowerShell script you need to set the Execution Policy to `RemoteSigned`. You can set this just for the current PowerShell process by running the command:
63+
5964
```PowerShell
6065
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
6166
```
62-
### (Optionally) install AzureAD PowerShell modules
63-
The scripts install the required PowerShell module (AzureAD) for the current user if needed. However, if you want to install if for all users on the machine, you can follow the following steps:
6467
65-
4. If you have never done it already, in the PowerShell window, install the AzureAD PowerShell modules. For this:
68+
### (Optionally) install Microsoft.Graph.Applications PowerShell modules
69+
70+
The scripts install the required PowerShell module (Microsoft.Graph.Applications) for the current user if needed. However, if you want to install if for all users on the machine, you can follow the following steps:
6671
67-
1. Open PowerShell as admin (On Windows, Search Powershell in the search bar, right click on it and select Run as administrator).
72+
1. If you have never done it already, in the PowerShell window, install the Microsoft.Graph.Applications PowerShell modules. For this:
73+
74+
1. Open PowerShell as admin (On Windows, Search Powershell in the search bar, right click on it and select **Run as administrator**).
6875
2. Type:
76+
6977
```PowerShell
70-
Install-Module AzureAD
78+
Install-Module Microsoft.Graph.Applications
7179
```
7280
7381
or if you cannot be administrator on your machine, run:
82+
7483
```PowerShell
75-
Install-Module AzureAD -Scope CurrentUser
84+
Install-Module Microsoft.Graph.Applications -Scope CurrentUser
7685
```
7786
7887
### Run the script and start running
7988
80-
5. Go to the `AppCreationScripts` sub-folder. From the folder where you cloned the repo,
89+
1. Go to the `AppCreationScripts` sub-folder. From the folder where you cloned the repo,
90+
8191
```PowerShell
8292
cd AppCreationScripts
8393
```
84-
6. Run the scripts. See below for the [four options](#four-ways-to-run-the-script) to do that.
85-
7. Open the Visual Studio solution, and in the solution's context menu, choose **Set Startup Projects**.
86-
8. select **Start** for the projects
8794
88-
You're done. this just works!
95+
1. Run the scripts. See below for the [four options](#four-ways-to-run-the-script) to do that.
96+
97+
You're done!
8998
90-
### Four ways to run the script
99+
### Two ways to run the script
91100
92101
We advise four ways of running the script:
93102
94103
- Interactive: you will be prompted for credentials, and the scripts decide in which tenant to create the objects,
95-
- non-interactive: you will provide credentials, and the scripts decide in which tenant to create the objects,
96-
- 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,
97-
- 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.
104+
- 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,
98105
99106
Here are the details on how to do this.
100107
101108
#### Option 1 (interactive)
102109
103-
- Just run ``. .\Configure.ps1``, and you will be prompted to sign-in (email address, password, and if needed MFA).
110+
- Just run ``.\Configure.ps1``, and you will be prompted to sign-in (email address, password, and if needed MFA).
104111
- The script will be run as the signed-in user and will use the tenant in which the user is defined.
105112
106113
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.
107114
108-
#### Option 2 (non-interactive)
109-
110-
When you know the indentity and credentials of the user in the name of whom you want to create the applications, you can use the non-interactive approach. It's more adapted to DevOps. Here is an example of script you'd want to run in a PowerShell Window
111-
112-
```PowerShell
113-
$secpasswd = ConvertTo-SecureString "[Password here]" -AsPlainText -Force
114-
$mycreds = New-Object System.Management.Automation.PSCredential ("[login@tenantName here]", $secpasswd)
115-
. .\Cleanup.ps1 -Credential $mycreds
116-
. .\Configure.ps1 -Credential $mycreds
117-
```
118-
119-
Of course, in real life, you might already get the password as a `SecureString`. You might also want to get the password from KeyVault.
120-
121-
#### Option 3 (Interactive, but create apps in a specified tenant)
115+
#### Option 2 (Interactive, but create apps in a specified tenant)
122116
123117
if you want to create the apps in a particular tenant, you can use the following option:
124-
- open the [Azure portal](https://portal.azure.com)
118+
119+
- Open the [Azure portal](https://portal.azure.com)
125120
- Select the Azure Active directory you are interested in (in the combo-box below your name on the top right of the browser window)
126121
- Find the "Active Directory" object in this tenant
127122
- Go to **Properties** and copy the content of the **Directory Id** property
@@ -133,14 +128,19 @@ $tenantId = "yourTenantIdGuid"
133128
. .\Configure.ps1 -TenantId $tenantId
134129
```
135130

136-
#### Option 4 (non-interactive, and create apps in a specified tenant)
131+
### Running the script on Azure Sovereign clouds
137132

138-
This option combines option 2 and option 3: it creates the application in a specific tenant. See option 3 for the way to get the tenant Id. Then run:
133+
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`.
139134

140-
```PowerShell
141-
$secpasswd = ConvertTo-SecureString "[Password here]" -AsPlainText -Force
142-
$mycreds = New-Object System.Management.Automation.PSCredential ("[login@tenantName here]", $secpasswd)
143-
$tenantId = "yourTenantIdGuid"
144-
. .\Cleanup.ps1 -Credential $mycreds -TenantId $tenantId
145-
. .\Configure.ps1 -Credential $mycreds -TenantId $tenantId
146-
```
135+
The acceptable values for this parameter are:
136+
137+
- AzureCloud
138+
- AzureChinaCloud
139+
- AzureUSGovernment
140+
141+
Example:
142+
143+
```PowerShell
144+
. .\Cleanup.ps1 -AzureEnvironmentName "AzureUSGovernment"
145+
. .\Configure.ps1 -AzureEnvironmentName "AzureUSGovernment"
146+
```

AppCreationScripts/Apps.json

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)