Configuration Reference
The Traffic Policy configuration reference for this action.Supported Phases
on_http_request
Type
oauth
Configuration Fields
The name of the OAuth identity provider to be used for authentication.
Unique authentication identifier for this provider. This value will be
used for the cookie, redirect, authentication and logout purposes.
To login a user you must use
/ngrok/login?auth_id={auth_id}
. If you are
using path based auth you must include the path to be redirected back to:
?redirect_path=/foo
Your OAuth app’s client ID.
Leave this empty if you want to use ngrok’s managed application.
Your OAuth app’s client secret.
Leave this empty if you want to use a managed application.
A list of additional scopes to request when users authenticate with the
identity provider.
A map of additional URL parameters to apply to the authorization endpoint
URL.
Defines the maximum lifetime of a session regardless of activity.
Defines the period of inactivity after which a user’s session is
automatically ended, requiring re-authentication.
How often should ngrok refresh data about the authenticated user from the
identity provider.
Allow CORS preflight requests to bypass authentication checks. Enable if
the endpoint needs to be accessible via CORS.
Sets the allowed domain for the auth cookie.
Special Paths
/ngrok/login
Redirect users to this path to explicitly begin an authentication flow. After authentication, users will be redirected to /
. If the IdP supports it, ngrok will attempt to instruct the IdP to force re-authentication which will force users to re-enter their credentials with the IdP even if they were already logged in. |
/ngrok/logout
Logs the user out by clearing their session cookie. Redirect users to this path to log them out.
When using the Google OAuth 2.0/OIDC provider in Chrome with a managed profile,
/ngrok/logout
only clears the ngrok session cookie; it does not end the Google/IdP session maintained by the browser. Users may be silently re-authenticated on the next request. To fully sign out, sign out of Chrome/Google (or use a non-managed profile or Incognito) in addition to calling /ngrok/logout
.Events
When this action is enabled, it populates the following fields in the http_request_complete.v0 event:oauth.app_client_id
oauth.decision
oauth.user.id
oauth.user.name
Supported Providers
ngrok currently supports the following OAuth providers (see the Integration Guides for more details). In some instances, ngrok has a managed application that allows you to configure OAuth without setting up your own application in your provider. This is useful for testing and development, but when you move into production, we recommend using your own custom application in your specific provider.Provider | Provider Identifier | Managed App Available | Integration Guide |
---|---|---|---|
Amazon | amazon | no | Documentation |
facebook | no | Documentation | |
GitHub | github | yes | Documentation |
GitLab | gitlab | yes | Documentation |
google | yes | Documentation | |
linkedin | yes | Documentation | |
Microsoft | microsoft | yes | Documentation |
Twitch | twitch | yes | Documentation |
Required Scopes
This is a list of the minimum required scopes for each provider. You can use this when configuring your identity provider. These are not required when using the ngrok managed applications.Provider | Scopes |
---|---|
Amazon | profile |
email | |
Github | read:org , read:user |
Gitlab | email , openid , profile |
https://www.googleapis.com/auth/userinfo.email , https://www.googleapis.com/auth/userinfo.profile | |
r_emailaddress , r_liteprofile | |
Microsoft | User.Read |
Twitch | user:read:email |
Try it out
Consult the list of supported providers for step-by-step integration guides.Behavior
Callback URL
When you create your own OAuth app, you must specify a ‘Callback URL’ or ‘Redirect URL’ to the OAuth provider. When using ngrok’s OAuth action, that Callback URL is always:Authentication
When an unauthenticated request is made to an OAuth-protected endpoint, it returns a redirect response that begins an authentication flow with the configured identity provider. The original URI path is saved so that users can be redirected to it if they successfully authenticate. If the user fails to authenticate with the identity provider, ngrok will display an error describing the failure returned by the identity provider and prompt them to try logging in again. If the user successfully authenticates with the identity provider, ngrok will take the following actions:- Sets a session cookie to avoid repeating the authentication flow again.
- Redirects the user to the original URI path they were attempting to access
before the authentication flow began. If no such URI path was captured, they
are redirected to
/
. - Continue processing the rest of the traffic policy actions.
Continuous Authorization
When an authenticated user makes a request, ngrok will sometimes refresh a user’s data from the identity provider (email, name, etc.) and re-evaluate authorization constraints. This refresh is executed as a back channel request to the identity provider; it is transparent to the user and they do not go through a re-authentication flow. The following circumstances trigger refresh and authorization re-evaluation:- On a periodic interval defined by the
userinfo_refresh_interval
parameter. - If you update the OAuth configuration of the endpoint either in the agent or through the dashboard.
- If you update the OAuth configuration of the endpoint.
Managed Applications
Managed applications allow you to use ngrok’s OAuth action without setting up your own OAuth apps with the identity providers. More practically, this means you can use the OAuth action without configuring a client id and client secret. Managed applications are great for getting started but they have some limitations.- They are only available for some identity providers.
- You may not pass custom scopes when using a managed application.
- The upstream headers
ngrok-auth-oauth-access-token
andngrok-auth-oauth-refresh-token
are not sent to your application.
Traffic Identities
ngrok’s Traffic Identities feature can be used to observe all of the authenticated user activity across your account in the ngrok dashboard or via the API. Whenever a user authenticates or accesses an endpoint with a configured OAuth action, their Traffic Identity record is created or updated. You may also use Traffic Identities to remotely log a user out by revoking a session.Cookies
This action sets two cookies in its operation. Cookies values are opaque to the upstream service and must not be modified.Cookie | Description |
---|---|
session | Used to track an authenticated user. |
nonce | Used to secure the authentication flow. |
Examples
Using a Managed Provider
The following Traffic Policy configuration will provide your app with a google authentication step.provider
value can be replaced with any of the Supported Providers that have an
a managed app available.
Restricting access to certain users
See here for an example of conditional access based on OAuth result variables.Using a Custom Provider
If you need more control than what a managed provider can offord you then you can bring your own provider.Google Example
GitHub Example
GitLab Example
LinkedIn Example
Microsoft Example
Twitch Example
Amazon Example
Facebook Example
Action Result Variables
The following variables are made available for use in subsequent expressions and CEL interpolations after the action has run. Variable values will only apply to the last action execution, results are not concatenated.Code for an error that occurred during the invocation of an action.
Message for an error that occurred during the invocation of an action.
Unique identifier for the ngrok Identity entity
Email address of the authorized user from the provider.
Name for the authorized user from the provider.
Identifier for the authorized user from the provider.
The current Identity session identifier for this request.
The access token from the provider.
The refresh token from the provider.
Timestamp when the current session will expire.
Returns true when the session timed out.
Returns true when the current session reached the max duration.
Returns true when ngrok updates the user information on the identity.