Skip to content

Commit 3f2a1e6

Browse files
authored
Merge pull request #37 from damienbod/dev-graph-update
Graph SDK 5 support, updated packages
2 parents 916c9c8 + 9075cb8 commit 3f2a1e6

File tree

9 files changed

+42
-32
lines changed

9 files changed

+42
-32
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
[Readme](https://github.com/damienbod/Blazor.BFF.AzureB2C.Template/blob/main/README.md)
44

5+
**2023-06-21** 2.1.0
6+
- Switched to Graph SDK 5
7+
- Updated packages
8+
59
**2023-03-12** 2.0.2
610
- Fix security headers, use on app requests including API calls
711
- Updated packages

README-NUGET.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This template can be used to create a Blazor WASM application hosted in an ASP.N
1717
### install
1818

1919
```
20-
dotnet new -i Blazor.BFF.AzureB2C.Template
20+
dotnet new install Blazor.BFF.AzureB2C.Template
2121
```
2222

2323
### run
@@ -172,7 +172,7 @@ public IActionResult Get()
172172
### uninstall
173173

174174
```
175-
dotnet new -u Blazor.BFF.AzureB2C.Template
175+
dotnet new uninstall Blazor.BFF.AzureB2C.Template
176176
```
177177

178178
### Troubleshooting

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This template can be used to create a Blazor WASM application hosted in an ASP.N
2525
### install
2626

2727
```
28-
dotnet new -i Blazor.BFF.AzureB2C.Template
28+
dotnet new install Blazor.BFF.AzureB2C.Template
2929
```
3030

3131
### run
@@ -180,7 +180,7 @@ public IActionResult Get()
180180
### uninstall
181181

182182
```
183-
dotnet new -u Blazor.BFF.AzureB2C.Template
183+
dotnet new uninstall Blazor.BFF.AzureB2C.Template
184184
```
185185

186186
## Development
@@ -198,13 +198,13 @@ nuget pack content/Blazor.BFF.AzureB2C.Template.nuspec
198198
Locally built nupkg:
199199

200200
```
201-
dotnet new -i Blazor.BFF.AzureB2C.Template.2.0.2.nupkg
201+
dotnet new install Blazor.BFF.AzureB2C.Template.2.1.0.nupkg
202202
```
203203

204204
Local folder:
205205

206206
```
207-
dotnet new -i <PATH>
207+
dotnet new install <PATH>
208208
```
209209

210210
Where `<PATH>` is the path to the folder containing .template.config.

content/Blazor.BFF.AzureB2C.Template.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
33
<metadata>
44
<id>Blazor.BFF.AzureB2C.Template</id>
5-
<version>2.0.2</version>
5+
<version>2.1.0</version>
66
<title>Blazor.BFF.AzureB2C.Template</title>
77
<license type="file">LICENSE</license>
88
<description>Blazor BFF template for WASM ASP.NET Core hosted</description>
@@ -15,7 +15,7 @@
1515
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1616
<copyright>2023 damienbod</copyright>
1717
<summary>This template provides a simple Blazor template with BFF server authentication WASM hosted</summary>
18-
<releaseNotes>Updated to .NET 7, updated security headers</releaseNotes>
18+
<releaseNotes>Updated to Graph SDK 5, updated packages</releaseNotes>
1919
<repository type="git" url="https://github.com/damienbod/Blazor.BFF.AzureB2C.Template" />
2020
<packageTypes>
2121
<packageType name="Template" />

content/BlazorBffAzureB2C/Client/BlazorBffAzureB2C.Client.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.3" />
12-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.3" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.7" />
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.7" PrivateAssets="all" />
1313
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
14-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="7.0.3" />
14+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="7.0.7" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

content/BlazorBffAzureB2C/Server/BlazorBffAzureB2C.Server.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.3" />
16-
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.3" NoWarn="NU1605" />
17-
<PackageReference Include="Microsoft.Identity.Web" Version="2.5.0" />
18-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="2.5.0" />
19-
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="2.5.0" />
20-
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.18.0" />
15+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.7" />
16+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.7" NoWarn="NU1605" />
17+
<PackageReference Include="Microsoft.Identity.Web" Version="2.12.4" />
18+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="2.12.4" />
19+
<PackageReference Include="Microsoft.Identity.Web.GraphServiceClient" Version="2.12.4" />
20+
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.19.0" />
2121
</ItemGroup>
2222

2323
</Project>

content/BlazorBffAzureB2C/Server/Controllers/GraphApiCallsController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ public async Task<IEnumerable<string>> Get()
3030
if (userId != null)
3131
{
3232
var userData = await _msGraphtService.GetGraphApiUser(userId);
33+
if (userData == null)
34+
return new List<string> { "no user data" };
35+
3336
return new List<string> { $"DisplayName: {userData.DisplayName}",
3437
$"GivenName: {userData.GivenName}", $"AboutMe: {userData.AboutMe}" };
3538
}
3639

37-
return Array.Empty<string>();
38-
40+
return Array.Empty<string>();
3941
}
4042
}

content/BlazorBffAzureB2C/Server/MsGraphClaimsTransformation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public async Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
2727
{
2828
var groupIds = await _msGraphService.GetGraphApiUserMemberGroups(objectIdentifier.Value);
2929

30-
foreach (var groupId in groupIds.ToList())
30+
foreach (var groupId in groupIds!.Value!.ToList())
3131
{
3232
claimsIdentity.AddClaim(new Claim(groupClaimType, groupId));
3333
}
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.Graph;
1+

2+
using Microsoft.Graph.Users.Item.GetMemberGroups;
3+
using Microsoft.Graph.Models;
24

35
namespace BlazorBffAzureB2C.Server.Services;
46

@@ -11,34 +13,36 @@ public MsGraphService(GraphApplicationClientService graphApplicationClientServic
1113
_graphApplicationClientService = graphApplicationClientService;
1214
}
1315

14-
public async Task<User> GetGraphApiUser(string userId)
16+
public async Task<User?> GetGraphApiUser(string userId)
1517
{
16-
var graphServiceClient = _graphApplicationClientService.GetGraphClientWithClientSecretCredential();
18+
var graphServiceClient = _graphApplicationClientService
19+
.GetGraphClientWithClientSecretCredential();
1720

1821
return await graphServiceClient.Users[userId]
19-
.Request()
2022
.GetAsync();
2123
}
2224

23-
public async Task<IUserAppRoleAssignmentsCollectionPage> GetGraphApiUserAppRoles(string userId)
25+
public async Task<AppRoleAssignmentCollectionResponse?> GetGraphApiUserAppRoles(string userId)
2426
{
25-
var graphServiceClient = _graphApplicationClientService.GetGraphClientWithClientSecretCredential();
27+
var graphServiceClient = _graphApplicationClientService
28+
.GetGraphClientWithClientSecretCredential();
2629

2730
return await graphServiceClient.Users[userId]
2831
.AppRoleAssignments
29-
.Request()
3032
.GetAsync();
3133
}
3234

33-
public async Task<IDirectoryObjectGetMemberGroupsCollectionPage> GetGraphApiUserMemberGroups(string userId)
35+
public async Task<GetMemberGroupsResponse?> GetGraphApiUserMemberGroups(string userId)
3436
{
3537
var graphServiceClient = _graphApplicationClientService.GetGraphClientWithClientSecretCredential();
3638

37-
var securityEnabledOnly = true;
39+
var requestBody = new GetMemberGroupsPostRequestBody
40+
{
41+
SecurityEnabledOnly = true,
42+
};
3843

3944
return await graphServiceClient.Users[userId]
40-
.GetMemberGroups(securityEnabledOnly)
41-
.Request()
42-
.PostAsync();
45+
.GetMemberGroups
46+
.PostAsync(requestBody);
4347
}
4448
}

0 commit comments

Comments
 (0)