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
{{ message }}
This repository was archived by the owner on May 17, 2024. It is now read-only.
# 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 configuration files using PowerShell
2
2
3
3
## Overview
4
4
5
5
### Quick summary
6
6
7
-
1. On Windows run PowerShell as **Administrator** and navigate to the root of the cloned directory
8
-
1. In PowerShell run:
9
-
10
-
```PowerShell
11
-
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
12
-
```
13
-
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)
7
+
1. Run the script to create your Azure AD application and configure the code of the sample application accordingly.
15
8
16
9
```PowerShell
17
10
cd .\AppCreationScripts\
18
-
.\Configure.ps1
11
+
.\Configure.ps1 -TenantId "your test tenant's id" -AzureEnvironmentName "[Optional] - Azure environment, defaults to 'Global'"
19
12
```
20
13
21
-
1. Open the Visual Studio solution and click start
22
-
23
14
### More details
24
15
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)
-[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)
16
+
-[Goal of the provided scripts](#goal-of-the-provided-scripts)
17
+
-[Presentation of the scripts](#presentation-of-the-scripts)
18
+
-[Usage pattern for tests and DevOps scenarios](#usage-pattern-for-tests-and-DevOps-scenarios)
19
+
-[How to use the app creation scripts?](#how-to-use-the-app-creation-scripts)
20
+
-[Pre-requisites](#pre-requisites)
21
+
-[Run the script and start running](#run-the-script-and-start-running)
22
+
-[Four ways to run the script](#four-ways-to-run-the-script)
23
+
-[Option 1 (interactive)](#option-1-interactive)
24
+
-[Option 2 (Interactive, but create apps in a specified tenant)](#option-3-Interactive-but-create-apps-in-a-specified-tenant)
25
+
-[Running the script on Azure Sovereign clouds](#running-the-script-on-Azure-Sovereign-clouds)
43
26
44
27
## Goal of the provided scripts
45
28
@@ -50,14 +33,16 @@ This sample comes with two PowerShell scripts, which automate the creation of th
50
33
These scripts are:
51
34
52
35
-`Configure.ps1` which:
53
-
- creates Azure AD applications and their related objects (permissions, dependencies, secrets),
54
-
- changes the configuration files in the C# and JavaScript projects.
36
+
- creates Azure AD applications and their related objects (permissions, dependencies, secrets, app roles),
37
+
- changes the configuration files in the sample projects.
55
38
- 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:
56
39
- the identifier of the application
57
40
- the AppId of the application
58
41
- the url of its registration in the [Azure portal](https://portal.azure.com).
59
42
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).
43
+
-`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`).
44
+
45
+
> :information_source: If the sample supports using certificates instead of client secrets, this folder will contain an additional set of scripts: `Configure-WithCertificates.ps1` and `Cleanup-WithCertificates.ps1`. You can use them in the same way to register app(s) that use certificates instead of client secrets.
61
46
62
47
### Usage pattern for tests and DevOps scenarios
63
48
@@ -67,31 +52,26 @@ The `Configure.ps1` will stop if it tries to create an Azure AD application whic
67
52
68
53
### Pre-requisites
69
54
55
+
1. PowerShell 7 or later (see: [installing PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell))
70
56
1. Open PowerShell (On Windows, press `Windows-R` and type `PowerShell` in the search window)
71
-
1. Navigate to the root directory of the project.
72
-
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:
73
57
74
-
```PowerShell
75
-
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:
60
+
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:
81
61
82
-
1. If you have never done it already, in the PowerShell window, install the AzureAD PowerShell modules. For this:
62
+
1. If you have never done it already, in the PowerShell window, install the Microsoft.Graph.Applications PowerShell modules. For this:
83
63
84
-
1. Open PowerShell as admin (On Windows, Search Powershell in the search bar, right click on it and select Run as administrator).
64
+
1. Open PowerShell
85
65
2. Type:
86
-
66
+
87
67
```PowerShell
88
-
Install-Module AzureAD
68
+
Install-Module Microsoft.Graph.Applications
89
69
```
90
70
91
-
or if you cannot be administrator on your machine, run:
92
-
71
+
or if you want the modules to be installed for the current user only, run:
@@ -106,44 +86,29 @@ The scripts install the required PowerShell module (AzureAD) for the current use
106
86
1. Open the Visual Studio solution, and in the solution's context menu, choose **Set Startup Projects**.
107
87
1. select **Start** for the projects
108
88
109
-
You're done. this just works!
89
+
You're done!
110
90
111
-
### Four ways to run the script
91
+
### Two ways to run the script
112
92
113
93
We advise four ways of running the script:
114
94
115
95
- Interactive: you will be prompted for credentials, and the scripts decide in which tenant to create the objects,
116
-
- 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.
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,
119
97
120
98
Here are the details on how to do this.
121
99
122
100
#### Option 1 (interactive)
123
101
124
-
- Just run ``. .\Configure.ps1``, and you will be prompted to sign-in (email address, password, and if needed MFA).
102
+
- Just run ``.\Configure.ps1``, and you will be prompted to sign-in (email address, password, and if needed MFA).
125
103
- The script will be run as the signed-in user and will use the tenant in which the user is defined.
126
104
127
105
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.
128
106
129
-
#### Option 2 (non-interactive)
130
-
131
-
When you know the identity 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
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`.
125
+
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
6
[string] $tenantId,
6
-
[Parameter(Mandatory=$False,HelpMessage='Azure environment to use while running the script (it defaults to AzureCloud)')]
7
+
[Parameter(Mandatory=$False,HelpMessage='Azure environment to use while running the script. Default = Global')]
7
8
[string] $azureEnvironmentName
8
9
)
9
10
10
-
#Requires -ModulesAzureAD-RunAsAdministrator
11
-
12
-
13
-
if ($null-eq (Get-Module-ListAvailable -Name "AzureAD")) {
14
-
Install-Module"AzureAD"-Scope CurrentUser
15
-
}
16
-
Import-Module AzureAD
17
-
$ErrorActionPreference="Stop"
18
11
19
12
FunctionCleanup
20
13
{
21
14
if (!$azureEnvironmentName)
22
15
{
23
-
$azureEnvironmentName="AzureCloud"
16
+
$azureEnvironmentName="Global"
24
17
}
25
18
26
19
<#
@@ -31,50 +24,129 @@ Function Cleanup
31
24
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
32
25
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
33
26
34
-
# Login to Azure PowerShell (interactive if credentials are not already provided:
35
-
# you'll need to sign-in with creds enabling your to create apps in the tenant)
Write-Host ("Connected to Tenant {0} ({1}) as account '{2}'. Domain is '{3}'"-f$Tenant.DisplayName,$Tenant.Id,$currentUserPrincipalName,$verifiedDomainName)
56
+
59
57
# Removes the applications
60
-
Write-Host"Cleaning-up applications from tenant '$tenantName'"
58
+
Write-Host"Cleaning-up applications from tenant '$tenantId'"
61
59
62
60
Write-Host"Removing 'spa' (msal-angular-spa) if needed"
Write-Host"Unable to remove ServicePrincipal 'msal-angular-spa'. Error is $message. Try deleting manually from Enterprise applications."-ForegroundColor White -BackgroundColor Red
96
+
}
97
+
}
98
+
99
+
# Pre-requisites
100
+
if ($null-eq (Get-Module-ListAvailable -Name "Microsoft.Graph")) {
101
+
Install-Module"Microsoft.Graph"-Scope CurrentUser
102
+
}
103
+
104
+
#Import-Module Microsoft.Graph
105
+
106
+
if ($null-eq (Get-Module-ListAvailable -Name "Microsoft.Graph.Authentication")) {
0 commit comments