You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 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
2
2
3
3
## Overview
4
4
5
5
### Quick summary
6
6
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
8
8
1. In PowerShell run:
9
+
9
10
```PowerShell
10
11
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
11
12
```
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
+
13
16
```PowerShell
14
-
cd .\AppCreationScripts\
15
-
.\Configure.ps1
17
+
cd .\AppCreationScripts\
18
+
.\Configure.ps1 -TenantId "your test tenant's id" -AzureEnvironmentName "[Optional] - Azure environment, defaults to 'Global'"
16
19
```
17
-
1. Open the Visual Studio solution and click start
18
20
19
21
### More details
20
22
21
-
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)
22
33
23
-
-[Present the scripts](#presentation-of-the-scripts) and explain their [usage patterns](#usage-pattern-for-tests-and-devops-scenarios) for test and DevOps scenarios.
24
-
- Explain the [pre-requisites](#pre-requisites)
25
-
- Explain [four ways of running the scripts](#four-ways-to-run-the-script):
26
-
-[Interactively](#option-1-interactive) to create the app in your home tenant
27
-
-[Passing credentials](#option-2-non-interactive) to create the app in your home tenant
28
-
-[Interactively in a specific tenant](#option-3-interactive-but-create-apps-in-a-specified-tenant)
29
-
-[Passing credentials in a specific tenant](#option-4-non-interactive-and-create-apps-in-a-specified-tenant)
30
-
31
-
## Goal of the scripts
34
+
## Goal of the provided scripts
32
35
33
36
### Presentation of the scripts
34
37
@@ -37,92 +40,85 @@ This sample comes with two PowerShell scripts, which automate the creation of th
37
40
These scripts are:
38
41
39
42
-`Configure.ps1` which:
40
-
- creates Azure AD applications and their related objects (permissions, dependencies, secrets),
41
-
- 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.
42
45
- 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:
43
46
- the identifier of the application
44
47
- the AppId of the application
45
48
- the url of its registration in the [Azure portal](https://portal.azure.com).
46
49
47
-
-`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`).
48
51
49
52
### Usage pattern for tests and DevOps scenarios
50
53
51
54
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.
52
55
53
-
## How to use the app creation scripts?
56
+
## How to use the app creation scripts?
54
57
55
58
### Pre-requisites
56
59
57
60
1. Open PowerShell (On Windows, press `Windows-R` and type `PowerShell` in the search window)
58
-
2. Navigate to the root directory of the project.
59
-
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
+
60
64
```PowerShell
61
65
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
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:
65
67
66
-
4. If you have never done it already, in the PowerShell window, install the AzureAD PowerShell modules. For this:
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:
67
71
68
-
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**).
69
75
2. Type:
76
+
70
77
```PowerShell
71
-
Install-Module AzureAD
78
+
Install-Module Microsoft.Graph.Applications
72
79
```
73
80
74
81
or if you cannot be administrator on your machine, run:
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
+
82
91
```PowerShell
83
92
cd AppCreationScripts
84
93
```
85
-
6. Run the scripts. See below for the [four options](#four-ways-to-run-the-script) to do that.
86
-
7. Open the Visual Studio solution, and in the solution's context menu, choose **Set Startup Projects**.
87
-
8. select **Start** for the projects
88
94
89
-
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
+
1. Open the Visual Studio solution, and in the solution's context menu, choose **Set Startup Projects**.
97
+
1. select **Start** for the projects
98
+
99
+
You're done!
90
100
91
-
### Four ways to run the script
101
+
### Two ways to run the script
92
102
93
103
We advise four ways of running the script:
94
104
95
105
- Interactive: you will be prompted for credentials, and the scripts decide in which tenant to create the objects,
96
-
- non-interactive: you will provide credentials, and the scripts decide in which tenant to create the objects,
97
-
- 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,
98
-
- 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.
106
+
- 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,
99
107
100
108
Here are the details on how to do this.
101
109
102
110
#### Option 1 (interactive)
103
111
104
-
- Just run ``. .\Configure.ps1``, and you will be prompted to sign-in (email address, password, and if needed MFA).
112
+
- Just run ``.\Configure.ps1``, and you will be prompted to sign-in (email address, password, and if needed MFA).
105
113
- The script will be run as the signed-in user and will use the tenant in which the user is defined.
106
114
107
115
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.
108
116
109
-
#### Option 2 (non-interactive)
110
-
111
-
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
#### Option 4 (non-interactive, and create apps in a specified tenant)
133
+
###Running the script on Azure Sovereign clouds
138
134
139
-
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:
135
+
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`.
[Parameter(Mandatory=$False,HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')]
5
-
[string] $tenantId
5
+
[string] $tenantId,
6
+
[Parameter(Mandatory=$False,HelpMessage='Azure environment to use while running the script. Default = Global')]
7
+
[string] $azureEnvironmentName
6
8
)
7
9
8
-
if ($null-eq (Get-Module-ListAvailable -Name "AzureAD")) {
9
-
Install-Module"AzureAD"-Scope CurrentUser
10
-
}
11
-
Import-Module AzureAD
12
-
$ErrorActionPreference="Stop"
13
-
14
10
FunctionCleanup
15
11
{
16
-
<#
17
-
.Description
18
-
This function removes the Azure AD applications for the sample. These applications were created by the Configure.ps1 script
19
-
#>
12
+
if (!$azureEnvironmentName)
13
+
{
14
+
$azureEnvironmentName="Global"
15
+
}
16
+
17
+
<#
18
+
.Description
19
+
This function removes the Azure AD applications for the sample. These applications were created by the Configure.ps1 script
20
+
#>
20
21
21
22
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
22
23
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
23
24
24
-
#Login to Azure PowerShell (interactive if credentials are not already provided:
25
-
# you'll need to sign-in with creds enabling your to create apps in the tenant)
Write-Host"Unable to remove the application 'WebApp-MultiTenant-v2'. Error is $message. Try deleting manually."-ForegroundColor White -BackgroundColor Red
48
+
}
49
+
50
+
Write-Host"Making sure there are no more (WebApp-MultiTenant-v2) applications found, will remove if needed..."
Write-Host"Unable to remove ServicePrincipal 'WebApp-MultiTenant-v2'. Error is $message. Try deleting manually from Enterprise applications."-ForegroundColor White -BackgroundColor Red
0 commit comments