# AspireKeycloakExtensions Methods

- Package: [Aspire.Keycloak.Authentication](/reference/api/csharp/aspire.keycloak.authentication.md)
- Type: [AspireKeycloakExtensions](/reference/api/csharp/aspire.keycloak.authentication/aspirekeycloakextensions.md)
- Kind: `Methods`
- Members: `8`

Provides extension methods for registering Keycloak-related services in an `Authentication.AuthenticationBuilder`.

## AddKeycloakJwtBearer(AuthenticationBuilder, string, string)

- Name: `AddKeycloakJwtBearer(AuthenticationBuilder, string, string)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.Keycloak.Authentication/AspireKeycloakExtensions.cs#L30)

Adds Keycloak JWT Bearer authentication to the application.

```csharp
public static class AspireKeycloakExtensions
{
    public static AuthenticationBuilder AddKeycloakJwtBearer(
        this AuthenticationBuilder builder,
        string serviceName,
        string realm)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The `Authentication.AuthenticationBuilder` to add services to.
- `serviceName` (`string`)
  The name of the service used to resolve the Keycloak server URL.
- `realm` (`string`)
  The realm of the Keycloak server to connect to.

## Remarks

The `serviceName` is used to resolve the Keycloak server URL and is combined with the realm to form the authority URL. For example, if `serviceName` is "keycloak" and `realm` is "myrealm", the authority URL will be "https+http://keycloak/realms/myrealm".

## AddKeycloakJwtBearer(AuthenticationBuilder, string, string, string)

- Name: `AddKeycloakJwtBearer(AuthenticationBuilder, string, string, string)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.Keycloak.Authentication/AspireKeycloakExtensions.cs#L44)

Adds Keycloak JWT Bearer authentication to the application.

```csharp
public static class AspireKeycloakExtensions
{
    public static AuthenticationBuilder AddKeycloakJwtBearer(
        this AuthenticationBuilder builder,
        string serviceName,
        string realm,
        string authenticationScheme)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The `Authentication.AuthenticationBuilder` to add services to.
- `serviceName` (`string`)
  The name of the service used to resolve the Keycloak server URL.
- `realm` (`string`)
  The realm of the Keycloak server to connect to.
- `authenticationScheme` (`string`)
  The authentication scheme name. Default is "Bearer".

## Remarks

The `serviceName` is used to resolve the Keycloak server URL and is combined with the realm to form the authority URL. For example, if `serviceName` is "keycloak" and `realm` is "myrealm", the authority URL will be "https+http://keycloak/realms/myrealm".

## AddKeycloakJwtBearer(AuthenticationBuilder, string, string, Action<JwtBearerOptions>)

- Name: `AddKeycloakJwtBearer(AuthenticationBuilder, string, string, Action<JwtBearerOptions>)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.Keycloak.Authentication/AspireKeycloakExtensions.cs#L58)

Adds Keycloak JWT Bearer authentication to the application.

```csharp
public static class AspireKeycloakExtensions
{
    public static AuthenticationBuilder AddKeycloakJwtBearer(
        this AuthenticationBuilder builder,
        string serviceName,
        string realm,
        Action<JwtBearerOptions>? configureOptions)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The `Authentication.AuthenticationBuilder` to add services to.
- `serviceName` (`string`)
  The name of the service used to resolve the Keycloak server URL.
- `realm` (`string`)
  The realm of the Keycloak server to connect to.
- `configureOptions` (`Action<JwtBearerOptions>`)
  An optional action to configure the `JwtBearer.JwtBearerOptions`.

## Remarks

The `serviceName` is used to resolve the Keycloak server URL and is combined with the realm to form the authority URL. For example, if `serviceName` is "keycloak" and `realm` is "myrealm", the authority URL will be "https+http://keycloak/realms/myrealm".

## AddKeycloakJwtBearer(AuthenticationBuilder, string, string, string, Action<JwtBearerOptions>)

- Name: `AddKeycloakJwtBearer(AuthenticationBuilder, string, string, string, Action<JwtBearerOptions>)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.Keycloak.Authentication/AspireKeycloakExtensions.cs#L79-L98)

Adds Keycloak JWT Bearer authentication to the application.

```csharp
public static class AspireKeycloakExtensions
{
    public static AuthenticationBuilder AddKeycloakJwtBearer(
        this AuthenticationBuilder builder,
        string serviceName,
        string realm,
        string authenticationScheme,
        Action<JwtBearerOptions>? configureOptions)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The `Authentication.AuthenticationBuilder` to add services to.
- `serviceName` (`string`)
  The name of the service used to resolve the Keycloak server URL.
- `realm` (`string`)
  The realm of the Keycloak server to connect to.
- `authenticationScheme` (`string`)
  The authentication scheme name. Default is "Bearer".
- `configureOptions` (`Action<JwtBearerOptions>`)
  An action to configure the `JwtBearer.JwtBearerOptions`.

## Remarks

The `serviceName` is used to resolve the Keycloak server URL and is combined with the realm to form the authority URL. For example, if `serviceName` is "keycloak" and `realm` is "myrealm", the authority URL will be "https+http://keycloak/realms/myrealm".

## AddKeycloakOpenIdConnect(AuthenticationBuilder, string, string)

- Name: `AddKeycloakOpenIdConnect(AuthenticationBuilder, string, string)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.Keycloak.Authentication/AspireKeycloakExtensions.cs#L112)

Adds Keycloak OpenID Connect authentication to the application.

```csharp
public static class AspireKeycloakExtensions
{
    public static AuthenticationBuilder AddKeycloakOpenIdConnect(
        this AuthenticationBuilder builder,
        string serviceName,
        string realm)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The `Authentication.AuthenticationBuilder` to add services to.
- `serviceName` (`string`)
  The name of the service used to resolve the Keycloak server URL.
- `realm` (`string`)
  The realm of the Keycloak server to connect to.

## Remarks

The `serviceName` is used to resolve the Keycloak server URL and is combined with the realm to form the authority URL. For example, if `serviceName` is "keycloak" and `realm` is "myrealm", the authority URL will be "https+http://keycloak/realms/myrealm".

## AddKeycloakOpenIdConnect(AuthenticationBuilder, string, string, string)

- Name: `AddKeycloakOpenIdConnect(AuthenticationBuilder, string, string, string)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.Keycloak.Authentication/AspireKeycloakExtensions.cs#L126)

Adds Keycloak OpenID Connect authentication to the application.

```csharp
public static class AspireKeycloakExtensions
{
    public static AuthenticationBuilder AddKeycloakOpenIdConnect(
        this AuthenticationBuilder builder,
        string serviceName,
        string realm,
        string authenticationScheme)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The `Authentication.AuthenticationBuilder` to add services to.
- `serviceName` (`string`)
  The name of the service used to resolve the Keycloak server URL.
- `realm` (`string`)
  The realm of the Keycloak server to connect to.
- `authenticationScheme` (`string`)
  The OpenID Connect authentication scheme name. Default is "OpenIdConnect".

## Remarks

The `serviceName` is used to resolve the Keycloak server URL and is combined with the realm to form the authority URL. For example, if `serviceName` is "keycloak" and `realm` is "myrealm", the authority URL will be "https+http://keycloak/realms/myrealm".

## AddKeycloakOpenIdConnect(AuthenticationBuilder, string, string, Action<OpenIdConnectOptions>)

- Name: `AddKeycloakOpenIdConnect(AuthenticationBuilder, string, string, Action<OpenIdConnectOptions>)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.Keycloak.Authentication/AspireKeycloakExtensions.cs#L140)

Adds Keycloak OpenID Connect authentication to the application.

```csharp
public static class AspireKeycloakExtensions
{
    public static AuthenticationBuilder AddKeycloakOpenIdConnect(
        this AuthenticationBuilder builder,
        string serviceName,
        string realm,
        Action<OpenIdConnectOptions>? configureOptions)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The `Authentication.AuthenticationBuilder` to add services to.
- `serviceName` (`string`)
  The name of the service used to resolve the Keycloak server URL.
- `realm` (`string`)
  The realm of the Keycloak server to connect to.
- `configureOptions` (`Action<OpenIdConnectOptions>`)
  An action to configure the `OpenIdConnect.OpenIdConnectOptions`.

## Remarks

The `serviceName` is used to resolve the Keycloak server URL and is combined with the realm to form the authority URL. For example, if `serviceName` is "keycloak" and `realm` is "myrealm", the authority URL will be "https+http://keycloak/realms/myrealm".

## AddKeycloakOpenIdConnect(AuthenticationBuilder, string, string, string, Action<OpenIdConnectOptions>)

- Name: `AddKeycloakOpenIdConnect(AuthenticationBuilder, string, string, string, Action<OpenIdConnectOptions>)`
- Modifiers: `extension`
- Returns: `AuthenticationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Components/Aspire.Keycloak.Authentication/AspireKeycloakExtensions.cs#L161-L180)

Adds Keycloak OpenID Connect authentication to the application.

```csharp
public static class AspireKeycloakExtensions
{
    public static AuthenticationBuilder AddKeycloakOpenIdConnect(
        this AuthenticationBuilder builder,
        string serviceName,
        string realm,
        string authenticationScheme,
        Action<OpenIdConnectOptions>? configureOptions)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AuthenticationBuilder`)
  The `Authentication.AuthenticationBuilder` to add services to.
- `serviceName` (`string`)
  The name of the service used to resolve the Keycloak server URL.
- `realm` (`string`)
  The realm of the Keycloak server to connect to.
- `authenticationScheme` (`string`)
  The OpenID Connect authentication scheme name. Default is "OpenIdConnect".
- `configureOptions` (`Action<OpenIdConnectOptions>`)
  An action to configure the `OpenIdConnect.OpenIdConnectOptions`.

## Remarks

The `serviceName` is used to resolve the Keycloak server URL and is combined with the realm to form the authority URL. For example, if `serviceName` is "keycloak" and `realm` is "myrealm", the authority URL will be "https+http://keycloak/realms/myrealm".
