Skip to content

Commit 5df4b84

Browse files
authored
Merge pull request #19 from damienbod/feature/cache-graph-claims
cache graph claims
2 parents 57162a5 + bf8107b commit 5df4b84

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
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-03-04** 1.0.10
6+
- Cache claims after authentication
7+
58
**2022-02-11** 1.0.9
69
- Update namespaces
710
- Update nuget packages

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.9.nupkg
94+
dotnet new -i Blazor.BFF.AzureB2C.Template.1.0.10.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.9</version>
5+
<version>1.0.10</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>Update namespaces, update nuget packages</releaseNotes>
18+
<releaseNotes>Cache claims after authentication</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
@@ -6,10 +6,10 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
10-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.2" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.2" PrivateAssets="all" />
1111
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
12-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.1" />
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.2" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

content/BlazorBffAzureB2C/Server/BlazorBffAzureB2C.Server.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.1" />
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.2" />
99
</ItemGroup>
1010

1111
<ItemGroup>
@@ -14,11 +14,11 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.1" NoWarn="NU1605" />
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" />
21-
<PackageReference Include="IdentityModel.AspNetCore" Version="4.1.2" />
17+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.2" NoWarn="NU1605" />
18+
<PackageReference Include="Microsoft.Graph" Version="4.19.0" />
19+
<PackageReference Include="Microsoft.Identity.Web" Version="1.23.0" />
20+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.23.0" />
21+
<PackageReference Include="IdentityModel.AspNetCore" Version="4.1.3" />
2222
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.16.1" />
2323
</ItemGroup>
2424

content/BlazorBffAzureB2C/Server/MsGraphClaimsTransformation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using BlazorBffAzureB2C.Server.Services;
2-
using Microsoft.AspNetCore.Authentication;
32
using System.Linq;
43
using System.Security.Claims;
54
using System.Threading.Tasks;
65

76
namespace BlazorBffAzureB2C.Server;
87

9-
public class MsGraphClaimsTransformation : IClaimsTransformation
8+
public class MsGraphClaimsTransformation
109
{
1110
private readonly MsGraphService _msGraphService;
1211

content/BlazorBffAzureB2C/Server/Startup.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BlazorBffAzureB2C.Server.Services;
22
using Microsoft.AspNetCore.Authentication;
3+
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
34
using Microsoft.AspNetCore.Builder;
45
using Microsoft.AspNetCore.Hosting;
56
using Microsoft.AspNetCore.Http;
@@ -9,6 +10,7 @@
910
using Microsoft.Extensions.Hosting;
1011
using Microsoft.Identity.Web;
1112
using Microsoft.Identity.Web.UI;
13+
using System;
1214

1315
namespace BlazorBffAzureB2C.Server;
1416

@@ -20,11 +22,12 @@ public Startup(IConfiguration configuration)
2022
}
2123

2224
public IConfiguration Configuration { get; }
25+
protected IServiceProvider ApplicationServices { get; set; }
2326

2427
public void ConfigureServices(IServiceCollection services)
2528
{
2629
services.AddScoped<MsGraphService>();
27-
services.AddTransient<IClaimsTransformation, MsGraphClaimsTransformation>();
30+
services.AddScoped<MsGraphClaimsTransformation>();
2831

2932
services.AddAntiforgery(options =>
3033
{
@@ -44,6 +47,17 @@ public void ConfigureServices(IServiceCollection services)
4447
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
4548
.AddInMemoryTokenCaches();
4649

50+
services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
51+
{
52+
options.Events.OnTokenValidated = async context =>
53+
{
54+
using var scope = ApplicationServices.CreateScope();
55+
context.Principal = await scope.ServiceProvider
56+
.GetRequiredService<MsGraphClaimsTransformation>()
57+
.TransformAsync(context.Principal);
58+
};
59+
});
60+
4761
services.AddControllersWithViews(options =>
4862
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()));
4963

@@ -58,6 +72,8 @@ public void ConfigureServices(IServiceCollection services)
5872

5973
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
6074
{
75+
ApplicationServices = app.ApplicationServices;
76+
6177
if (env.IsDevelopment())
6278
{
6379
app.UseDeveloperExceptionPage();

0 commit comments

Comments
 (0)