Google OAuth
Creating a custom Google OAuth application
Step-by-step instructions below follow Google's documentation on setting up OAuth 2.0 for a web application.
Build the consent screen
- Create or select a project on the Google Cloud Platform Console.
- Navigate to the project's OAuth consent screen.
- Select whether your application is an internal or external app.
- Fill out the application name and support email.
- Add additional scopes required by your application, saving the full scope URI for later.
- Ensure that the
email
andprofile
scopes are still selected. - Under Authorized domains, add
ngrok.com
and your application homepage domain. - Add links to your application homepage and privacy policy. The final consent screen should resemble:
- Save the application.
- Applications that require verification cannot complete the consent screen and are not supported by ngrok.
Create credentials for ngrok
- Navigate to Credentials for your project.
- Select "Create credentials" from the top menu and select "OAuth Client ID".
- Choose "Web application" from the list of application types.
- Name your secret, then set "Authorized Redirect URIs" to
https://idp.ngrok.com/oauth2/callback
. The final credentials form should resemble: - Securely store the client ID and secret from the final screen:
Update your ngrok endpoint traffic policy
- Access the ngrok Dashboard Endpoints page and locate an existing endpoint you'd like to add this to or create a new one.
- In your traffic policy, add the following configuration:
- YAML
- JSON
---
on_http_request:
- actions:
- type: oauth
config:
provider: google
client_id: "{your app's oauth client id}"
client_secret: "{your app's oauth client secret}"
scopes:
- https://www.googleapis.com/auth/userinfo.profile
- https://www.googleapis.com/auth/userinfo.email
{
"on_http_request": [
{
"actions": [
{
"type": "oauth",
"config": {
"provider": "google",
"client_id": "{your app's oauth client id}",
"client_secret": "{your app's oauth client secret}",
"scopes": [
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
]
}
}
]
}
]
}
- 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. For example:
- YAML
- JSON
# Only allow access to me@example.com. Add this after your OAuth Action.
---
on_http_request:
- expressions:
- "!(actions.ngrok.oauth.identity.email in ['me@example.com'])"
actions:
- type: deny
// Only allow access to me@example.com. Add this after your OAuth Action.
{
"on_http_request": [
{
"expressions": [
"!(actions.ngrok.oauth.identity.email in ['me@example.com'])"
],
"actions": [
{
"type": "deny"
}
]
}
]
}
Additional application setup information
- Google OAuth 2.0 Web Server (prerequisite steps)
- GCP Help: Setting up OAuth 2.0
- Google OAuth 2.0 workflow