OAuth
Overview
The OAuth Traffic Policy action restricts access to only authorized users by enforcing OAuth through an identity provider of your choice.
Configuration Reference
The Traffic Policy configuration reference for this action.
Supported Phases
on_http_request
Type
oauth
Configuration Fields
providerstringRequired
The name of the OAuth identity provider to be used for authentication.
auth_idstring
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
To log a user out you must use
/ngrok/logout?auth_id={auth_id}
You additionally can provide a path to redirect the user to on logout:
?redirect_path=/
client_idstring
Your OAuth app's client ID.
Leave this empty if you want to use ngrok’s managed application.
client_secretstring
Your OAuth app's client secret.
Leave this empty if you want to use a managed application.
scopesarray of strings
A list of additional scopes to request when users authenticate with the identity provider.
authz_url_paramsmap of string to string
A map of additional URL parameters to apply to the authorization endpoint URL.
max_session_durationduration
Defines the maximum lifetime of a session regardless of activity.
idle_session_timeoutduration
Defines the period of inactivity after which a user's session is automatically ended, requiring re-authentication.
userinfo_refresh_intervalduration
How often should ngrok refresh data about the authenticated user from the identity provider.
allow_cors_preflightboolean
Allow CORS preflight requests to bypass authentication checks. Enable if the endpoint needs to be accessible via CORS.
Default:
false
auth_cookie_domainstring
Sets the allowed domain for the auth cookie.
Special Paths
Path | Description |
---|---|
/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. |
Events
When this action is enabled, it populates the following fields in the http_request_complete.v0 event:
Fields |
---|
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:
Loading…
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.
If a previously authenticated user becomes unauthorized because their identity provider information changed or because the OAuth action configuration changed, they are presented an error and are prompted to try logging in again.