- Automatically enforce OAuth or JWT validation on browser or curl/machine-to-machine traffic, respectively.
- Route only authenticated requests to your upstream app and API services.
1. Set up your JWT provider
You can use any provider/issuer, but we have a guide for defining an API and generating tokens with Auth0.2. Start internal endpoints for your services
Start an internal Agent Endpoint, replacing$PORT
based on where your app service listens.
You can also use one of our SDKs or the Kubernetes Operator.
3. Reserve a domain
Navigate to the Domains section of the ngrok dashboard and click New + to reserve a free static domain likehttps://your-service.ngrok.app
or a custom domain you already own.
We’ll refer to this domain as $NGROK_DOMAIN
from here on out.
4. Create a Cloud Endpoint
Navigate to the Endpoints section of the ngrok dashboard, then click New + and Cloud Endpoint. In the URL field, enter the domain you just reserved to finish creating your Cloud Endpoint.5. Add JWT validation, OAuth, and routing with Traffic Policy
While still viewing your new cloud endpoint in the dashboard, copy and paste the policy below into the Traffic Policy editor. You may need to change:$YOUR_JWT_DOMAIN
: The domain name for your tenant at your JWT provider—for example, with Auth0, it looks something likehttps://example.us.auth0
.$YOUR_EMAIL_DOMAIN
: The domain name associated with your organization’s Google accounts for OAuth checks.
jwt-validation
action.
If the request has the appropriate Authorization: Bearer …
header, then ngrok forwards it to your API service.
In the second section, it then checks whether the user agent is from a human/browser, then asks them to authenticate with Google’s OAuth.
If the account they sign into matches $YOUR_EMAIL_DOMAIN
, then ngrok forwards it to your web app service.
In all other cases, the policy returns a 403 Forbidden
response because the request was not properly authenticated.
6. Try out your endpoint
Visit the domain you reserved either in the browser or in the terminal using a tool likecurl
.
You should see the app or service at the port connected to your internal Agent Endpoint.
In your terminal, make sure you add your JWT as a header:
What’s next?
- Read more about Traffic Policy and its core concepts.
- Explore all the configuration options in the
jwt-validate
andoauth
actions. - View your traffic in Traffic Inspector.