Skip to content

Commit 55bd520

Browse files
Minor edits
1 parent aca6e5a commit 55bd520

File tree

4 files changed

+76
-56
lines changed

4 files changed

+76
-56
lines changed

5-AccessControl/2-call-api-groups/AppCreationScripts/BulkCreateGroups.ps1

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
[CmdletBinding()]
23
param(
34
[PSCredential] $Credential,
@@ -7,47 +8,49 @@ param(
78
[string] $azureEnvironmentName
89
)
910

10-
$ErrorActionPreference = "Stop"
1111
<#.Description
12-
This function generates groups names
12+
This function generates groups names.
1313
#>
14-
Function GetGroupName([int] $val) {
14+
Function GetGroupName([int] $val)
15+
{
1516

16-
if ($val -lt 10) {
17+
if ($val -lt 10)
18+
{
1719
$groupName = "Test Group 00" + $val;
1820
}
19-
elseif ($val -lt 100) {
21+
elseif ($val -lt 100)
22+
{
2023
$groupName = "Test Group 0" + $val;
2124
}
22-
else {
25+
else
26+
{
2327
$groupName = "Test Group " + $val;
2428
}
2529

2630
return $groupName;
31+
2732
}
2833

2934
<#.Description
30-
This function creates security groups and assigns the user to the security groups
31-
#>
35+
This function creates security groups and assigns the user to the security groups.
36+
#>
3237
Function CreateGroupsAndAssignUser($user)
3338
{
3439
$val = 1;
35-
36-
while ($val -ne 223)
37-
{
40+
while ($val -ne 223)
41+
{
3842
$groupName = GetGroupName -val $val
3943
$group = Get-MgGroup -Filter "DisplayName eq '$groupName'"
4044
$groupNameLower = $groupName.ToLower();
4145
$nickName = $groupNameLower.replace(' ','');
42-
4346
if ($group)
4447
{
4548
Write-Host "Group $($group.DisplayName) already exists"
4649
}
4750
else
4851
{
4952
$newsg = New-MgGroup -DisplayName $groupName -MailEnabled:$False -MailNickName $nickName -SecurityEnabled
50-
Write-Host "Successfully created group '$($newsg.DisplayName)'"
53+
Write-Host "Successfully created group '$($newsg.DisplayName)'"
5154
$userId = $user.Id
5255
$params = @{
5356
"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/{$userId}"
@@ -59,7 +62,6 @@ Function CreateGroupsAndAssignUser($user)
5962

6063
$val += 1;
6164
}
62-
6365
}
6466

6567
<#.Description
@@ -69,51 +71,60 @@ Function CreateGroupsAndAssignUser($user)
6971
Function ConfigureApplications
7072
{
7173

72-
if (!$azureEnvironmentName) {
74+
if (!$azureEnvironmentName)
75+
{
7376
$azureEnvironmentName = "Global"
7477
}
7578

7679
Write-Host "Connecting to Microsoft Graph"
77-
if ($tenantId -eq "") {
80+
81+
if ($tenantId -eq "")
82+
{
7883
Connect-MgGraph -Scopes "User.Read.All Group.ReadWrite.All GroupMember.ReadWrite.All" -Environment $azureEnvironmentName
7984
$tenantId = (Get-MgContext).TenantId
8085
}
81-
else {
86+
else
87+
{
8288
Connect-MgGraph -TenantId $tenantId -Scopes "User.Read.All Group.ReadWrite.All GroupMember.ReadWrite.All" -Environment $azureEnvironmentName
8389
}
8490

8591
# Add user object Id here
86-
$usersobjectId = Read-Host -Prompt "Enter the object Id (from Azure portal) of the user who will assigned to these security groups: "
87-
88-
$user = Get-MgUser -UserId $usersobjectId
92+
$usersobjectId = Read-Host -Prompt "Enter the object Id (from Azure portal) of the user who will assigned to these security groups"
93+
94+
$user = Get-MgUser -UserId $usersobjectId
8995

9096
Write-Host 'Found user -'
9197
$user | Format-List ID, DisplayName, Mail, UserPrincipalName
9298

9399
CreateGroupsAndAssignUser -user $user
94100
}
95101

96-
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Authentication")) {
97-
Install-Module "Microsoft.Graph.Authentication" -Scope CurrentUser
102+
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Authentication"))
103+
{
104+
Install-Module "Microsoft.Graph.Authentication" -Scope CurrentUser
98105
Write-Host "Installed Microsoft.Graph.Authentication module. If you are having issues, please create a new PowerShell session and try again."
99106
}
100107

101108
Import-Module Microsoft.Graph.Authentication
102109

103-
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Groups")) {
110+
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Groups"))
111+
{
104112
Install-Module "Microsoft.Graph.Groups" -Scope CurrentUser
105113
Write-Host "Installed Microsoft.Graph.Groups module. If you are having issues, please create a new PowerShell session and try again."
106114
}
107115

108116
Import-Module Microsoft.Graph.Groups
109117

110-
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Users")) {
118+
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Users"))
119+
{
111120
Install-Module "Microsoft.Graph.Users" -Scope CurrentUser
112121
Write-Host "Installed Microsoft.Graph.Users module. If you are having issues, please create a new PowerShell session and try again."
113122
}
114123

115124
Import-Module Microsoft.Graph.Users
116125

126+
$ErrorActionPreference = "Stop"
127+
117128
try
118129
{
119130
ConfigureApplications -tenantId $tenantId -environment $azureEnvironmentName

5-AccessControl/2-call-api-groups/AppCreationScripts/BulkRemoveGroups.ps1

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
[CmdletBinding()]
23
param(
34
[PSCredential] $Credential,
@@ -8,18 +9,21 @@ param(
89
)
910

1011
<#.Description
11-
This function generates groups names
12+
This function generates groups names.
1213
#>
13-
Function GetGroupName([int] $val) {
14+
Function GetGroupName([int] $val)
15+
{
1416

1517
if ($val -lt 10)
1618
{
1719
$groupName = "Test Group 00" + $val;
1820
}
19-
elseif ($val -lt 100) {
21+
elseif ($val -lt 100)
22+
{
2023
$groupName = "Test Group 0" + $val;
2124
}
22-
else {
25+
else
26+
{
2327
$groupName = "Test Group " + $val;
2428
}
2529

@@ -28,40 +32,43 @@ Function GetGroupName([int] $val) {
2832
}
2933

3034
<#.Description
31-
This function removes security groups from tenant
32-
#>
33-
Function RemoveGroups {
35+
This function removes security groups from tenant
36+
#>
37+
Function RemoveGroups
38+
{
3439
$val = 1;
35-
while ($val -ne 223) {
40+
while ($val -ne 223)
41+
{
3642

3743
$groupName = GetGroupName -val $val
3844

3945
$group = Get-MgGroup -Filter "DisplayName eq '$groupName'"
40-
4146
if ($group)
4247
{
4348
Remove-MgGroup -GroupId $group.Id
44-
Write-Host "Successfully deleted $($group.DisplayName)"
49+
Write-Host "Successfully deleted '$($group.DisplayName)'"
4550
}
4651
else
4752
{
4853
Write-Host "Couldn't find group $($groupName) with ID: $($group.Id)"
49-
}
50-
54+
}
5155

5256
$val += 1;
5357
}
5458
}
55-
<#.Description
56-
This function signs in the user to the tenant using Graph SDK
57-
#>
58-
Function ConfigureApplications {
5959

60-
if (!$azureEnvironmentName) {
60+
<#.Description
61+
This function signs in the user to the tenant using Graph SDK.
62+
#>
63+
Function ConfigureApplications
64+
{
65+
if (!$azureEnvironmentName)
66+
{
6167
$azureEnvironmentName = "Global"
6268
}
6369

6470
Write-Host "Connecting to Microsoft Graph"
71+
6572
if ($tenantId -eq "")
6673
{
6774
Connect-MgGraph -Scopes "Group.ReadWrite.All" -Environment $azureEnvironmentName
@@ -72,16 +79,18 @@ Function ConfigureApplications {
7279
Connect-MgGraph -TenantId $tenantId -Scopes "Group.ReadWrite.All" -Environment $azureEnvironmentName
7380
}
7481

75-
RemoveGroups
82+
# now remove groups
83+
RemoveGroups
84+
7685
}
7786

7887
$ErrorActionPreference = "Stop"
7988

8089
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Authentication"))
8190
{
82-
Install-Module "Microsoft.Graph.Authentication" -Scope CurrentUser
83-
Write-Host "Installed Microsoft.Graph.Authentication module. If you are having issues, please create a new PowerShell session and try again."
91+
Install-Module "Microsoft.Graph.Authentication" -Scope CurrentUser
8492
}
93+
8594
Import-Module Microsoft.Graph.Authentication
8695

8796
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Groups"))
@@ -98,7 +107,6 @@ if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Users"))
98107

99108
Import-Module Microsoft.Graph.Users
100109

101-
102110
try
103111
{
104112
ConfigureApplications -tenantId $tenantId -environment $azureEnvironmentName

5-AccessControl/2-call-api-groups/AppCreationScripts/Configure.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ Function ConfigureApplications
485485
Write-Host "IMPORTANT: Please follow the instructions below to complete a few manual step(s) in the Azure portal":
486486
Write-Host "- For client"
487487
Write-Host " - Navigate to $clientPortalUrl"
488-
Write-Host " - This script has created a group named 'GroupAdmin' for you. On Azure portal, navigate to Azure AD > Groups blade and assign some users to it." -ForegroundColor Red
489-
Write-Host " - This script has created a group named 'GroupMember' for you. On Azure portal, navigate to Azure AD > Groups blade and assign some users to it." -ForegroundColor Red
488+
Write-Host " - This script has created a group named 'GroupAdmin' and 'GroupMember' for you. On Azure portal, navigate to Azure AD > Groups blade and assign some users to it." -ForegroundColor Red
489+
Write-Host " - To support overage scenario, remember to provide admin consent for GroupMember.Read.All permission in the portal." -ForegroundColor Red
490490
Write-Host " - Security groups matching the names you provided have been created in this tenant (if not present already). On Azure portal, assign some users to it, and configure ID & Access tokens to emit Group IDs" -ForegroundColor Red
491491
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
492492

5-AccessControl/2-call-api-groups/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
22
page_type: sample
3-
services: ms-identity
4-
client: Angular SPA
5-
service: .NET Core web API
6-
level: 300
7-
languages:
3+
name: Angular single-page application calling a protected ASP.NET Core web API and using Security Groups to implement Role-Based Access Control
4+
description: An Angular single-page application calling a protected AspNet web API and using Security Groups to implement Role-Based Access Control (RBAC)
5+
- languages:
86
- typescript
97
- csharp
108
- javascript
@@ -14,11 +12,14 @@ products:
1412
- msal-js
1513
- msal-angular
1614
- microsoft-identity-web
17-
platform: javascript
18-
endpoint: AAD v2.0
1915
urlFragment: ms-identity-javascript-angular-tutorial
20-
name: Angular single-page application calling a protected ASP.NET Core web API and using Security Groups to implement Role-Based Access Control
21-
description: An Angular single-page application calling a protected AspNet web API and using Security Groups to implement Role-Based Access Control (RBAC)
16+
extensions:
17+
- services: ms-identity
18+
- platform: javascript
19+
- endpoint: AAD v2.0
20+
- level: 300
21+
- client: Angular SPA
22+
- service: .NET Core web API
2223
---
2324

2425
# Angular single-page application calling a protected ASP.NET Core web API and using Security Groups to implement Role-Based Access Control

0 commit comments

Comments
 (0)