2022-05-26 23:06:25 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								aliases:
							 
						 
					
						
							
								
									
										
										
										
											2022-12-10 00:36:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  ../../../auth/google/
							 
						 
					
						
							
								
									
										
										
										
											2022-06-03 00:57:22 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								description: Grafana OAuthentication Guide
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Configure Google OAuth2 Authentication
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								weight: 300
							 
						 
					
						
							
								
									
										
										
										
											2022-05-26 23:06:25 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 18:11:56 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-03 00:57:22 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# Configure Google OAuth2 authentication
  
						 
					
						
							
								
									
										
										
										
											2018-09-06 18:11:56 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-24 21:46:31 +08: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 18:11:56 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Create Google OAuth keys
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								First, you need to create a Google OAuth Client:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-02-20 17:16:25 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								1.  Go to https://console.developers.google.com/apis/credentials. 
						 
					
						
							
								
									
										
										
										
											2020-10-02 00:45:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								1.  Click **Create Credentials** , then click **OAuth Client ID**  in the drop-down menu 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								1.  Enter the following: 
						 
					
						
							
								
									
										
										
										
											2018-09-06 18:11:56 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								   -  Application Type: Web Application
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   -  Name: Grafana
							 
						 
					
						
							
								
									
										
										
										
											2020-06-24 21:46:31 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								   -  Authorized JavaScript Origins: https://grafana.mycompany.com
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 18:11:56 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								   -  Authorized Redirect URLs: https://grafana.mycompany.com/login/google
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   -  Replace https://grafana.mycompany.com with the URL of your Grafana instance.
							 
						 
					
						
							
								
									
										
										
										
											2020-10-02 00:45:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								1.  Click Create 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								1.  Copy the Client ID and Client Secret from the 'OAuth Client' modal 
						 
					
						
							
								
									
										
										
										
											2018-09-06 18:11:56 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Enable Google OAuth in Grafana
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-18 04:24:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								Specify the Client ID and Secret in the [Grafana configuration file ]({{< relref "../../../configure-grafana/#config-file-locations" >}} ). For example:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 18:11:56 +08: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
							 
						 
					
						
							
								
									
										
										
										
											2023-01-06 03:04:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								hosted_domain = mycompany.com
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 18:11:56 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-10 04:26:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								You may have to set the `root_url`  option of `[server]`  for the callback URL to be
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 03:22:02 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								correct. For example in case you are serving Grafana behind a proxy.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 18:11:56 +08: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.
							 
						 
					
						
							
								
									
										
										
										
											2022-11-14 23:47:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-06 03:04:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You may specify a domain to be passed as `hd`  query parameter accepted by Google's
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								OAuth 2.0 authentication API. Refer to Google's OAuth [documentation ](https://developers.google.com/identity/openid-connect/openid-connect#hd-param ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-14 23:47:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Configure refresh token
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								>  Available in Grafana v9.3 and later versions.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								>  **Note:** This feature is behind the `accessTokenExpirationCheck` feature toggle.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								When a user logs in using an OAuth provider, Grafana verifies that the access token has not expired. When an access token expires, Grafana uses the provided refresh token (if any exists) to obtain a new access token.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Grafana uses a refresh token to obtain a new access token without requiring the user to log in again. If a refresh token doesn't exist, Grafana logs the user out of the system after the access token has expired.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								By default, Grafana includes the `access_type=offline`  parameter in the authorization request to request a refresh token.