Skip to content

Commit 5194b7e

Browse files
authored
Merge pull request #13 from damienbod/dev/object-identifier-ms-graph
Object identifier Microsoft graph
2 parents 99d07e2 + fd41971 commit 5194b7e

File tree

9 files changed

+29
-34
lines changed

9 files changed

+29
-34
lines changed

Changelog.md

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

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

5+
**2022-01-23** 1.0.8
6+
- Using the object identifier to request the MS graph data
7+
58
**2022-01-23** 1.0.7
69
- Remove PWA items, default template uses anti-forgery cookies and no PWA support
710
(Will consider supporting this later, requires switching to CORS preflight CSRF protection)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ nuget pack content/Blazor.BFF.AzureB2C.Template.nuspec
9191
Locally built nupkg:
9292

9393
```
94-
dotnet new -i Blazor.BFF.AzureB2C.Template.1.0.7.nupkg
94+
dotnet new -i Blazor.BFF.AzureB2C.Template.1.0.8.nupkg
9595
```
9696

9797
Local folder:

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>1.0.7</version>
5+
<version>1.0.8</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>2022 damienbod</copyright>
1717
<summary>This template provides a simple Blazor template with BFF server authentication WASM hosted</summary>
18-
<releaseNotes>Remove PWA items, default template uses anti-forgery cookies and no PWA support, Using the AuthorizedHandler for protected requests</releaseNotes>
18+
<releaseNotes>Use object identifier to select MS Graph users</releaseNotes>
1919
<repository type="git" url="https://github.com/damienbod/Blazor.BFF.AzureB2C.Template" />
2020
<packageTypes>
2121
<packageType name="Template" />

content/BlazorBffAzureB2C/Server/BlazorBffAzureB2C.Server.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.1" NoWarn="NU1605" />
18-
<PackageReference Include="Microsoft.Graph" Version="4.14.0" />
19-
<PackageReference Include="Microsoft.Identity.Web" Version="1.22.1" />
20-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.1" />
18+
<PackageReference Include="Microsoft.Graph" Version="4.17.0" />
19+
<PackageReference Include="Microsoft.Identity.Web" Version="1.22.3" />
20+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.3" />
2121
<PackageReference Include="IdentityModel.AspNetCore" Version="4.1.2" />
2222
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.16.1" />
2323
</ItemGroup>

content/BlazorBffAzureB2C/Server/Controllers/GraphApiCallsController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace BlazorBffAzureB2C.Server.Controllers
1515
[Route("api/[controller]")]
1616
public class GraphApiCallsController : ControllerBase
1717
{
18-
private GraphApiClientService _graphApiClientService;
18+
private MsGraphService _graphApiClientService;
1919

20-
public GraphApiCallsController(GraphApiClientService graphApiClientService)
20+
public GraphApiCallsController(MsGraphService graphApiClientService)
2121
{
2222
_graphApiClientService = graphApiClientService;
2323
}

content/BlazorBffAzureB2C/Server/GraphApiClaimsTransformation.cs renamed to content/BlazorBffAzureB2C/Server/MsGraphClaimsTransformation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
namespace BlazorBffAzureB2C.Server
88
{
9-
public class GraphApiClaimsTransformation : IClaimsTransformation
9+
public class MsGraphClaimsTransformation : IClaimsTransformation
1010
{
11-
private readonly GraphApiClientService _graphApiClientService;
11+
private readonly MsGraphService _msGraphService;
1212

13-
public GraphApiClaimsTransformation(GraphApiClientService graphApiClientService)
13+
public MsGraphClaimsTransformation(MsGraphService msGraphService)
1414
{
1515

16-
_graphApiClientService = graphApiClientService;
16+
_msGraphService = msGraphService;
1717
}
1818

1919
public async Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
@@ -22,10 +22,10 @@ public async Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
2222
var groupClaimType = "group";
2323
if (!principal.HasClaim(claim => claim.Type == groupClaimType))
2424
{
25-
var nameidentifierClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";
26-
var nameidentifier = principal.Claims.FirstOrDefault(t => t.Type == nameidentifierClaimType);
25+
var objectidentifierClaimType = "http://schemas.microsoft.com/identity/claims/objectidentifier";
26+
var objectIdentifier = principal.Claims.FirstOrDefault(t => t.Type == objectidentifierClaimType);
2727

28-
var groupIds = await _graphApiClientService.GetGraphApiUserMemberGroups(nameidentifier.Value);
28+
var groupIds = await _msGraphService.GetGraphApiUserMemberGroups(objectIdentifier.Value);
2929

3030
foreach (var groupId in groupIds.ToList())
3131
{

content/BlazorBffAzureB2C/Server/Program.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
using Microsoft.AspNetCore.Hosting;
2-
using Microsoft.Extensions.Configuration;
32
using Microsoft.Extensions.Hosting;
4-
using Microsoft.Extensions.Logging;
5-
using System;
6-
using System.Collections.Generic;
7-
using System.Linq;
8-
using System.Threading.Tasks;
93

104
namespace BlazorBffAzureB2C.Server
115
{

content/BlazorBffAzureB2C/Server/Services/GraphApiClientService.cs renamed to content/BlazorBffAzureB2C/Server/Services/MsGraphService.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
namespace BlazorBffAzureB2C.Server.Services
77
{
8-
public class GraphApiClientService
8+
public class MsGraphService
99
{
1010
private readonly GraphServiceClient _graphServiceClient;
1111

12-
public GraphApiClientService(IConfiguration configuration)
12+
public MsGraphService(IConfiguration configuration)
1313
{
1414
string[] scopes = configuration.GetValue<string>("GraphApi:Scopes")?.Split(' ');
1515
var tenantId = configuration.GetValue<string>("GraphApi:TenantId");
@@ -33,18 +33,16 @@ public GraphApiClientService(IConfiguration configuration)
3333
public async Task<User> GetGraphApiUser(string userId)
3434
{
3535
return await _graphServiceClient.Users[userId]
36-
.Request()
37-
.GetAsync()
38-
.ConfigureAwait(false);
36+
.Request()
37+
.GetAsync();
3938
}
4039

4140
public async Task<IUserAppRoleAssignmentsCollectionPage> GetGraphApiUserAppRoles(string userId)
4241
{
4342
return await _graphServiceClient.Users[userId]
44-
.AppRoleAssignments
45-
.Request()
46-
.GetAsync()
47-
.ConfigureAwait(false);
43+
.AppRoleAssignments
44+
.Request()
45+
.GetAsync();
4846
}
4947

5048
public async Task<IDirectoryObjectGetMemberGroupsCollectionPage> GetGraphApiUserMemberGroups(string userId)
@@ -53,8 +51,8 @@ public async Task<IDirectoryObjectGetMemberGroupsCollectionPage> GetGraphApiUser
5351

5452
return await _graphServiceClient.Users[userId]
5553
.GetMemberGroups(securityEnabledOnly)
56-
.Request().PostAsync()
57-
.ConfigureAwait(false);
54+
.Request()
55+
.PostAsync();
5856
}
5957
}
6058
}

content/BlazorBffAzureB2C/Server/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public Startup(IConfiguration configuration)
2323

2424
public void ConfigureServices(IServiceCollection services)
2525
{
26-
services.AddScoped<GraphApiClientService>();
27-
services.AddTransient<IClaimsTransformation, GraphApiClaimsTransformation>();
26+
services.AddScoped<MsGraphService>();
27+
services.AddTransient<IClaimsTransformation, MsGraphClaimsTransformation>();
2828

2929
services.AddAntiforgery(options =>
3030
{

0 commit comments

Comments
 (0)