From ae565cccedb55b041fec369403e14a5d9a106fef Mon Sep 17 00:00:00 2001 From: Maarten Balliauw Date: Fri, 2 May 2025 14:49:32 +0200 Subject: [PATCH] Refactor code snippets in documentation for clarity Updated code examples across various docs to improve readability by adding consistent formatting and placeholder comments. These changes enhance the overall clarity and maintainability of the documentation. --- .../advanced/user-tokens.md | 17 +++++++++++++---- src/content/docs/bff/extensibility/tokens.md | 5 +++-- src/content/docs/bff/fundamentals/apis/local.md | 13 +++++++++---- .../docs/bff/fundamentals/session/handlers.md | 8 ++++++-- src/content/docs/identityserver/data/ef.md | 4 +++- .../docs/identityserver/fundamentals/hosting.md | 7 +++++-- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/content/docs/accesstokenmanagement/advanced/user-tokens.md b/src/content/docs/accesstokenmanagement/advanced/user-tokens.md index 0edca3124..53ba42201 100644 --- a/src/content/docs/accesstokenmanagement/advanced/user-tokens.md +++ b/src/content/docs/accesstokenmanagement/advanced/user-tokens.md @@ -57,14 +57,19 @@ The `UserTokenRequestParameters` class can be used for that: The request parameters can be passed via the manual API: ```csharp -var token = await _tokenManagementService.GetAccessTokenAsync(User, new UserAccessTokenRequestParameters { ... }); +var token = await _tokenManagementService + .GetAccessTokenAsync(User, new UserAccessTokenRequestParameters { + // ... + }); ``` ...the extension methods ```csharp var token = await HttpContext.GetUserAccessTokenAsync( - new UserTokenRequestParameters { ... }); + new UserTokenRequestParameters { + // ... + }); ``` ...or the HTTP client factory @@ -73,7 +78,9 @@ var token = await HttpContext.GetUserAccessTokenAsync( // Program.cs // registers HTTP client that uses the managed user access token builder.Services.AddUserAccessTokenHttpClient("invoices", - parameters: new UserTokenRequestParameters { ... }, + parameters: new UserTokenRequestParameters { + // ... + }, configureClient: client => { client.BaseAddress = new Uri("https://api.company.com/invoices/"); @@ -84,7 +91,9 @@ builder.Services.AddHttpClient(client => { client.BaseAddress = new Uri("https://api.company.com/invoices/"); }) - .AddUserAccessTokenHandler(new UserTokenRequestParameters { ... }); + .AddUserAccessTokenHandler(new UserTokenRequestParameters { + // ... + }); ``` ## Token Storage diff --git a/src/content/docs/bff/extensibility/tokens.md b/src/content/docs/bff/extensibility/tokens.md index 7c52e93d6..575e2401d 100644 --- a/src/content/docs/bff/extensibility/tokens.md +++ b/src/content/docs/bff/extensibility/tokens.md @@ -26,8 +26,9 @@ The token management library uses a named HTTP client from the HTTP client facto ```cs builder.Services.AddHttpClient( AccessTokenManagementDefaults.BackChannelHttpClientName, - configureClient => { ... } - ); + configureClient => { + // ... + }); ``` :::note diff --git a/src/content/docs/bff/fundamentals/apis/local.md b/src/content/docs/bff/fundamentals/apis/local.md index cd1f596a1..7a741843f 100644 --- a/src/content/docs/bff/fundamentals/apis/local.md +++ b/src/content/docs/bff/fundamentals/apis/local.md @@ -106,12 +106,13 @@ Endpoints that require the pre- and post-processing described above must be deco For Minimal API endpoints, you can apply BFF pre- and post-processing when they are mapped. ```csharp -app.MapPost("/foo", context => { ... }) +app.MapPost("/foo", context => { + // ... + }) .RequireAuthorization() // no anonymous access .AsBffApiEndpoint(); // BFF pre/post processing ``` - For MVC controllers, you can similarly apply BFF pre- and post-processing to controller actions when they are mapped. ```csharp app.MapControllers() @@ -124,7 +125,9 @@ Alternatively, you can apply the *[BffApi]* attribute directly to the controller [Route("myApi")] [BffApi] public class MyApiController : ControllerBase -{ ... } +{ + // ... +} ``` #### Disabling Anti-forgery Protection @@ -144,7 +147,9 @@ app.MapControllers() .AsBffApiEndpoint(requireAntiforgeryCheck: false); // simple endpoint -app.MapPost("/foo", context => { /* ... */ }) +app.MapPost("/foo", context => { + // ... + }) .RequireAuthorization() // WARNING: Disabling antiforgery protection may make // your APIs vulnerable to CSRF attacks diff --git a/src/content/docs/bff/fundamentals/session/handlers.md b/src/content/docs/bff/fundamentals/session/handlers.md index 466647d03..b69e46820 100644 --- a/src/content/docs/bff/fundamentals/session/handlers.md +++ b/src/content/docs/bff/fundamentals/session/handlers.md @@ -28,8 +28,12 @@ builder.Services.AddAuthentication(options => options.DefaultChallengeScheme = "oidc"; options.DefaultSignOutScheme = "oidc"; }) - .AddCookie("cookie", options => { ... }) - .AddOpenIdConnect("oidc", options => { ... }); + .AddCookie("cookie", options => { + // ... + }) + .AddOpenIdConnect("oidc", options => { + // ... + }); ``` ## The OpenID Connect Authentication Handler diff --git a/src/content/docs/identityserver/data/ef.md b/src/content/docs/identityserver/data/ef.md index 046beb9d8..cefd30973 100644 --- a/src/content/docs/identityserver/data/ef.md +++ b/src/content/docs/identityserver/data/ef.md @@ -78,7 +78,9 @@ To enable caching for the EF configuration store implementation, use the `AddCon ```csharp // Program.cs builder.Services.AddIdentityServer() - .AddConfigurationStore(options => { ... }) + .AddConfigurationStore(options => { + // ... + }) // this is something you will want in production to reduce load on and requests to the DB .AddConfigurationStoreCache(); ``` diff --git a/src/content/docs/identityserver/fundamentals/hosting.md b/src/content/docs/identityserver/fundamentals/hosting.md index d4da78aa2..e4d6ce7b2 100644 --- a/src/content/docs/identityserver/fundamentals/hosting.md +++ b/src/content/docs/identityserver/fundamentals/hosting.md @@ -23,11 +23,14 @@ You add the necessary services to the ASP.NET Core service provider by calling ` ```cs //Program.cs -var idsvrBuilder = builder.Services.AddIdentityServer(options => { ... }); +var idsvrBuilder = builder.Services.AddIdentityServer(options => +{ + // ... +}); ``` Many of the fundamental configuration settings can be set on the options. See the -`[IdentityServerOptions](/identityserver/reference/options)` reference for more details. +[`IdentityServerOptions`](/identityserver/reference/options) reference for more details. The builder object has a number of extension methods to add additional services to the ASP.NET Core service provider. You can see the full list in the [reference](/identityserver/reference/di) section, but very commonly you start by