|
| 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(); |
0 commit comments