-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from DuendeSoftware/joe/react-net8
Recreate BFF/React sample using new templates
- Loading branch information
Showing
69 changed files
with
4,899 additions
and
42,352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"version": "0.2.0", | ||
"compounds": [ | ||
{ | ||
"name": "All", | ||
"configurations": ["API", "BFF"], | ||
"presentation": { | ||
"hidden": false, | ||
"group": "compunds", | ||
} | ||
}, | ||
], | ||
"configurations": [ | ||
{ | ||
"name": "API", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-api", | ||
"program": "${workspaceFolder}/React.Api/bin/Debug/net8.0/React.Api.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/React.Api", | ||
"env": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"console": "externalTerminal", | ||
}, | ||
{ | ||
"name": "BFF", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-bff", | ||
"program": "${workspaceFolder}/React.Bff/bin/Debug/net8.0/React.Bff.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/React.Bff", | ||
"env": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"console": "externalTerminal", | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"type": "process", | ||
"command": "dotnet", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/React.sln", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "build-api", | ||
"type": "process", | ||
"command": "dotnet", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/React.Api/React.Api.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "build-bff", | ||
"type": "process", | ||
"command": "dotnet", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/React.Bff/React.Bff.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using React.Api; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddAuthentication("token") | ||
.AddJwtBearer("token", options => | ||
{ | ||
options.Authority = "https://demo.duendesoftware.com"; | ||
options.Audience = "api"; | ||
|
||
options.MapInboundClaims = false; | ||
}); | ||
|
||
builder.Services.AddAuthorization(options => | ||
{ | ||
options.AddPolicy("ApiCaller", policy => | ||
{ | ||
policy.RequireClaim("scope", "api"); | ||
}); | ||
|
||
options.AddPolicy("InteractiveUser", policy => | ||
{ | ||
policy.RequireClaim("sub"); | ||
}); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.MapGroup("/todos") | ||
.ToDoGroup() | ||
.RequireAuthorization("ApiCaller", "InteractiveUser"); | ||
|
||
|
||
app.Run(); | ||
|
14 changes: 14 additions & 0 deletions
14
IdentityServer/v7/BFF/React/React.Api/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": false, | ||
"applicationUrl": "https://localhost:7001", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
76 changes: 76 additions & 0 deletions
76
IdentityServer/v7/BFF/React/React.Api/ToDoEndpointGroup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Microsoft.AspNetCore.Http.Extensions; | ||
using System.Security.Claims; | ||
|
||
namespace React.Api; | ||
|
||
public static class TodoEndpointGroup | ||
{ | ||
private static readonly List<ToDo> data = new List<ToDo>() | ||
{ | ||
new ToDo { Id = ToDo.NewId(), Date = DateTimeOffset.UtcNow, Name = "Demo ToDo API", User = "2 (Bob Smith)" }, | ||
new ToDo { Id = ToDo.NewId(), Date = DateTimeOffset.UtcNow.AddHours(1), Name = "Stop Demo", User = "2 (Bob Smith)" }, | ||
new ToDo { Id = ToDo.NewId(), Date = DateTimeOffset.UtcNow.AddHours(4), Name = "Have Dinner", User = "1 (Alice Smith)" }, | ||
}; | ||
|
||
public static RouteGroupBuilder ToDoGroup(this RouteGroupBuilder group) | ||
{ | ||
// GET | ||
group.MapGet("/", () => data); | ||
group.MapGet("/{id}", (int id) => | ||
{ | ||
var item = data.FirstOrDefault(x => x.Id == id); | ||
}); | ||
|
||
// POST | ||
group.MapPost("/", (ToDo model, ClaimsPrincipal user, HttpContext context) => | ||
{ | ||
model.Id = ToDo.NewId(); | ||
model.User = $"{user.FindFirst("sub")?.Value} ({user.FindFirst("name")?.Value})"; | ||
|
||
data.Add(model); | ||
|
||
var url = new Uri($"{context.Request.GetEncodedUrl()}/{model.Id}"); | ||
|
||
return Results.Created(url, model); | ||
}); | ||
|
||
// PUT | ||
group.MapPut("/{id}", (int id, ToDo model, ClaimsPrincipal User) => | ||
{ | ||
var item = data.FirstOrDefault(x => x.Id == id); | ||
if (item == null) return Results.NotFound(); | ||
|
||
item.Date = model.Date; | ||
item.Name = model.Name; | ||
|
||
return Results.NoContent(); | ||
}); | ||
|
||
// DELETE | ||
group.MapDelete("/{id}", (int id) => | ||
{ | ||
var item = data.FirstOrDefault(x => x.Id == id); | ||
if (item == null) return Results.NotFound(); | ||
|
||
data.Remove(item); | ||
|
||
return Results.NoContent(); | ||
}); | ||
|
||
return group; | ||
} | ||
} | ||
|
||
public class ToDo | ||
{ | ||
static int _nextId = 1; | ||
public static int NewId() | ||
{ | ||
return _nextId++; | ||
} | ||
|
||
public int Id { get; set; } | ||
public DateTimeOffset Date { get; set; } | ||
public string? Name { get; set; } | ||
public string? User { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
IdentityServer/v7/BFF/React/React.Api/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
...ontendHost/Properties/launchSettings.json → .../React.Bff/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
{ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"FrontendHost": { | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:7240;http://localhost:5267", | ||
"launchUrl": "weatherforecast", | ||
"applicationUrl": "https://localhost:6001", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
<SpaRoot>..\react.client</SpaRoot> | ||
<SpaProxyLaunchCommand>npm run dev</SpaProxyLaunchCommand> | ||
<SpaProxyServerUrl>https://localhost:5173</SpaProxyServerUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\react.client\react.client.esproj"> | ||
<ReferenceOutputAssembly>false</ReferenceOutputAssembly> | ||
</ProjectReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.SpaProxy"> | ||
<Version>8.*-*</Version> | ||
</PackageReference> | ||
<PackageReference Include="Duende.BFF" Version="2.2.0" /> | ||
<PackageReference Include="Duende.BFF.Yarp" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.