2018-09-06 05:11:56 -05:00
+++
title = "Google OAuth2 Authentication"
description = "Grafana OAuthentication Guide "
keywords = ["grafana", "configuration", "documentation", "oauth"]
type = "docs"
[menu.docs]
2018-09-06 06:15:36 -05:00
name = "Google"
2020-06-30 16:42:50 -05:00
identifier = "google_oauth2"
2018-09-06 05:11:56 -05:00
parent = "authentication"
2020-10-01 16:37:26 -05:00
weight = 600
2018-09-06 05:11:56 -05:00
+++
# Google OAuth2 Authentication
2020-06-24 08:46:31 -05:00
To enable Google OAuth2 you must register your application with Google. Google will generate a client ID and secret key for you to use.
2018-09-06 05:11:56 -05:00
## Create Google OAuth keys
First, you need to create a Google OAuth Client:
2020-02-20 03:16:25 -06:00
1. Go to https://console.developers.google.com/apis/credentials.
2020-10-01 11:45:05 -05:00
1. Click **Create Credentials** , then click **OAuth Client ID** in the drop-down menu
1. Enter the following:
2018-09-06 05:11:56 -05:00
- Application Type: Web Application
- Name: Grafana
2020-06-24 08:46:31 -05:00
- Authorized JavaScript Origins: https://grafana.mycompany.com
2018-09-06 05:11:56 -05:00
- Authorized Redirect URLs: https://grafana.mycompany.com/login/google
- Replace https://grafana.mycompany.com with the URL of your Grafana instance.
2020-10-01 11:45:05 -05:00
1. Click Create
1. Copy the Client ID and Client Secret from the 'OAuth Client' modal
2018-09-06 05:11:56 -05:00
## Enable Google OAuth in Grafana
2020-06-23 11:56:44 -05:00
Specify the Client ID and Secret in the [Grafana configuration file ]({{< relref "../administration/configuration.md#config-file-locations" >}} ). For example:
2018-09-06 05:11:56 -05:00
```bash
[auth.google]
enabled = true
client_id = CLIENT_ID
client_secret = CLIENT_SECRET
scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
auth_url = https://accounts.google.com/o/oauth2/auth
token_url = https://accounts.google.com/o/oauth2/token
allowed_domains = mycompany.com mycompany.org
allow_sign_up = true
```
2018-10-11 14:22:02 -05:00
You may have to set the `root_url` option of `[server]` for the callback URL to be
correct. For example in case you are serving Grafana behind a proxy.
2018-09-06 05:11:56 -05:00
Restart the Grafana back-end. You should now see a Google login button
on the login page. You can now login or sign up with your Google
accounts. The `allowed_domains` option is optional, and domains were separated by space.
You may allow users to sign-up via Google authentication by setting the
`allow_sign_up` option to `true` . When this option is set to `true` , any
user successfully authenticating via Google authentication will be
automatically signed up.