Skip to content

Commit c4bed14

Browse files
committed
update scripts, remove miw.ui
1 parent bce3cd0 commit c4bed14

File tree

9 files changed

+102
-23
lines changed

9 files changed

+102
-23
lines changed

2-WebApp-graph-user/2-6-BFF-Proxy/AppCreationScripts/Configure-WithCertificates.ps1

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,44 @@ Function UpdateTextFile([string] $configFilePath, [System.Collections.HashTable]
126126
Set-Content -Path $configFilePath -Value $lines -Force
127127
}
128128

129+
<#.Description
130+
This function takes a string input as a single line, matches a key value and replaces with the replacement value
131+
#>
132+
Function ReplaceInLine([string] $line, [string] $key, [string] $value)
133+
{
134+
$index = $line.IndexOf($key)
135+
if ($index -ige 0)
136+
{
137+
$index2 = $index+$key.Length
138+
$line = $line.Substring(0, $index) + $value + $line.Substring($index2)
139+
}
140+
return $line
141+
}
142+
143+
<#.Description
144+
This function takes a dictionary of keys to search and their replacements and replaces the placeholders in a text file
145+
#>
146+
Function ReplaceInTextFile([string] $configFilePath, [System.Collections.HashTable] $dictionary)
147+
{
148+
$lines = Get-Content $configFilePath
149+
$index = 0
150+
while($index -lt $lines.Length)
151+
{
152+
$line = $lines[$index]
153+
foreach($key in $dictionary.Keys)
154+
{
155+
if ($line.Contains($key))
156+
{
157+
$lines[$index] = ReplaceInLine $line $key $dictionary[$key]
158+
}
159+
}
160+
$index++
161+
}
162+
163+
Set-Content -Path $configFilePath -Value $lines -Force
164+
}
165+
166+
129167
<#.Description
130168
This function takes a string as input and creates an instance of an Optional claim object
131169
#>
@@ -284,13 +322,13 @@ Function ConfigureApplications
284322
# $configFile = $pwd.Path + "\..\CallGraphBFF\appsettings.json"
285323
$configFile = $(Resolve-Path ($pwd.Path + "\..\CallGraphBFF\appsettings.json"))
286324

287-
$dictionary = @{ "TenantId" = $tenantId;"ClientId" = $clientAadApplication.AppId;"ClientSecret" = $clientAppKey };
325+
$dictionary = @{ "Enter_the_Tenant_Id_Here" = $tenantId;"Enter_the_Application_Id_Here" = $clientAadApplication.AppId;"Enter_the_Client_Secret_Here" = $clientAppKey };
288326

289327
Write-Host "Updating the sample config '$configFile' with the following config values:" -ForegroundColor Yellow
290328
$dictionary
291329
Write-Host "-----------------"
292330

293-
UpdateTextFile -configFilePath $configFile -dictionary $dictionary
331+
ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary
294332
Write-Host "- App client - created at $clientPortalUrl"
295333

296334

2-WebApp-graph-user/2-6-BFF-Proxy/AppCreationScripts/Configure.ps1

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,44 @@ Function UpdateTextFile([string] $configFilePath, [System.Collections.HashTable]
126126
Set-Content -Path $configFilePath -Value $lines -Force
127127
}
128128

129+
<#.Description
130+
This function takes a string input as a single line, matches a key value and replaces with the replacement value
131+
#>
132+
Function ReplaceInLine([string] $line, [string] $key, [string] $value)
133+
{
134+
$index = $line.IndexOf($key)
135+
if ($index -ige 0)
136+
{
137+
$index2 = $index+$key.Length
138+
$line = $line.Substring(0, $index) + $value + $line.Substring($index2)
139+
}
140+
return $line
141+
}
142+
143+
<#.Description
144+
This function takes a dictionary of keys to search and their replacements and replaces the placeholders in a text file
145+
#>
146+
Function ReplaceInTextFile([string] $configFilePath, [System.Collections.HashTable] $dictionary)
147+
{
148+
$lines = Get-Content $configFilePath
149+
$index = 0
150+
while($index -lt $lines.Length)
151+
{
152+
$line = $lines[$index]
153+
foreach($key in $dictionary.Keys)
154+
{
155+
if ($line.Contains($key))
156+
{
157+
$lines[$index] = ReplaceInLine $line $key $dictionary[$key]
158+
}
159+
}
160+
$index++
161+
}
162+
163+
Set-Content -Path $configFilePath -Value $lines -Force
164+
}
165+
166+
129167
<#.Description
130168
This function takes a string as input and creates an instance of an Optional claim object
131169
#>
@@ -266,13 +304,13 @@ Function ConfigureApplications
266304
# $configFile = $pwd.Path + "\..\CallGraphBFF\appsettings.json"
267305
$configFile = $(Resolve-Path ($pwd.Path + "\..\CallGraphBFF\appsettings.json"))
268306

269-
$dictionary = @{ "TenantId" = $tenantId;"ClientId" = $clientAadApplication.AppId;"ClientSecret" = $clientAppKey };
307+
$dictionary = @{ "Enter_the_Tenant_Id_Here" = $tenantId;"Enter_the_Application_Id_Here" = $clientAadApplication.AppId;"Enter_the_Client_Secret_Here" = $clientAppKey };
270308

271309
Write-Host "Updating the sample config '$configFile' with the following config values:" -ForegroundColor Yellow
272310
$dictionary
273311
Write-Host "-----------------"
274312

275-
UpdateTextFile -configFilePath $configFile -dictionary $dictionary
313+
ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary
276314
Write-Host "- App client - created at $clientPortalUrl"
277315

278316

2-WebApp-graph-user/2-6-BFF-Proxy/AppCreationScripts/sample.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@
4848
"CodeConfiguration": [
4949
{
5050
"App": "client",
51-
"SettingKind": "JSON",
51+
"SettingKind": "Replace",
5252
"SettingFile": "\\..\\CallGraphBFF\\appsettings.json",
5353
"Mappings": [
5454
{
55-
"key": "TenantId",
55+
"key": "Enter_the_Tenant_Id_Here",
5656
"value": "$tenantId"
5757
},
5858
{
59-
"key": "ClientId",
59+
"key": "Enter_the_Application_Id_Here",
6060
"value": ".AppId"
6161
},
6262
{
63-
"key": "ClientSecret",
63+
"key": "Enter_the_Client_Secret_Here",
6464
"value": ".AppKey"
6565
}
6666
]

2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF/CallGraphBFF.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
77
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
@@ -14,10 +14,10 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="6.0.10" />
18-
<PackageReference Include="Microsoft.Identity.Web" Version="2.7.0" />
19-
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="2.7.0" />
20-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="2.7.0" />
17+
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="7.0.5" />
18+
<PackageReference Include="Microsoft.Identity.Web" Version="2.9.0" />
19+
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="2.9.0" />
20+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="2.9.0" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF/ClientApp/package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
options.Events = new CustomCookieAuthenticationEvents(); // modifies the behavior of certain cookie authentication events.
3939
});
4040

41+
builder.Services.AddControllersWithViews();
42+
4143
var app = builder.Build();
4244

4345
// Configure the HTTP request pipeline.

2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF/Utils/CustomCookieAuthenticationEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public async override Task ValidatePrincipal(CookieValidatePrincipalContext cont
2727
var tokenAcquisition = context.HttpContext.RequestServices.GetRequiredService<ITokenAcquisition>();
2828

2929
string token = await tokenAcquisition.GetAccessTokenForUserAsync(
30-
scopes: new[] { "User.Read" },
30+
scopes: new[] { "openid" },
3131
user: context.Principal);
3232
}
3333
catch (MicrosoftIdentityWebChallengeUserException ex) when (AccountDoesNotExitInTokenCache(ex))

2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF/appsettings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"AzureAd": {
33
"Instance": "https://login.microsoftonline.com/",
4-
"TenantId": "[Enter 'common', or 'organizations' or the Tenant Id (obtained from the Azure portal. Select 'Endpoints' from the 'App registrations' blade and use the GUID in any of the URLs), e.g. da41245a5-11b3-996c-00a8-4d99re19f292]",
5-
"ClientId": "[Enter the Client Id (Application ID obtained from the Azure portal), e.g. ba74781c2-53c2-442a-97c2-3d60re42f403]",
4+
"TenantId": "Enter_the_Tenant_Id_Here",
5+
"ClientId": "Enter_the_Application_Id_Here",
66
"ClientCredentials": [
77
{
88
"SourceType": "ClientSecret",
9-
"ClientSecret": "[Copy the client secret added to the app from the Azure portal]"
9+
"ClientSecret": "Enter_the_Client_Secret_Here"
1010
},
1111
// {
1212
// "SourceType": "StoreWithDistinguishedName",
@@ -32,4 +32,4 @@
3232
}
3333
},
3434
"AllowedHosts": "*"
35-
}
35+
}

2-WebApp-graph-user/2-6-BFF-Proxy/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
179179
> In the steps below, "ClientID" is the same as "Application ID" or "AppId".
180180
181181
1. Open the `2-6-BFF-Proxy/CallGraphBFF/appsettings.json` file.
182-
1. Find the key `TenantId` and replace the existing value with your Azure AD tenant/directory ID.
183-
1. Find the key `ClientId` and replace the existing value with the application ID (clientId) of `CallGraphBFF` app copied from the Azure portal.
184-
1. Find the key `ClientSecret` and replace the existing value with the generated secret that you saved during the creation of `CallGraphBFF` copied from the Azure portal.
182+
1. Find the string `Enter_the_Tenant_Id_Here` and replace it with your Azure AD tenant/directory ID.
183+
1. Find the string `Enter_the_Application_Id_Here` and replace it with the application ID (clientId) of `CallGraphBFF` app copied from the Azure portal.
184+
1. Find the string `Enter_the_Client_Secret_Here` and replace it with the generated secret that you saved during the creation of `CallGraphBFF` copied from the Azure portal.
185185

186186
### Step 5: Running the sample
187187

0 commit comments

Comments
 (0)