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

Commit f9e6f25

Browse files
committed
update ps scripts
1 parent e634a7f commit f9e6f25

File tree

8 files changed

+209
-1382
lines changed

8 files changed

+209
-1382
lines changed

5-AccessControl/2-call-api-groups/API/TodoListAPI/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"TenantId": "Enter the ID of your Azure AD tenant copied from the Azure portal",
55
"ClientId": "Enter the application ID (clientId) of the 'TodoListAPI' application copied from the Azure portal",
66
"ClientSecret": "Enter the Client Secret of the 'TodoListAPI' application copied from the Azure portal",
7-
"Scopes": [ "access_as_user" ],
7+
"Scopes": [ "access_via_group_assignment" ],
88
"Groups": {
99
"GroupAdmin": "Enter the objectID for GroupAdmin group copied from Azure Portal",
1010
"GroupMember": "Enter the objectID for GroupMember group copied from Azure Portal"

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

Lines changed: 98 additions & 673 deletions
Large diffs are not rendered by default.

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

Lines changed: 85 additions & 668 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Function Cleanup
5757

5858
foreach ($app in $apps)
5959
{
60-
Remove-MgApplication -ApplicationId $app.Id -Debug
60+
Remove-MgApplication -ApplicationId $app.Id
6161
Write-Host "Removed msal-angular-app.."
6262
}
6363

@@ -72,16 +72,6 @@ Function Cleanup
7272
Write-Warning $Error[0]
7373
Write-Host "Unable to remove ServicePrincipal 'msal-angular-app'. Error is $message. Try deleting manually from Enterprise applications." -ForegroundColor White -BackgroundColor Red
7474
}
75-
Write-Host "You may want to remove the security group 'GroupAdmin' if it was created to test this sample only."
76-
#if($null -ne (Get-MgGroup -Filter "DisplayName eq 'GroupAdmin'"))
77-
#{
78-
# Remove-MgGroup -GroupId (Get-MgGroup -Filter "DisplayName eq 'GroupAdmin'").Id
79-
#}
80-
Write-Host "You may want to remove the security group 'GroupMember' if it was created to test this sample only."
81-
#if($null -ne (Get-MgGroup -Filter "DisplayName eq 'GroupMember'"))
82-
#{
83-
# Remove-MgGroup -GroupId (Get-MgGroup -Filter "DisplayName eq 'GroupMember'").Id
84-
#}
8575
}
8676

8777
if ($null -eq (Get-Module -ListAvailable -Name "Microsoft.Graph.Applications")) {

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Function ConfigureApplications
214214
}
215215

216216
$scopes = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphPermissionScope]
217-
$scope = CreateScope -value access_as_user `
217+
$scope = CreateScope -value access_via_group_assignment `
218218
-userConsentDisplayName "Access msal-angular-app" `
219219
-userConsentDescription "Allow the application to access msal-angular-app on your behalf." `
220220
-adminConsentDisplayName "Access msal-angular-app" `
@@ -234,19 +234,23 @@ Function ConfigureApplications
234234

235235
# Add Required Resources Access (from 'client' to 'client')
236236
Write-Host "Getting access from 'client' to 'client'"
237-
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "msal-angular-app" `
238-
-requiredDelegatedPermissions "access_as_user" `
239-
$requiredResourcesAccess.Add($requiredPermissions)
237+
$requiredPermission = GetRequiredPermissions -applicationDisplayName "msal-angular-app" `
238+
-requiredDelegatedPermissions "access_via_group_assignment" `
239+
240+
$requiredResourcesAccess.Add($requiredPermission)
240241

241242
# Add Required Resources Access (from 'client' to 'Microsoft Graph')
242243
Write-Host "Getting access from 'client' to 'Microsoft Graph'"
243-
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "Microsoft Graph" `
244+
$requiredPermission = GetRequiredPermissions -applicationDisplayName "Microsoft Graph" `
244245
-requiredDelegatedPermissions "User.Read|GroupMember.Read.All" `
245-
$requiredResourcesAccess.Add($requiredPermissions)
246+
247+
$requiredResourcesAccess.Add($requiredPermission)
246248
Update-MgApplication -ApplicationId $clientAadApplication.Id -RequiredResourceAccess $requiredResourcesAccess
247249
Write-Host "Granted permissions."
248250

249251
Write-Host "Successfully registered and configured that app registration for 'msal-angular-app' at" -ForegroundColor Green
252+
253+
# print the registered app portal URL for any further navigation
250254
$clientPortalUrl
251255
Function UpdateLine([string] $line, [string] $value)
252256
{
@@ -288,7 +292,8 @@ Function UpdateTextFile([string] $configFilePath, [System.Collections.HashTable]
288292

289293
$dictionary = @{ "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" = $clientAadApplication.AppId;"Enter the Client Secret of the 'TodoListAPI' application copied from the Azure portal" = $clientAppKey };
290294

291-
Write-Host "Updating the sample config '$configFile' with the following config values"
295+
Write-Host "Updating the sample config '$configFile' with the following config values:"
296+
$dictionary
292297

293298
ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary
294299

@@ -298,7 +303,8 @@ Function UpdateTextFile([string] $configFilePath, [System.Collections.HashTable]
298303

299304
$dictionary = @{ "Enter_the_Application_Id_Here" = $clientAadApplication.AppId;"Enter_the_Tenant_Info_Here" = $tenantId;"Enter_the_Web_Api_Application_Id_Here" = $clientAadApplication.AppId };
300305

301-
Write-Host "Updating the sample config '$configFile' with the following config values"
306+
Write-Host "Updating the sample config '$configFile' with the following config values:"
307+
$dictionary
302308

303309
ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary
304310
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
@@ -307,7 +313,6 @@ Function UpdateTextFile([string] $configFilePath, [System.Collections.HashTable]
307313
Write-Host " - Navigate to $clientPortalUrl"
308314
Write-Host " - This script has created a group named GroupAdmin for you. On Azure portal, assign some users to it, and configure your ID and Access token to emit GroupID in your app registration." -ForegroundColor Red
309315
Write-Host " - This script has created a group named GroupMember for you. On Azure portal, assign some users to it, and configure your ID and Access token to emit GroupID in your app registration." -ForegroundColor Red
310-
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
311316
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
312317
if($isOpenSSL -eq 'Y')
313318
{

5-AccessControl/2-call-api-groups/AppCreationScripts/sample.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"ReplyUrls": "http://localhost:4200/, http://localhost:4200/auth",
3131
"GroupMembershipClaims": "SecurityGroup",
3232
"Scopes": [
33-
"access_as_user"
33+
"access_via_group_assignment"
3434
],
3535
"Sample": {
3636
"SampleSubPath": "5-AccessControl\\2-call-api-groups\\SPA",
@@ -40,7 +40,7 @@
4040
{
4141
"Resource": "client",
4242
"DelegatedPermissions": [
43-
"access_as_user"
43+
"access_via_group_assignment"
4444
]
4545
},
4646
{
@@ -51,16 +51,6 @@
5151
]
5252
}
5353
],
54-
"SecurityGroups": [
55-
{
56-
"Name": "GroupAdmin",
57-
"Description": "Admin Security Group"
58-
},
59-
{
60-
"Name": "GroupMember",
61-
"Description": "User Security Group"
62-
}
63-
],
6454
"OptionalClaims": {
6555
"IdTokenClaims": [
6656
"acct"

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ This sample demonstrates a cross-platform application suite involving an Angular
3434

3535
Access control in Azure AD can also be done with **App Roles**, as shown in the [previous tutorial](../1-call-api-roles/README.md). **Security Groups** and **App Roles** in Azure AD are by no means mutually exclusive - they can be used in tandem to provide even finer grained access control.
3636

37+
In the sample, a dashboard component allows signed-in users to see the tasks assigned to them or other users based on their memberships to one of the two security groups, **GroupAdmin** and **GroupMember**.
38+
3739
> :information_source: See the community call: [Implement authorization in your applications with the Microsoft identity platform](https://www.youtube.com/watch?v=LRoc-na27l0)
3840
3941
> :information_source: See the community call: [Deep dive on using MSAL.js to integrate Angular single-page applications with Azure Active Directory](https://www.youtube.com/watch?v=EJey9KP1dZA)
4042
4143
## Scenario
4244

43-
In the sample, a dashboard component allows signed-in users to see the tasks assigned to them or other users based on their memberships to one of the two security groups, **GroupAdmin** and **GroupMember**.
44-
4545
- The **TodoListSPA** uses [MSAL Angular](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-angular) to authenticate a user with the Microsoft identity platform.
4646
- The app then obtains an [access token](https://docs.microsoft.com/azure/active-directory/develop/access-tokens) from Azure Active Directory (Azure AD) on behalf of the authenticated user for the **TodoListAPI**.
4747
- **TodoListAPI** uses [Microsoft.Identity.Web](https://github.com/AzureAD/microsoft-identity-web) to protect its endpoint and accept only authorized calls.
@@ -107,9 +107,9 @@ For more information and potential issues, see: [HTTPS in .NET Core](https://doc
107107

108108
### Step 5: Register the sample application(s) in your tenant
109109

110-
While there are multiple project in this sample, we'd register just one app with Azure AD and use the registered app's *client id* in both apps. This reuse of app ids (client ids) is used when the apps themselves are just components of one larger app topology.
110+
> :information_source: While there are multiple project in this sample, we'd register just one app with Azure AD and use the registered app's *client id* in both apps. This reuse of app ids (client ids) is used when the apps themselves are just components of one larger app topology.
111111
112-
There is one project in this sample. To register it, you can:
112+
There are two projects in this sample. To register it, you can:
113113

114114
- follow the steps below for manually register your apps
115115
- or use PowerShell scripts that:
@@ -172,7 +172,7 @@ To manually register the apps, as a first step you'll need to:
172172
173173
1. All APIs must publish a minimum of one [scope](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-authorization-code), also called [Delegated Permission](https://docs.microsoft.com/azure/active-directory/develop/v2-permissions-and-consent#permission-types), for the client apps to obtain an access token for a *user* successfully. To publish a scope, follow these steps:
174174
1. Select **Add a scope** button open the **Add a scope** screen and Enter the values as indicated below:
175-
1. For **Scope name**, use `access_as_user`.
175+
1. For **Scope name**, use `access_via_group_assignment`.
176176
1. Select **Admins and users** options for **Who can consent?**.
177177
1. For **Admin consent display name** type in *Access 'msal-angular-app' as the signed-in user.*.
178178
1. For **Admin consent description** type in *Allow the app to access the 'msal-angular-app' as a signed-in user.*.
@@ -304,8 +304,8 @@ You have two different options available to you on how you can further configure
304304
1. Find the app key `groups.groupMember` and replace the existing value with the **object ID** of the **GroupMember** group copied from the Azure portal.
305305
306306
1. Open the `API\TodoListAPI\appsettings.json` file.
307-
2. Find the app key `Groups.GroupAdmin` and replace the existing value with the object ID of the **GroupAdmin** group copied from the Azure portal.
308-
3. Find the app key `Groups.GroupMember` and replace the existing value with the object ID of the **GroupMember** group copied from the Azure portal.
307+
2. Find the app key `Groups.GroupAdmin` and replace the existing value with the **object ID** of the **GroupAdmin** group copied from the Azure portal.
308+
3. Find the app key `Groups.GroupMember` and replace the existing value with the **object ID** of the **GroupMember** group copied from the Azure portal.
309309
310310
### Step 6: Running the sample
311311

5-AccessControl/2-call-api-groups/SPA/src/app/auth-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const msalConfig: Configuration = {
4848
export const protectedResources = {
4949
apiTodoList: {
5050
endpoint: "https://localhost:44351/api/todolist",
51-
scopes: ["api://Enter_the_Web_Api_Application_Id_Here/access_as_user"]
51+
scopes: ["api://Enter_the_Web_Api_Application_Id_Here/access_via_group_assignment"]
5252
},
5353
apiGraph: {
5454
endpoint: "https://graph.microsoft.com/v1.0/me/memberOf",

0 commit comments

Comments
 (0)