# LogtoClientBuilder Methods

- Package: [CommunityToolkit.Aspire.Logto.Client](/reference/api/csharp/communitytoolkit.aspire.logto.client.md)
- Type: [LogtoClientBuilder](/reference/api/csharp/communitytoolkit.aspire.logto.client/logtoclientbuilder.md)
- Kind: `Methods`
- Members: `3`

Provides methods to configure and add Logto client services to an application builder.

<a id="addlogtojwtbearer"></a>
<a id="addlogtojwtbearer-authenticationbuilder-string-string-string-string-action-jwtbeareroptions"></a>

## AddLogtoJwtBearer(AuthenticationBuilder, string, string, string, string?, Action<JwtBearerOptions>)

- Name: `AddLogtoJwtBearer(AuthenticationBuilder, string, string, string, string?, Action<JwtBearerOptions>)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Logto.Client/LogtoClientBuilder.cs)

Configures and adds the Logto JSON Web Token (JWT) Bearer authentication to the specified authentication builder.

```csharp
public static class LogtoClientBuilder
{
    public static AuthenticationBuilder AddLogtoJwtBearer(
        this AuthenticationBuilder builder,
        string serviceName,
        string appIdentification,
        string authenticationScheme = "Bearer",
        string? configurationSectionName = "Aspire:Logto:Client",
        Action<JwtBearerOptions>? configureOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The authentication builder used to configure authentication services.
- `serviceName` (`string`)
  The name of the Logto service instance to be used for authentication.
- `appIdentification` (`string`)
  A collection of application identifiers associated with the Logto service.
- `authenticationScheme` (`string`) `optional`
  The authentication scheme identifier for the Logto JWT Bearer authentication. Defaults to "Bearer".
- `configurationSectionName` (`string?`) `optional`
  The name of the configuration section that contains Logto client settings. Defaults to "Aspire:Logto:Client".
- `configureOptions` (`Action<JwtBearerOptions>`) `optional`
  A delegate to configure the options for JWT bearer authentication.

## Returns

`AuthenticationBuilder` -- An updated `Authentication.AuthenticationBuilder` instance with the configured Logto JWT Bearer authentication.

## Exceptions

- `ArgumentNullException` -- Thrown when the builder or serviceName is null.

<a id="addlogtojwtbearer-authenticationbuilder-string-ienumerable-string-string-string-action-jwtbeareroptions"></a>

## AddLogtoJwtBearer(AuthenticationBuilder, string, IEnumerable<string>, string, string?, Action<JwtBearerOptions>)

- Name: `AddLogtoJwtBearer(AuthenticationBuilder, string, IEnumerable<string>, string, string?, Action<JwtBearerOptions>)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Logto.Client/LogtoClientBuilder.cs)

Configures and adds the Logto JSON Web Token (JWT) Bearer authentication for the specified application.

```csharp
public static class LogtoClientBuilder
{
    public static AuthenticationBuilder AddLogtoJwtBearer(
        this AuthenticationBuilder builder,
        string serviceName,
        IEnumerable<string> appIdentification,
        string authenticationScheme = "Bearer",
        string? configurationSectionName = "Aspire:Logto:Client",
        Action<JwtBearerOptions>? configureOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The authentication builder used to configure the application's authentication services.
- `serviceName` (`string`)
  The name of the service associated with Logto configuration.
- `appIdentification` (`IEnumerable<string>`)
  A collection of application identifiers (audiences) used to validate the JWT's audience claim.
- `authenticationScheme` (`string`) `optional`
  The authentication scheme identifier for the Logto JWT Bearer authentication. Defaults to "Bearer".
- `configurationSectionName` (`string?`) `optional`
  The name of the configuration section that contains Logto client settings. Defaults to "Aspire:Logto:Client".
- `configureOptions` (`Action<JwtBearerOptions>`) `optional`
  A delegate to configure additional JwtBearerOptions as needed for specific authentication behavior.

## Returns

`AuthenticationBuilder` -- An updated `Authentication.AuthenticationBuilder` instance with the configured Logto JWT Bearer authentication.

## Exceptions

- `ArgumentNullException` -- Thrown when the builder is null.
- `InvalidOperationException` -- Thrown when serviceName or appIdentification is missing or invalid.

<a id="addlogtooidc"></a>
<a id="addlogtooidc-ihostapplicationbuilder-string-string-string-string-action-logtooptions-action-openidconnectoptions"></a>

## AddLogtoOIDC(IHostApplicationBuilder, string?, string?, string, string, Action<LogtoOptions>, Action<OpenIdConnectOptions>)

- Name: `AddLogtoOIDC(IHostApplicationBuilder, string?, string?, string, string, Action<LogtoOptions>, Action<OpenIdConnectOptions>)`
- Modifiers: `extension`
- Returns: `IServiceCollection`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Logto.Client/LogtoClientBuilder.cs#L54-L68)

Configures and adds the Logto OpenID Connect (OIDC) authentication for the specified application's service collection.

```csharp
public static class LogtoClientBuilder
{
    public static IServiceCollection AddLogtoOIDC(
        this IHostApplicationBuilder builder,
        string? connectionName = null,
        string? configurationSectionName = "Aspire:Logto:Client",
        string authenticationScheme = "Logto",
        string cookieScheme = "Logto.Cookie",
        Action<LogtoOptions>? logtoOptions = null,
        Action<OpenIdConnectOptions>? oidcOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The application builder used to configure the application's services and pipeline.
- `connectionName` (`string?`) `optional`
  The name of the connection configuration to be used. If null, a default connection is used.
- `configurationSectionName` (`string?`) `optional`
  The name of the configuration section that contains Logto client settings. Defaults to "Aspire:Logto:Client".
- `authenticationScheme` (`string`) `optional`
  The authentication scheme identifier for the Logto OIDC authentication. Defaults to "Logto".
- `cookieScheme` (`string`) `optional`
  The cookie scheme name to be used with the Logto OIDC authentication. Defaults to "Logto.Cookie".
- `logtoOptions` (`Action<LogtoOptions>`) `optional`
  A delegate to configure Logto-specific options such as endpoint, application ID, or secret.
- `oidcOptions` (`Action<OpenIdConnectOptions>`) `optional`
  A delegate to configure OpenID Connect options for fine-tuning authentication behavior.

## Returns

`IServiceCollection` -- An updated `DependencyInjection.IServiceCollection` instance with the configured Logto OIDC authentication.

## Exceptions

- `ArgumentNullException` -- Thrown when the builder is null.
