Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 1a8a31b

Browse files
committed
update configuration and sample.js files
1 parent da557b4 commit 1a8a31b

Some content is hidden

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

53 files changed

+2017
-1520
lines changed

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

+3-15
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44

55
### Quick summary
66

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-
147
1. Run the script to create your Azure AD application and configure the code of the sample application accordingly.
158

169
```PowerShell
@@ -59,28 +52,23 @@ The `Configure.ps1` will stop if it tries to create an Azure AD application whic
5952

6053
### Pre-requisites
6154

55+
1. PowerShell 7 or later (see: [installing PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell))
6256
1. Open PowerShell (On Windows, press `Windows-R` and type `PowerShell` in the search window)
63-
1. Navigate to the root directory of the project.
64-
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:
65-
66-
```PowerShell
67-
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
68-
```
6957

7058
### (Optionally) install Microsoft.Graph.Applications PowerShell modules
7159

7260
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:
7361

7462
1. If you have never done it already, in the PowerShell window, install the Microsoft.Graph.Applications PowerShell modules. For this:
7563

76-
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
7765
2. Type:
7866

7967
```PowerShell
8068
Install-Module Microsoft.Graph.Applications
8169
```
8270
83-
or if you cannot be administrator on your machine, run:
71+
or if you want the modules to be installed for the current user only, run:
8472
8573
```PowerShell
8674
Install-Module Microsoft.Graph.Applications -Scope CurrentUser

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
1+
#Requires -Version 7
2+
23
[CmdletBinding()]
34
param(
45
[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')]

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Requires -Version 7
12

23
[CmdletBinding()]
34
param(
@@ -160,7 +161,7 @@ Function ConfigureApplications
160161
$owner = Get-MgApplicationOwner -ApplicationId $currentAppObjectId
161162
if ($owner -eq $null)
162163
{
163-
New-MgApplicationOwnerByRef -ApplicationId $currentAppObjectId -BodyParameter = @{"@odata.id" = "htps://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
164+
New-MgApplicationOwnerByRef -ApplicationId $currentAppObjectId -BodyParameter @{"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
164165
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($clientServicePrincipal.DisplayName)'"
165166
}
166167
Write-Host "Done creating the client application (msal-react-spa)"

1-Authentication/1-sign-in/AppCreationScripts/sample.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"HomePage": "http://localhost:3000/",
1919
"ReplyUrls": "http://localhost:3000/, http://localhost:3000/redirect",
2020
"Audience": "AzureADMyOrg",
21-
"SDK": "MsalJs",
21+
"SDK": "MsalReact",
2222
"SampleSubPath": "1-Authentication\\1-sign-in\\SPA"
2323
}
2424
],

2-Authorization-I/1-call-graph/AppCreationScripts/AppCreationScripts.md

+7-18
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44

55
### Quick summary
66

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-
147
1. Run the script to create your Azure AD application and configure the code of the sample application accordingly.
158

169
```PowerShell
@@ -49,6 +42,8 @@ These scripts are:
4942

5043
- `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`).
5144

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.
46+
5247
### Usage pattern for tests and DevOps scenarios
5348

5449
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.
@@ -57,28 +52,23 @@ The `Configure.ps1` will stop if it tries to create an Azure AD application whic
5752

5853
### Pre-requisites
5954

55+
1. PowerShell 7 or later (see: [installing PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell))
6056
1. Open PowerShell (On Windows, press `Windows-R` and type `PowerShell` in the search window)
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-
64-
```PowerShell
65-
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
66-
```
6757

6858
### (Optionally) install Microsoft.Graph.Applications PowerShell modules
6959

7060
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:
7161

7262
1. If you have never done it already, in the PowerShell window, install the Microsoft.Graph.Applications PowerShell modules. For this:
7363

74-
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
7565
2. Type:
7666

7767
```PowerShell
7868
Install-Module Microsoft.Graph.Applications
7969
```
8070
81-
or if you cannot be administrator on your machine, run:
71+
or if you want the modules to be installed for the current user only, run:
8272
8373
```PowerShell
8474
Install-Module Microsoft.Graph.Applications -Scope CurrentUser
@@ -139,11 +129,10 @@ The acceptable values for this parameter are:
139129
- AzureCloud
140130
- AzureChinaCloud
141131
- AzureUSGovernment
142-
- AzureGermanyCloud
143132

144133
Example:
145134

146135
```PowerShell
147-
. .\Cleanup.ps1 -AzureEnvironmentName "AzureGermanyCloud"
148-
. .\Configure.ps1 -AzureEnvironmentName "AzureGermanyCloud"
136+
. .\Cleanup.ps1 -AzureEnvironmentName "AzureUSGovernment"
137+
. .\Configure.ps1 -AzureEnvironmentName "AzureUSGovernment"
149138
```

2-Authorization-I/1-call-graph/AppCreationScripts/Cleanup.ps1

+83-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Requires -Version 7
12

23
[CmdletBinding()]
34
param(
@@ -7,6 +8,7 @@ param(
78
[string] $azureEnvironmentName
89
)
910

11+
1012
Function Cleanup
1113
{
1214
if (!$azureEnvironmentName)
@@ -24,29 +26,51 @@ Function Cleanup
2426

2527
# Connect to the Microsoft Graph API
2628
Write-Host "Connecting to Microsoft Graph"
27-
if ($tenantId -eq "") {
28-
Connect-MgGraph -Scopes "Application.ReadWrite.All" -Environment $azureEnvironmentName
29-
$tenantId = (Get-MgContext).TenantId
29+
30+
31+
if ($tenantId -eq "")
32+
{
33+
Connect-MgGraph -Scopes "User.Read.All Organization.Read.All Application.ReadWrite.All" -Environment $azureEnvironmentName
3034
}
31-
else {
32-
Connect-MgGraph -TenantId $tenantId -Scopes "Application.ReadWrite.All" -Environment $azureEnvironmentName
35+
else
36+
{
37+
Connect-MgGraph -TenantId $tenantId -Scopes "User.Read.All Organization.Read.All Application.ReadWrite.All" -Environment $azureEnvironmentName
3338
}
3439

40+
$context = Get-MgContext
41+
$tenantId = $context.TenantId
42+
43+
# Get the user running the script
44+
$currentUserPrincipalName = $context.Account
45+
$user = Get-MgUser -Filter "UserPrincipalName eq '$($context.Account)'"
46+
47+
# get the tenant we signed in to
48+
$Tenant = Get-MgOrganization
49+
$tenantName = $Tenant.DisplayName
50+
51+
$verifiedDomain = $Tenant.VerifiedDomains | where {$_.Isdefault -eq $true}
52+
$verifiedDomainName = $verifiedDomain.Name
53+
$tenantId = $Tenant.Id
54+
55+
Write-Host ("Connected to Tenant {0} ({1}) as account '{2}'. Domain is '{3}'" -f $Tenant.DisplayName, $Tenant.Id, $currentUserPrincipalName, $verifiedDomainName)
56+
3557
# Removes the applications
3658
Write-Host "Cleaning-up applications from tenant '$tenantId'"
3759

3860
Write-Host "Removing 'spa' (ms-identity-react-c2s1) if needed"
3961
try
4062
{
41-
Get-MgApplication -Filter "DisplayName eq 'ms-identity-react-c2s1'" | ForEach-Object {Remove-MgApplication -ApplicationId $_.Id }
63+
Get-MgApplication -Filter "DisplayName eq 'ms-identity-react-c2s1'" | ForEach-Object {Remove-MgApplication -ApplicationId $_.Id }
4264
}
4365
catch
4466
{
45-
Write-Host "Unable to remove the application 'ms-identity-react-c2s1' . Try deleting manually." -ForegroundColor White -BackgroundColor Red
67+
$message = $_
68+
Write-Warning $Error[0]
69+
Write-Host "Unable to remove the application 'ms-identity-react-c2s1'. Error is $message. Try deleting manually." -ForegroundColor White -BackgroundColor Red
4670
}
4771

4872
Write-Host "Making sure there are no more (ms-identity-react-c2s1) applications found, will remove if needed..."
49-
$apps = Get-MgApplication -Filter "DisplayName eq 'ms-identity-react-c2s1'"
73+
$apps = Get-MgApplication -Filter "DisplayName eq 'ms-identity-react-c2s1'" | Format-List Id, DisplayName, AppId, SignInAudience, PublisherDomain
5074

5175
if ($apps)
5276
{
@@ -62,23 +86,67 @@ Function Cleanup
6286
# also remove service principals of this app
6387
try
6488
{
65-
Get-MgServicePrincipal -filter "DisplayName eq 'ms-identity-react-c2s1'" | ForEach-Object {Remove-MgServicePrincipal -ApplicationId $_.Id -Confirm:$false}
89+
Get-MgServicePrincipal -filter "DisplayName eq 'ms-identity-react-c2s1'" | ForEach-Object {Remove-MgServicePrincipal -ServicePrincipalId $_.Id -Confirm:$false}
6690
}
6791
catch
6892
{
69-
Write-Host "Unable to remove ServicePrincipal 'ms-identity-react-c2s1' . Try deleting manually from Enterprise applications." -ForegroundColor White -BackgroundColor Red
93+
$message = $_
94+
Write-Warning $Error[0]
95+
Write-Host "Unable to remove ServicePrincipal 'ms-identity-react-c2s1'. Error is $message. Try deleting manually from Enterprise applications." -ForegroundColor White -BackgroundColor Red
7096
}
7197
}
7298

73-
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Applications")) {
74-
Install-Module "Microsoft.Graph.Applications" -Scope CurrentUser
75-
}
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")) {
107+
Install-Module "Microsoft.Graph.Authentication" -Scope CurrentUser
108+
}
109+
110+
Import-Module Microsoft.Graph.Authentication
111+
112+
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Identity.DirectoryManagement")) {
113+
Install-Module "Microsoft.Graph.Identity.DirectoryManagement" -Scope CurrentUser
114+
}
115+
116+
Import-Module Microsoft.Graph.Identity.DirectoryManagement
117+
118+
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Applications")) {
119+
Install-Module "Microsoft.Graph.Applications" -Scope CurrentUser
120+
}
121+
76122
Import-Module Microsoft.Graph.Applications
123+
124+
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Groups")) {
125+
Install-Module "Microsoft.Graph.Groups" -Scope CurrentUser
126+
}
127+
128+
Import-Module Microsoft.Graph.Groups
129+
130+
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Users")) {
131+
Install-Module "Microsoft.Graph.Users" -Scope CurrentUser
132+
}
133+
134+
Import-Module Microsoft.Graph.Users
135+
77136
$ErrorActionPreference = "Stop"
78137

79138

80-
Cleanup -tenantId $tenantId -environment $azureEnvironmentName
139+
try
140+
{
141+
Cleanup -tenantId $tenantId -environment $azureEnvironmentName
142+
}
143+
catch
144+
{
145+
$_.Exception.ToString() | out-host
146+
$message = $_
147+
Write-Warning $Error[0]
148+
Write-Host "Unable to register apps. Error is $message." -ForegroundColor White -BackgroundColor Red
149+
}
81150

82151
Write-Host "Disconnecting from tenant"
83152
Disconnect-MgGraph
84-

0 commit comments

Comments
 (0)