Skip to content

Commit 7a7193e

Browse files
committed
revise new chapters
1 parent 0fadfd8 commit 7a7193e

Some content is hidden

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

41 files changed

+656
-878
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ dist
104104
.tern-port
105105

106106
# .NET binaries
107-
bin
108-
obj
107+
bin/
108+
obj/
109109

110110
# Visual Studio cache
111111
.vs

6-AccessControl/1-call-api-roles/AppCreationScripts/Cleanup.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ Function Cleanup
5959
# Removes the applications
6060
Write-Host "Cleaning-up applications from tenant '$tenantName'"
6161

62-
Write-Host "Removing 'service' (TodoListAPI) if needed"
63-
Get-AzureADApplication -Filter "DisplayName eq 'TodoListAPI'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
64-
$apps = Get-AzureADApplication -Filter "DisplayName eq 'TodoListAPI'"
62+
Write-Host "Removing 'service' (msal-dotnet-api) if needed"
63+
Get-AzureADApplication -Filter "DisplayName eq 'msal-dotnet-api'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
64+
$apps = Get-AzureADApplication -Filter "DisplayName eq 'msal-dotnet-api'"
6565
if ($apps)
6666
{
6767
Remove-AzureADApplication -ObjectId $apps.ObjectId
@@ -70,14 +70,14 @@ Function Cleanup
7070
foreach ($app in $apps)
7171
{
7272
Remove-AzureADApplication -ObjectId $app.ObjectId
73-
Write-Host "Removed TodoListAPI.."
73+
Write-Host "Removed msal-dotnet-api.."
7474
}
7575
# also remove service principals of this app
76-
Get-AzureADServicePrincipal -filter "DisplayName eq 'TodoListAPI'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
76+
Get-AzureADServicePrincipal -filter "DisplayName eq 'msal-dotnet-api'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
7777

78-
Write-Host "Removing 'client' (TodoListSPA) if needed"
79-
Get-AzureADApplication -Filter "DisplayName eq 'TodoListSPA'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
80-
$apps = Get-AzureADApplication -Filter "DisplayName eq 'TodoListSPA'"
78+
Write-Host "Removing 'client' (msal-angular-spa) if needed"
79+
Get-AzureADApplication -Filter "DisplayName eq 'msal-angular-spa'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
80+
$apps = Get-AzureADApplication -Filter "DisplayName eq 'msal-angular-spa'"
8181
if ($apps)
8282
{
8383
Remove-AzureADApplication -ObjectId $apps.ObjectId
@@ -86,10 +86,10 @@ Function Cleanup
8686
foreach ($app in $apps)
8787
{
8888
Remove-AzureADApplication -ObjectId $app.ObjectId
89-
Write-Host "Removed TodoListSPA.."
89+
Write-Host "Removed msal-angular-spa.."
9090
}
9191
# also remove service principals of this app
92-
Get-AzureADServicePrincipal -filter "DisplayName eq 'TodoListSPA'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
92+
Get-AzureADServicePrincipal -filter "DisplayName eq 'msal-angular-spa'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
9393

9494
}
9595

6-AccessControl/1-call-api-roles/AppCreationScripts/Configure.ps1

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ Function ConfigureApplications
197197
$user = Get-AzureADUser -ObjectId $creds.Account.Id
198198

199199
# Create the service AAD application
200-
Write-Host "Creating the AAD application (TodoListAPI)"
200+
Write-Host "Creating the AAD application (msal-dotnet-api)"
201201
# create the application
202-
$serviceAadApplication = New-AzureADApplication -DisplayName "TodoListAPI" `
202+
$serviceAadApplication = New-AzureADApplication -DisplayName "msal-dotnet-api" `
203203
-HomePage "https://localhost:44351/api/todolist" `
204204
-PublicClient $False
205205

@@ -228,48 +228,50 @@ Function ConfigureApplications
228228
# rename the user_impersonation scope if it exists to match the readme steps or add a new scope
229229
$scopes = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.OAuth2Permission]
230230

231-
if ($scopes.Count -ge 0)
231+
# delete default scope i.e. User_impersonation
232+
$scope = $serviceAadApplication.Oauth2Permissions | Where-Object { $_.Value -eq "User_impersonation" }
233+
if($scope -ne $null)
232234
{
233-
# add all existing scopes first
234-
$serviceAadApplication.Oauth2Permissions | foreach-object { $scopes.Add($_) }
235-
236-
$scope = $serviceAadApplication.Oauth2Permissions | Where-Object { $_.Value -eq "User_impersonation" }
235+
# disable the scope
236+
$scope.IsEnabled = $false
237+
$scopes.Add($scope)
238+
Set-AzureADApplication -ObjectId $serviceAadApplication.ObjectId -Oauth2Permissions $scopes
239+
240+
# clear the scope
241+
$scopes.Clear()
242+
Set-AzureADApplication -ObjectId $serviceAadApplication.ObjectId -Oauth2Permissions $scopes
243+
}
237244

238-
if ($scope -ne $null)
239-
{
240-
$scope.Value = "access_as_user"
241-
}
242-
else
243-
{
244-
# Add scope
245-
$scope = CreateScope -value "access_as_user" `
246-
-userConsentDisplayName "Access TodoListAPI" `
247-
-userConsentDescription "Allow the application to access TodoListAPI on your behalf." `
248-
-adminConsentDisplayName "Access TodoListAPI" `
245+
if ($scopes.Count -ge 0)
246+
{
247+
$scope = CreateScope -value access_as_user `
248+
-userConsentDisplayName "Access msal-dotnet-api" `
249+
-userConsentDescription "Allow the application to access msal-dotnet-api on your behalf." `
250+
-adminConsentDisplayName "Access msal-dotnet-api" `
249251
-adminConsentDescription "Allows the app to have the same access to information in the directory on behalf of the signed-in user."
250252

251-
$scopes.Add($scope)
252-
}
253+
$scopes.Add($scope)
254+
253255
}
254256

255257
# add/update scopes
256258
Set-AzureADApplication -ObjectId $serviceAadApplication.ObjectId -OAuth2Permission $scopes
257259

258-
Write-Host "Done creating the service application (TodoListAPI)"
260+
Write-Host "Done creating the service application (msal-dotnet-api)"
259261

260262
# URL of the AAD application in the Azure portal
261263
# Future? $servicePortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$serviceAadApplication.AppId+"/objectId/"+$serviceAadApplication.ObjectId+"/isMSAApp/"
262264
$servicePortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$serviceAadApplication.AppId+"/objectId/"+$serviceAadApplication.ObjectId+"/isMSAApp/"
263-
Add-Content -Value "<tr><td>service</td><td>$currentAppId</td><td><a href='$servicePortalUrl'>TodoListAPI</a></td></tr>" -Path createdApps.html
265+
Add-Content -Value "<tr><td>service</td><td>$currentAppId</td><td><a href='$servicePortalUrl'>msal-dotnet-api</a></td></tr>" -Path createdApps.html
264266

265267

266268
# Create the client AAD application
267-
Write-Host "Creating the AAD application (TodoListSPA)"
269+
Write-Host "Creating the AAD application (msal-angular-spa)"
268270
# create the application
269-
$clientAadApplication = New-AzureADApplication -DisplayName "TodoListSPA" `
271+
$clientAadApplication = New-AzureADApplication -DisplayName "msal-angular-spa" `
270272
-HomePage "http://localhost:4200/" `
271273
-ReplyUrls "http://localhost:4200/" `
272-
-IdentifierUris "https://$tenantName/TodoListSPA" `
274+
-IdentifierUris "https://$tenantName/msal-angular-spa" `
273275
-PublicClient $False
274276

275277
# create the service principal of the newly created application
@@ -292,18 +294,18 @@ Function ConfigureApplications
292294
$appRoles.Add($newRole)
293295
Set-AzureADApplication -ObjectId $clientAadApplication.ObjectId -AppRoles $appRoles
294296

295-
Write-Host "Done creating the client application (TodoListSPA)"
297+
Write-Host "Done creating the client application (msal-angular-spa)"
296298

297299
# URL of the AAD application in the Azure portal
298300
# Future? $clientPortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$clientAadApplication.AppId+"/objectId/"+$clientAadApplication.ObjectId+"/isMSAApp/"
299301
$clientPortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$clientAadApplication.AppId+"/objectId/"+$clientAadApplication.ObjectId+"/isMSAApp/"
300-
Add-Content -Value "<tr><td>client</td><td>$currentAppId</td><td><a href='$clientPortalUrl'>TodoListSPA</a></td></tr>" -Path createdApps.html
302+
Add-Content -Value "<tr><td>client</td><td>$currentAppId</td><td><a href='$clientPortalUrl'>msal-angular-spa</a></td></tr>" -Path createdApps.html
301303

302304
$requiredResourcesAccess = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.RequiredResourceAccess]
303305

304306
# Add Required Resources Access (from 'client' to 'service')
305307
Write-Host "Getting access from 'client' to 'service'"
306-
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "TodoListAPI" `
308+
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "msal-dotnet-api" `
307309
-requiredDelegatedPermissions "access_as_user" `
308310

309311
$requiredResourcesAccess.Add($requiredPermissions)
@@ -313,31 +315,37 @@ Function ConfigureApplications
313315
Write-Host "Granted permissions."
314316

315317
# Update config file for 'service'
316-
$configFile = $pwd.Path + "\..\TodoListAPI\appsettings.json"
318+
$configFile = $pwd.Path + "\..\API\appsettings.json"
317319
Write-Host "Updating the sample code ($configFile)"
318320
$dictionary = @{ "Enter the domain of your Azure AD tenant, e.g. contoso.onmicrosoft.com" = $tenantName;"Enter the ID of your Azure AD tenant copied from the Azure portal" = $tenantId;"Enter the application ID (clientId) of the 'TodoListAPI' application copied from the Azure portal" = $serviceAadApplication.AppId };
319321
ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary
320322

321323
# Update config file for 'client'
322-
$configFile = $pwd.Path + "\..\TodoListSPA\src\app\auth-config.json"
324+
$configFile = $pwd.Path + "\..\SPA\src\app\auth-config.ts"
323325
Write-Host "Updating the sample code ($configFile)"
324-
$dictionary = @{ "Enter the application ID (clientId) of the 'TodoListSPA' application copied from the Azure portal" = $clientAadApplication.AppId;"Enter the ID of your Azure AD tenant copied from the Azure portal" = $tenantId;"Enter the endpoint for TodoListAPI, e.g. https://localhost:44351/api/todolist" = $serviceAadApplication.HomePage;"Enter the API scopes as declared in the app registration 'Expose an API' blade, e.g. api://{clientId}/access_as_user" = ("api://"+$serviceAadApplication.AppId+"/access_as_user") };
326+
$dictionary = @{ "Enter_the_Application_Id_Here" = $clientAadApplication.AppId;"Enter_the_Tenant_Info_Here" = $tenantId;"Enter_the_Web_Api_Scope_here" = ("api://"+$serviceAadApplication.AppId+"/access_as_user") };
325327
ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary
326328
Write-Host ""
327329
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
328330
Write-Host "IMPORTANT: Please follow the instructions below to complete a few manual step(s) in the Azure portal":
329331
Write-Host "- For 'service'"
330332
Write-Host " - Navigate to '$servicePortalUrl'"
331-
Write-Host " - To receive the `roles` claim with the name of the app roles this user is assigned to, make sure that the user accounts you plan to sign-in to this app is assigned to the app roles of this SPA app. The guide, https://docs.microsoft.com/azure/active-directory/manage-apps/assign-user-or-group-access-portal#assign-a-user-to-an-app---portal provides step by step instructions." -ForegroundColor Red
333+
Write-Host " - To receive the `roles` claim with the name of the app roles this user is assigned to, make sure that the user accounts you plan to sign-in to this app is assigned to the app roles of this service instance. The guide, https://aka.ms/userassignmentrequired provides step by step instructions." -ForegroundColor Red
332334
Write-Host " - Or you can run the ..\CreateUsersAndAssignRoles.ps1 command to automatically create a number of users, and assign these users to the app roles of this app." -ForegroundColor Red
333335
Write-Host "- For 'client'"
334336
Write-Host " - Navigate to '$clientPortalUrl'"
335337
Write-Host " - Navigate to the portal and set the 'replyUrlsWithType' to 'Spa' in the application manifest" -ForegroundColor Red
336-
Write-Host " - To receive the `roles` claim with the name of the app roles this user is assigned to, make sure that the user accounts you plan to sign-in to this app is assigned to the app roles of this SPA app. The guide, https://docs.microsoft.com/azure/active-directory/manage-apps/assign-user-or-group-access-portal#assign-a-user-to-an-app---portal provides step by step instructions." -ForegroundColor Red
338+
Write-Host " - To receive the `roles` claim with the name of the app roles this user is assigned to, make sure that the user accounts you plan to sign-in to this app is assigned to the app roles of this SPA app. The guide, https://aka.ms/userassignmentrequired provides step by step instructions." -ForegroundColor Red
337339
Write-Host " - Or you can run the ..\CreateUsersAndAssignRoles.ps1 command to automatically create a number of users, and assign these users to the app roles of this app." -ForegroundColor Red
338340

339341
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
340-
342+
if($isOpenSSL -eq 'Y')
343+
{
344+
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
345+
Write-Host "You have generated certificate using OpenSSL so follow below steps: "
346+
Write-Host "Install the certificate on your system from current folder."
347+
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
348+
}
341349
Add-Content -Value "</tbody></table></body></html>" -Path createdApps.html
342350
}
343351

6-AccessControl/1-call-api-roles/AppCreationScripts/sample.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"Sample": {
3-
"Title": "An Angular single-page application (SPA) calling a protected web API and using App Roles to implement Role-Based Access Control (RBAC)",
3+
"Title": "Angular single-page application calling a protected web API and using App Roles to implement Role-Based Access Control",
44
"Level": 300,
5-
"Client": "Angular SPA TodoListSPA",
6-
"Service": ".NET Core web API TodoListAPI",
7-
"RepositoryUrl": "ms-identity-javascript-angular-spa-dotnetcore-webapi-roles-groups",
5+
"Client": "Angular SPA",
6+
"Service": ".NET Core web API",
7+
"RepositoryUrl": "ms-identity-javascript-angular-tutorial",
88
"Endpoint": "AAD v2.0"
99
},
1010
"AADApps": [
1111
{
1212
"Id": "service",
13-
"Name": "TodoListAPI-chapter1",
13+
"Name": "msal-dotnet-api",
1414
"Kind": "WebApi",
1515
"Audience": "AzureADMyOrg",
1616
"HomePage": "https://localhost:44351/api/todolist",
@@ -33,7 +33,7 @@
3333
},
3434
{
3535
"Id": "client",
36-
"Name": "TodoListSPA-chapter1",
36+
"Name": "msal-angular-spa",
3737
"Kind": "SinglePageApplication",
3838
"Audience": "AzureADMyOrg",
3939
"HomePage": "http://localhost:4200/",
@@ -67,7 +67,7 @@
6767
{
6868
"App": "service",
6969
"SettingKind": "Replace",
70-
"SettingFile": "\\..\\TodoListAPI\\appsettings.json",
70+
"SettingFile": "\\..\\API\\appsettings.json",
7171
"Mappings": [
7272
{
7373
"key": "Enter the domain of your Azure AD tenant, e.g. contoso.onmicrosoft.com",
@@ -87,22 +87,18 @@
8787
{
8888
"App": "client",
8989
"SettingKind": "Replace",
90-
"SettingFile": "\\..\\TodoListSPA\\src\\app\\auth-config.json",
90+
"SettingFile": "\\..\\SPA\\src\\app\\auth-config.ts",
9191
"Mappings": [
9292
{
93-
"key": "Enter the application ID (clientId) of the 'TodoListSPA' application copied from the Azure portal",
93+
"key": "Enter_the_Application_Id_Here",
9494
"value": "client.AppId"
9595
},
9696
{
97-
"key": "Enter the ID of your Azure AD tenant copied from the Azure portal",
97+
"key": "Enter_the_Tenant_Info_Here",
9898
"value": "$tenantId"
9999
},
100100
{
101-
"key": "Enter the endpoint for TodoListAPI, e.g. https://localhost:44351/api/todolist",
102-
"value": "service.HomePage"
103-
},
104-
{
105-
"key": "Enter the API scopes as declared in the app registration 'Expose an API' blade, e.g. api://{clientId}/access_as_user",
101+
"key": "Enter_the_Web_Api_Scope_here",
106102
"value": "service.Scope"
107103
}
108104
]

0 commit comments

Comments
 (0)