|
| 1 | ++++ |
| 2 | +title = "OAuth authentication" |
| 3 | +description = "Grafana OAuthentication Guide " |
| 4 | +keywords = ["grafana", "configuration", "documentation", "oauth"] |
| 5 | +type = "docs" |
| 6 | +[menu.docs] |
| 7 | +name = "Generic OAuth2" |
| 8 | +identifier = "generic_oauth" |
| 9 | +parent = "authentication" |
| 10 | +weight = 3 |
| 11 | ++++ |
| 12 | + |
| 13 | +# Generic OAuth Authentication |
| 14 | + |
| 15 | +You can configure many different oauth2 authentication services with Grafana using the generic oauth2 feature. Below you |
| 16 | +can find examples using Okta, BitBucket, OneLogin and Azure. |
| 17 | + |
| 18 | +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`. |
| 19 | + |
| 20 | +Example config: |
| 21 | + |
| 22 | +```bash |
| 23 | +[auth.generic_oauth] |
| 24 | +enabled = true |
| 25 | +client_id = YOUR_APP_CLIENT_ID |
| 26 | +client_secret = YOUR_APP_CLIENT_SECRET |
| 27 | +scopes = |
| 28 | +auth_url = |
| 29 | +token_url = |
| 30 | +api_url = |
| 31 | +allowed_domains = mycompany.com mycompany.org |
| 32 | +allow_sign_up = true |
| 33 | +``` |
| 34 | + |
| 35 | +Set api_url to the resource that returns [OpenID UserInfo](https://connect2id.com/products/server/docs/api/userinfo) compatible information. |
| 36 | + |
| 37 | +## Set up OAuth2 with Okta |
| 38 | + |
| 39 | +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`. |
| 40 | + |
| 41 | +Finally set up the generic oauth module like this: |
| 42 | +```bash |
| 43 | +[auth.generic_oauth] |
| 44 | +name = Okta |
| 45 | +enabled = true |
| 46 | +scopes = openid profile email |
| 47 | +client_id = <okta application Client ID> |
| 48 | +client_secret = <okta application Client Secret> |
| 49 | +auth_url = https://<okta domain>/oauth2/v1/authorize |
| 50 | +token_url = https://<okta domain>/oauth2/v1/token |
| 51 | +api_url = https://<okta domain>/oauth2/v1/userinfo |
| 52 | +``` |
| 53 | + |
| 54 | +## Set up OAuth2 with Bitbucket |
| 55 | + |
| 56 | +```bash |
| 57 | +[auth.generic_oauth] |
| 58 | +name = BitBucket |
| 59 | +enabled = true |
| 60 | +allow_sign_up = true |
| 61 | +client_id = <client id> |
| 62 | +client_secret = <client secret> |
| 63 | +scopes = account email |
| 64 | +auth_url = https://bitbucket.org/site/oauth2/authorize |
| 65 | +token_url = https://bitbucket.org/site/oauth2/access_token |
| 66 | +api_url = https://api.bitbucket.org/2.0/user |
| 67 | +team_ids = |
| 68 | +allowed_organizations = |
| 69 | +``` |
| 70 | + |
| 71 | +## Set up OAuth2 with OneLogin |
| 72 | + |
| 73 | +1. Create a new Custom Connector with the following settings: |
| 74 | + - Name: Grafana |
| 75 | + - Sign On Method: OpenID Connect |
| 76 | + - Redirect URI: `https://<grafana domain>/login/generic_oauth` |
| 77 | + - Signing Algorithm: RS256 |
| 78 | + - Login URL: `https://<grafana domain>/login/generic_oauth` |
| 79 | + |
| 80 | + then: |
| 81 | +2. Add an App to the Grafana Connector: |
| 82 | + - Display Name: Grafana |
| 83 | + |
| 84 | + then: |
| 85 | +3. Under the SSO tab on the Grafana App details page you'll find the Client ID and Client Secret. |
| 86 | + |
| 87 | + Your OneLogin Domain will match the url you use to access OneLogin. |
| 88 | + |
| 89 | + Configure Grafana as follows: |
| 90 | + |
| 91 | + ```bash |
| 92 | + [auth.generic_oauth] |
| 93 | + name = OneLogin |
| 94 | + enabled = true |
| 95 | + allow_sign_up = true |
| 96 | + client_id = <client id> |
| 97 | + client_secret = <client secret> |
| 98 | + scopes = openid email name |
| 99 | + auth_url = https://<onelogin domain>.onelogin.com/oidc/auth |
| 100 | + token_url = https://<onelogin domain>.onelogin.com/oidc/token |
| 101 | + api_url = https://<onelogin domain>.onelogin.com/oidc/me |
| 102 | + team_ids = |
| 103 | + allowed_organizations = |
| 104 | + ``` |
| 105 | + |
| 106 | +### Set up OAuth2 with Auth0 |
| 107 | + |
| 108 | +1. Create a new Client in Auth0 |
| 109 | + - Name: Grafana |
| 110 | + - Type: Regular Web Application |
| 111 | + |
| 112 | +2. Go to the Settings tab and set: |
| 113 | + - Allowed Callback URLs: `https://<grafana domain>/login/generic_oauth` |
| 114 | + |
| 115 | +3. Click Save Changes, then use the values at the top of the page to configure Grafana: |
| 116 | + |
| 117 | + ```bash |
| 118 | + [auth.generic_oauth] |
| 119 | + enabled = true |
| 120 | + allow_sign_up = true |
| 121 | + team_ids = |
| 122 | + allowed_organizations = |
| 123 | + name = Auth0 |
| 124 | + client_id = <client id> |
| 125 | + client_secret = <client secret> |
| 126 | + scopes = openid profile email |
| 127 | + auth_url = https://<domain>/authorize |
| 128 | + token_url = https://<domain>/oauth/token |
| 129 | + api_url = https://<domain>/userinfo |
| 130 | + ``` |
| 131 | + |
| 132 | +### Set up OAuth2 with Azure Active Directory |
| 133 | + |
| 134 | +1. Log in to portal.azure.com and click "Azure Active Directory" in the side menu, then click the "Properties" sub-menu item. |
| 135 | + |
| 136 | +2. Copy the "Directory ID", this is needed for setting URLs later |
| 137 | + |
| 138 | +3. Click "App Registrations" and add a new application registration: |
| 139 | + - Name: Grafana |
| 140 | + - Application type: Web app / API |
| 141 | + - Sign-on URL: `https://<grafana domain>/login/generic_oauth` |
| 142 | + |
| 143 | +4. Click the name of the new application to open the application details page. |
| 144 | + |
| 145 | +5. Note down the "Application ID", this will be the OAuth client id. |
| 146 | + |
| 147 | +6. Click "Settings", then click "Keys" and add a new entry under Passwords |
| 148 | + - Key Description: Grafana OAuth |
| 149 | + - Duration: Never Expires |
| 150 | + |
| 151 | +7. Click Save then copy the key value, this will be the OAuth client secret. |
| 152 | + |
| 153 | +8. Configure Grafana as follows: |
| 154 | + |
| 155 | + ```bash |
| 156 | + [auth.generic_oauth] |
| 157 | + name = Azure AD |
| 158 | + enabled = true |
| 159 | + allow_sign_up = true |
| 160 | + client_id = <application id> |
| 161 | + client_secret = <key value> |
| 162 | + scopes = openid email name |
| 163 | + auth_url = https://login.microsoftonline.com/<directory id>/oauth2/authorize |
| 164 | + token_url = https://login.microsoftonline.com/<directory id>/oauth2/token |
| 165 | + api_url = |
| 166 | + team_ids = |
| 167 | + allowed_organizations = |
| 168 | + ``` |
| 169 | + |
| 170 | +<hr> |
| 171 | + |
| 172 | + |
0 commit comments