> ## Documentation Index
> Fetch the complete documentation index at: https://ngrok.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Twitch OAuth

> Configure ngrok to authenticate users with Twitch OAuth. Register an application in the Twitch developer console.

This guide explains how to register a Twitch application and configure ngrok to use Twitch OAuth for user authentication.
The steps follow Twitch's [OAuth 2.0 documentation](https://dev.twitch.tv/docs/authentication/).

## What you'll need

* A [Twitch](https://www.twitch.tv/) account with two-factor authentication (2FA) enabled (required to register an application).
* Your ngrok authtoken and an endpoint with the OAuth action in its Traffic Policy.

## Create credentials for ngrok

Follow [Twitch's documentation for registering an app](https://dev.twitch.tv/docs/authentication/register-app/) in the [Twitch developer console](https://dev.twitch.tv/console), then set the following:

* **OAuth Redirect URLs**: `https://idp.ngrok.com/oauth2/callback`
* **Category**: select a category, for example **Website Integration**.

After registering, generate a client secret and note the **Client ID** and **Client Secret** for use in your Traffic Policy below.

> [!NOTE]
>
> **Required:** You must enable two-factor authentication (2FA) on your Twitch account before you can register an application.

## Update your ngrok endpoint Traffic Policy

1. Access the [ngrok dashboard Endpoints page](https://dashboard.ngrok.com/endpoints?sortBy=createdAt\&orderBy=desc) and locate an existing endpoint you'd like to add this to or create a new one.
2. In your Traffic Policy, add the following configuration:

> [!NOTE]
>
> You may add [any scopes](https://developers.facebook.com/docs/apps/review/login-permissions) that are required by your application with the following caveats.
>
> * Scopes which require a Facebook [app review](https://developers.facebook.com/docs/apps/review/#app-review) are unsupported.
> * ngrok will enforce that users [accept all permissions](https://developers.facebook.com/docs/facebook-login/handling-declined-permissions#reprompt) before completing authorization.

```yaml policy.yml theme={null}
on_http_request:
  - actions:
      - type: oauth
        config:
          provider: twitch
          client_id: '{your app''s oauth client id}'
          client_secret: '{your app''s oauth client secret}'
          scopes:
            - user:read:email
            - openid
```

```json policy.json theme={null}
{
  "on_http_request": [
    {
      "actions": [
        {
          "type": "oauth",
          "config": {
            "provider": "twitch",
            "client_id": "{your app's oauth client id}",
            "client_secret": "{your app's oauth client secret}",
            "scopes": [
              "user:read:email",
              "openid"
            ]
          }
        }
      ]
    }
  ]
}
```

Click **Save** to validate and update your Traffic Policy.

### Configure access control

Optionally, configure access control to your service by only allowing specific users or domains.

```yaml policy.yml theme={null}
on_http_request:
  - expressions:
      - '!(actions.ngrok.oauth.identity.email in [''me@example.com''])'
    actions:
      - type: deny
```

```json policy.json theme={null}
{
  "on_http_request": [
    {
      "expressions": [
        "!(actions.ngrok.oauth.identity.email in ['me@example.com'])"
      ],
      "actions": [
        {
          "type": "deny"
        }
      ]
    }
  ]
}
```

## Further resources

* [Authentication](https://dev.twitch.tv/docs/authentication/)
* [Registering Your App](https://dev.twitch.tv/docs/authentication/register-app/)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.