Skip to content

Commit 995f40c

Browse files
RolandGuijtRoland Guijt
andauthored
Add BlazorWasm sample for BFF v4 (#290)
Co-authored-by: Roland Guijt <roland.guijt@duendesoftware.com>
1 parent e5aa460 commit 995f40c

69 files changed

Lines changed: 60347 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BFF/v4/BlazorWasm/BFF/BFF.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\BlazorWasm\BlazorWasm.csproj" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Duende.BFF.Yarp" Version="4.0.2" />
15+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.2" />
16+
</ItemGroup>
17+
18+
</Project>

BFF/v4/BlazorWasm/BFF/Program.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Duende.Bff;
2+
using Duende.Bff.Yarp;
3+
using Microsoft.AspNetCore.Authentication;
4+
5+
var builder = WebApplication.CreateBuilder(args);
6+
7+
builder.Services.AddAuthorization();
8+
builder.Services.AddCascadingAuthenticationState();
9+
builder.Services
10+
.AddBff()
11+
.AddRemoteApis()
12+
.ConfigureOpenIdConnect(options =>
13+
{
14+
options.Authority = "https://demo.duendesoftware.com";
15+
16+
options.ClientId = "interactive.confidential";
17+
options.ClientSecret = "secret";
18+
options.ResponseType = "code";
19+
options.ResponseMode = "query";
20+
21+
options.Scope.Clear();
22+
options.Scope.Add("openid");
23+
options.Scope.Add("profile");
24+
options.Scope.Add("api");
25+
options.Scope.Add("offline_access");
26+
27+
options.MapInboundClaims = false;
28+
options.ClaimActions.MapAll();
29+
options.GetClaimsFromUserInfoEndpoint = true;
30+
options.SaveTokens = true;
31+
32+
options.TokenValidationParameters.NameClaimType = "name";
33+
options.TokenValidationParameters.RoleClaimType = "role";
34+
})
35+
.ConfigureCookies(options =>
36+
{
37+
options.Cookie.Name = "__Host-blazor";
38+
options.Cookie.SameSite = SameSiteMode.Strict;
39+
});
40+
41+
var app = builder.Build();
42+
43+
app.UseAuthentication();
44+
app.UseBff();
45+
app.UseAuthorization();
46+
47+
app.MapBffManagementEndpoints();
48+
49+
app.MapStaticAssets();
50+
51+
app.MapGet("/api/data", async () =>
52+
{
53+
var json = await File.ReadAllTextAsync("weather.json");
54+
return Results.Content(json, "application/json");
55+
}).RequireAuthorization().AsBffApiEndpoint();
56+
57+
app.MapRemoteBffApiEndpoint("/remoteapi", new Uri("https://demo.duendesoftware.com/api"))
58+
.WithAccessToken();
59+
60+
app.MapFallbackToFile("index.html");
61+
62+
app.Run();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "http://localhost:5267",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
12+
},
13+
"https": {
14+
"commandName": "Project",
15+
"dotnetRunMessages": true,
16+
"launchBrowser": true,
17+
"applicationUrl": "https://localhost:7256;http://localhost:5267",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
}
22+
}
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}

BFF/v4/BlazorWasm/BFF/weather.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"date": "2022-01-06",
4+
"temperatureC": 1,
5+
"summary": "Freezing"
6+
},
7+
{
8+
"date": "2022-01-07",
9+
"temperatureC": 14,
10+
"summary": "Bracing"
11+
},
12+
{
13+
"date": "2022-01-08",
14+
"temperatureC": -13,
15+
"summary": "Freezing"
16+
},
17+
{
18+
"date": "2022-01-09",
19+
"temperatureC": -16,
20+
"summary": "Balmy"
21+
},
22+
{
23+
"date": "2022-01-10",
24+
"temperatureC": -2,
25+
"summary": "Chilly"
26+
}
27+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Solution>
2+
<Project Path="BFF/BFF.csproj" />
3+
<Project Path="BlazorWasm/BlazorWasm.csproj" />
4+
</Solution>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<CascadingAuthenticationState>
2+
<Router AppAssembly="@typeof(App).Assembly" NotFoundPage="typeof(Pages.NotFound)">
3+
<Found Context="routeData">
4+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
5+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
6+
</Found>
7+
</Router>
8+
</CascadingAuthenticationState>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Duende.BFF.Blazor.Client" Version="4.0.2" />
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="10.0.2" />
14+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0" PrivateAssets="all" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<Folder Include="wwwroot\sample-data\" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@inherits LayoutComponentBase
2+
<div class="page">
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<main>
8+
<div class="top-row px-4">
9+
<AuthorizeView>
10+
<Authorized>
11+
<strong>Hello, @context.User.Identity.Name!</strong>
12+
<a href="@context.User.FindFirst("bff:logout_url")?.Value">Log out
13+
</a>
14+
</Authorized>
15+
<NotAuthorized>
16+
<a href="bff/login">Log in</a>
17+
</NotAuthorized>
18+
</AuthorizeView>
19+
</div>
20+
<article class="content px-4">
21+
@Body
22+
</article>
23+
</main>
24+
</div>

0 commit comments

Comments
 (0)