Skip to content

Commit

Permalink
Additional modernization changes for BFF
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Guijt committed Jun 20, 2024
1 parent 341275e commit ab4fd92
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ The behavior of each [management endpoint]({{< ref "/bff/session/management" >}}

```csharp
// management endpoints
services.AddTransient<ILoginService, DefaultLoginService>();
services.AddTransient<ISilentLoginService, DefaultSilentLoginService>();
services.AddTransient<ISilentLoginCallbackService, DefaultSilentLoginCallbackService>();
services.AddTransient<ILogoutService, DefaultLogoutService>();
services.AddTransient<IUserService, DefaultUserService>();
services.AddTransient<IBackchannelLogoutService, DefaultBackchannelLogoutService>();
services.AddTransient<IDiagnosticsService, DefaultDiagnosticsService>();
builder.Services.AddTransient<ILoginService, DefaultLoginService>();
builder.Services.AddTransient<ISilentLoginService, DefaultSilentLoginService>();
builder.Services.AddTransient<ISilentLoginCallbackService, DefaultSilentLoginCallbackService>();
builder.Services.AddTransient<ILogoutService, DefaultLogoutService>();
builder.Services.AddTransient<IUserService, DefaultUserService>();
builder.Services.AddTransient<IBackchannelLogoutService, DefaultBackchannelLogoutService>();
builder.Services.AddTransient<IDiagnosticsService, DefaultDiagnosticsService>();
```

You can add your own implementation by overriding the default after calling *AddBff()*.
Expand Down
10 changes: 4 additions & 6 deletions IdentityServer/v7/docs/content/bff/extensibility/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ public interface IUserSessionStore

Once you have an implementation, you can register it when you enable server-side sessions:

```
public void ConfigureServices(IServiceCollection services)
{
services.AddBff()
.AddServerSideSessions<YourStoreClassName>();
}
```csharp
builder.Services.AddBff()
.AddServerSideSessions<YourStoreClassName>();

```

## User Session Store Cleanup
Expand Down
4 changes: 2 additions & 2 deletions IdentityServer/v7/docs/content/bff/extensibility/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Both aspects can be customized.
The token management library uses a named HTTP client from the HTTP client factory for all token service communication. You can provide a customized HTTP client yourself using the well-known name after calling *AddBff*:

```cs
services.AddHttpClient(AccessTokenManagementDefaults.BackChannelHttpClientName, configureClient => { ... });
builder.Services.AddHttpClient(AccessTokenManagementDefaults.BackChannelHttpClientName, configureClient => { ... });
```

{{% notice note %}}
Expand Down Expand Up @@ -98,7 +98,7 @@ You can implement this interface yourself or extend the *DefaultAccessTokenRetri
Implementations of the *IAccessTokenRetriever* can be added to endpoints when they are mapped using the *WithAccessTokenRetriever* extension method:

```cs
endpoints.MapRemoteBffApiEndpoint("/api/impersonation", "https://api.example.com/endpoint/requiring/impersonation")
app.MapRemoteBffApiEndpoint("/api/impersonation", "https://api.example.com/endpoint/requiring/impersonation")
.RequireAccessToken(TokenType.User)
.WithAccessTokenRetriever<ImpersonationAccessTokenRetriever>();
```
Expand Down
4 changes: 2 additions & 2 deletions IdentityServer/v7/docs/content/bff/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ weight: 90

The *Duende.BFF.BffOptions* allows to configure several aspects of the BFF framework.

You set the options at startup time in your *ConfigureServices* method:
You set the options at startup time:

```cs
services.AddBff(options =>
builder.Services.AddBff(options =>
{
// configure options here..
})
Expand Down
6 changes: 3 additions & 3 deletions IdentityServer/v7/docs/content/bff/session/handlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Furthermore the BFF plumbing relies on the configuration of the ASP.NET Core def
OpenID Connect for *challenge* and *signout* - cookies for all the other operations:

```csharp
services.AddAuthentication(options =>
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = "cookie";
options.DefaultChallengeScheme = "oidc";
Expand All @@ -37,7 +37,7 @@ The exact settings depend on the OIDC provider and its configuration settings. W
* request a refresh token using the *offline_access* scope

```csharp
services.AddAuthentication().AddOpenIdConnect("oidc", options =>
builder.Services.AddAuthentication().AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://demo.duendesoftware.com";

Expand Down Expand Up @@ -79,7 +79,7 @@ Things to consider:
* use the highest available *SameSite* mode that is compatible with your application, e.g. *strict*, but at least *lax*

```csharp
services.AddAuthentication().AddCookie("cookie", options =>
builder.Services.AddAuthentication().AddCookie("cookie", options =>
{
// set session lifetime
options.ExpireTimeSpan = TimeSpan.FromHours(8);
Expand Down
26 changes: 7 additions & 19 deletions IdentityServer/v7/docs/content/bff/session/management/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,18 @@ In addition Duende.BFF adds an implementation of the OpenID Connect back-channel
You enable the endpoints by adding the relevant services into the DI container:

```csharp
public void ConfigureServices(IServiceCollection services)
// Add BFF services to DI - also add server-side session management
builder.Services.AddBff(options =>
{
// Add BFF services to DI - also add server-side session management
services.AddBff(options =>
{
// default value
options.ManagementBasePath = "/bff";
};

// rest omitted
}
// default value
options.ManagementBasePath = "/bff";
};
```

Endpoint routing is used to map the management endpoints:
The management endpoints need to be mapped:

```csharp
public void Configure(IApplicationBuilder app)
{
// rest omitted
app.UseEndpoints(endpoints =>
{
endpoints.MapBffManagementEndpoints();
});
app.MapBffManagementEndpoints();
```

*MapBffManagementEndpoints* adds all BFF management endpoints. You can also map each endpoint individually by calling the various *MapBffManagementXxxEndpoint* methods, for example *endpoints.MapBffManagementLoginEndpoint()*.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Duende.BFF includes all the plumbing to store your sessions server-side. The coo

## Configuring Server-side Sessions

Server-side session can be enabled in *Startup*:
Server-side sessions can be enabled in the application's startup:

```csharp
services.AddBff()
builder.Services.AddBff()
.AddServerSideSessions();
```

Expand All @@ -29,7 +29,7 @@ To use the EF session store, install the *Duende.BFF.EntityFramework* nuget pack
```csharp
var cn = _configuration.GetConnectionString("db");

services.AddBff()
builder.Services.AddBff()
.AddEntityFrameworkServerSideSessions(options=>
{
options.UseSqlServer(cn);
Expand All @@ -47,7 +47,7 @@ Abandoned sessions will remain in the store unless something removes the stale e
If you wish to have such sessions cleaned up periodically, then you can configure the *EnableSessionCleanup* and *SessionCleanupInterval* options:

```csharp
services.AddBff(options => {
builder.Services.AddBff(options => {
options.EnableSessionCleanup = true;
options.SessionCleanupInterval = TimeSpan.FromMinutes(5);
})
Expand All @@ -62,7 +62,7 @@ Just enable session cleanup:
```csharp
var cn = _configuration.GetConnectionString("db");

services.AddBff(options => {
builder.Services.AddBff(options => {
options.EnableSessionCleanup = true;
})
.AddEntityFrameworkServerSideSessions(options=>
Expand Down
4 changes: 2 additions & 2 deletions IdentityServer/v7/docs/content/bff/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ You can then use the token to set it on an *HttpClient* instance:
client.SetBearerToken(token);
```

We recommend to leverage the *HttpClientFactory* to fabricate HTTP clients that are already aware of the token management plumbing. For this you would register a named client in your *startup* e.g. like this:
We recommend to leverage the *HttpClientFactory* to fabricate HTTP clients that are already aware of the token management plumbing. For this you would register a named client in your application startup e.g. like this:

```cs
// registers HTTP client that uses the managed user access token
services.AddUserAccessTokenHttpClient("apiClient", configureClient: client =>
builder.Services.AddUserAccessTokenHttpClient("apiClient", configureClient: client =>
{
client.BaseAddress = new Uri("https://remoteServer/");
});
Expand Down

0 comments on commit ab4fd92

Please sign in to comment.