# NgrokExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.Ngrok](/reference/api/csharp/communitytoolkit.aspire.hosting.ngrok.md)
- Type: [NgrokExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.ngrok/ngrokextensions.md)
- Kind: `Methods`
- Members: `4`

Extension methods for adding ngrok to the application model.

## AddNgrok(IDistributedApplicationBuilder, string, string?, int?, string?, int?)

- Name: `AddNgrok(IDistributedApplicationBuilder, string, string?, int?, string?, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<NgrokResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ngrok/NgrokExtensions.cs#L37-L79)

Configures a container resource for grok which is pre-configured to connect to the resource that this method is used on.

```csharp
public static class NgrokExtensions
{
    public static IResourceBuilder<NgrokResource> AddNgrok(
        this IDistributedApplicationBuilder builder,
        string name,
        string? configurationFolder = null,
        int? endpointPort = null,
        string? endpointName = null,
        int? configurationVersion = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder` to add the resource to.
- `name` (`string`)
  The name of the resource.
- `configurationFolder` (`string?`) `optional`
  The folder where temporary ngrok configuration files will be stored; defaults to .ngrok
- `endpointPort` (`int?`) `optional`
  The port of the endpoint for this resource, defaults to a randomly assigned port.
- `endpointName` (`string?`) `optional`
  The name of the endpoint for this resource, defaults to http.
- `configurationVersion` (`int?`) `optional`
  The output version of the ngrok configuration file.

## Returns

`IResourceBuilder<NgrokResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithAuthToken(IResourceBuilder<NgrokResource>, string)

- Name: `WithAuthToken(IResourceBuilder<NgrokResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<NgrokResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ngrok/NgrokExtensions.cs)

Adds a ngrok auth token to a ngrok resource.

```csharp
public static class NgrokExtensions
{
    public static IResourceBuilder<NgrokResource> WithAuthToken(
        this IResourceBuilder<NgrokResource> builder,
        string ngrokAuthToken)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<NgrokResource>`)
  The ngrok resource builder.
- `ngrokAuthToken` (`string`)
  The ngrok auth token.

## Returns

`IResourceBuilder<NgrokResource>` -- The same reference to ngrok resource builder.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithAuthToken(IResourceBuilder<NgrokResource>, IResourceBuilder<ParameterResource>)

- Name: `WithAuthToken(IResourceBuilder<NgrokResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<NgrokResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ngrok/NgrokExtensions.cs)

Adds a ngrok auth token to a ngrok resource.

```csharp
public static class NgrokExtensions
{
    public static IResourceBuilder<NgrokResource> WithAuthToken(
        this IResourceBuilder<NgrokResource> builder,
        IResourceBuilder<ParameterResource> ngrokAuthToken)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<NgrokResource>`)
  The ngrok resource builder.
- `ngrokAuthToken` (`IResourceBuilder<ParameterResource>`)
  The ngrok auth token as a parameter resource.

## Returns

`IResourceBuilder<NgrokResource>` -- The same reference to ngrok resource builder.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithTunnelEndpoint(IResourceBuilder<NgrokResource>, IResourceBuilder<TResource>, string, string?, IDictionary<string, string>)

- Name: `WithTunnelEndpoint(IResourceBuilder<NgrokResource>, IResourceBuilder<TResource>, string, string?, IDictionary<string, string>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<NgrokResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ngrok/NgrokExtensions.cs#L134)

Configures a resource with endpoints as a ngrok tunnel endpoint.

```csharp
public static class NgrokExtensions
{
    public static IResourceBuilder<NgrokResource> WithTunnelEndpoint<TResource>(
        this IResourceBuilder<NgrokResource> builder,
        IResourceBuilder<TResource> resource,
        string endpointName,
        string? ngrokUrl = null,
        IDictionary<string, string>? labels = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<NgrokResource>`)
  The ngrok resource builder.
- `resource` (`IResourceBuilder<TResource>`)
  The resource whose endpoint should be exposed through ngrok.
- `endpointName` (`string`)
  The endpoint name to expose.
- `ngrokUrl` (`string?`) `optional`
  The ngrok URL to use, or `null` to allow ngrok to choose one.
- `labels` (`IDictionary<string, string>`) `optional`
  Optional endpoint labels.

## Returns

`IResourceBuilder<NgrokResource>` -- The same reference to ngrok resource builder.

## Remarks

This overload is not available in polyglot app hosts. Use the overload that accepts `Generic.IReadOnlyDictionary`2` labels instead.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.
