Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Generic OAuth Authentication
You can configure many different oauth2 authentication services with Grafana using the generic oauth2 feature. Below you can find examples using Okta, BitBucket, OneLogin and Azure.
This callback URL must match the full HTTP address that you use in your browser to access Grafana, but with the prefix path of /login/generic_oauth
.
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.
Example config:
[auth.generic_oauth]
enabled = true
client_id = YOUR_APP_CLIENT_ID
client_secret = YOUR_APP_CLIENT_SECRET
scopes =
auth_url =
token_url =
api_url =
allowed_domains = mycompany.com mycompany.org
allow_sign_up = true
Set api_url
to the resource that returns OpenID UserInfo compatible information.
Grafana will attempt to determine the user’s e-mail address by querying the OAuth provider as described below in the following order until an e-mail address is found:
- Check for the presence of an e-mail address via the
email
field encoded in the OAuthid_token
parameter. - Check for the presence of an e-mail address in the
attributes
map encoded in the OAuthid_token
parameter. By default Grafana will perform a lookup into the attributes map using theemail:primary
key, however, this is configurable and can be adjusted by using theemail_attribute_name
configuration option. - Query the
/emails
endpoint of the OAuth provider’s API (configured withapi_url
) and check for the presence of an e-mail address marked as a primary address. - If no e-mail address is found in steps (1-3), then the e-mail address of the user is set to the empty string.
Set up OAuth2 with Okta
First set up Grafana as an OpenId client “webapplication” in Okta. Then set the Base URIs to https://<grafana domain>/
and set the Login redirect URIs to https://<grafana domain>/login/generic_oauth
.
Finally set up the generic oauth module like this:
[auth.generic_oauth]
name = Okta
enabled = true
scopes = openid profile email
client_id = <okta application Client ID>
client_secret = <okta application Client Secret>
auth_url = https://<okta domain>/oauth2/v1/authorize
token_url = https://<okta domain>/oauth2/v1/token
api_url = https://<okta domain>/oauth2/v1/userinfo
Set up OAuth2 with Bitbucket
[auth.generic_oauth]
name = BitBucket
enabled = true
allow_sign_up = true
client_id = <client id>
client_secret = <client secret>
scopes = account email
auth_url = https://bitbucket.org/site/oauth2/authorize
token_url = https://bitbucket.org/site/oauth2/access_token
api_url = https://api.bitbucket.org/2.0/user
team_ids =
allowed_organizations =
Set up OAuth2 with OneLogin
Create a new Custom Connector with the following settings:
- Name: Grafana
- Sign On Method: OpenID Connect
- Redirect URI:
https://<grafana domain>/login/generic_oauth
- Signing Algorithm: RS256
- Login URL:
https://<grafana domain>/login/generic_oauth
then:
Add an App to the Grafana Connector:
- Display Name: Grafana
then:
Under the SSO tab on the Grafana App details page you’ll find the Client ID and Client Secret.
Your OneLogin Domain will match the url you use to access OneLogin.
Configure Grafana as follows:
[auth.generic_oauth] name = OneLogin enabled = true allow_sign_up = true client_id = <client id> client_secret = <client secret> scopes = openid email name auth_url = https://<onelogin domain>.onelogin.com/oidc/auth token_url = https://<onelogin domain>.onelogin.com/oidc/token api_url = https://<onelogin domain>.onelogin.com/oidc/me team_ids = allowed_organizations =
Set up OAuth2 with Auth0
Create a new Client in Auth0
- Name: Grafana
- Type: Regular Web Application
Go to the Settings tab and set:
- Allowed Callback URLs:
https://<grafana domain>/login/generic_oauth
- Allowed Callback URLs:
Click Save Changes, then use the values at the top of the page to configure Grafana:
[auth.generic_oauth] enabled = true allow_sign_up = true team_ids = allowed_organizations = name = Auth0 client_id = <client id> client_secret = <client secret> scopes = openid profile email auth_url = https://<domain>/authorize token_url = https://<domain>/oauth/token api_url = https://<domain>/userinfo
Set up OAuth2 with Azure Active Directory
Log in to portal.azure.com and click “Azure Active Directory” in the side menu, then click the “Properties” sub-menu item.
Copy the “Directory ID”, this is needed for setting URLs later
Click “App Registrations” and add a new application registration:
- Name: Grafana
- Application type: Web app / API
- Sign-on URL:
https://<grafana domain>/login/generic_oauth
Click the name of the new application to open the application details page.
Note down the “Application ID”, this will be the OAuth client id.
Click “Settings”, then click “Keys” and add a new entry under Passwords
- Key Description: Grafana OAuth
- Duration: Never Expires
Click Save then copy the key value, this will be the OAuth client secret.
Configure Grafana as follows:
[auth.generic_oauth] name = Azure AD enabled = true allow_sign_up = true client_id = <application id> client_secret = <key value> scopes = openid email name auth_url = https://login.microsoftonline.com/<directory id>/oauth2/authorize token_url = https://login.microsoftonline.com/<directory id>/oauth2/token api_url = team_ids = allowed_organizations =
Note: It’s important to ensure that the root_url in Grafana is set in your Azure Application Reply URLs (App -> Settings -> Reply URLs)
Set up OAuth2 with Centrify
Create a new Custom OpenID Connect application configuration in the Centrify dashboard.
Create a memorable unique Application ID, e.g. “grafana”, “grafana_aws”, etc.
Put in other basic configuration (name, description, logo, category)
On the Trust tab, generate a long password and put it into the OpenID Connect Client Secret field.
Put the URL to the front page of your Grafana instance into the “Resource Application URL” field.
Add an authorized Redirect URI like https://your-grafana-server/login/generic_oauth
Set up permissions, policies, etc. just like any other Centrify app
Configure Grafana as follows:
[auth.generic_oauth] name = Centrify enabled = true allow_sign_up = true client_id = <OpenID Connect Client ID from Centrify> client_secret = <your generated OpenID Connect Client Sercret" scopes = openid email name auth_url = https://<your domain>.my.centrify.com/OAuth2/Authorize/<Application ID> token_url = https://<your domain>.my.centrify.com/OAuth2/Token/<Application ID>