When configuring GitLab OAuth2 authentication, an error occurs when redirecting to Grafana after successful GitLab authentication.
配置GitLab OAuth2身份验证,gitlab认证成功后跳转登录到grafana时报错
The log error message is:
日志报错信息:
logger=authn.service t=2024-11-22T20:02:48.258471558+08:00 level=error msg=“Failed to authenticate request” client=auth.client.gitlab error=“[auth.oauth.userinfo.error] failed to get user info: user 's email is not confirmed”
Configuring GitLab OAuth2 authentication, the GitLab configuration in the Grafana configuration file is as follows:
配置GitLab OAuth2身份验证,在Grafana配置文件中的GitLab配置如下:
[auth.gitlab]
enabled = true
allow_sign_up = true
client_id = 80a96d2b06aaf43a020f431d32b3fd772509f42b464db76ce63c9ca06eb24c7b
client_secret = cbe735cf2b779c18b7b94cf71c205ba907cde9695f0d15b491ee5872454284ec
scopes = api read_user openid
auth_url = xxxxxx
token_url = xxxxxx
api_url = xxxxxx
allowed_domains =
allowed_groups =
GitLab version:
gitlab版本
gitlab-ce-9.1.9
Grafana version:
Grafana版本
grafana-11.3.1-1
I’m sorry to hear that you’re experiencing difficulties.
Grafana can provide valuable information about certain issues through its own debug logs. These logs can help troubleshoot and identify the root cause of problems (especially if they are related to anything that can be configured via Grafana config file).
To enable debug logging edit the configuration file grafana.ini
:
[log]
# Either "console", "file", "syslog". Default is console and file
# Use space to separate multiple modes, e.g. "console file"
mode = console file
# Either "debug", "info", "warn", "error", "critical", default is "info"
level = debug
Then restart grafana for the setting to go into effect.
Replicate the problem and check Grafana logs. However, before posting the debug logs on the community forum, it is important to sanitize any private details such as passwords, tokens, IPs, names, … By including properly formatted debug logs (with sanitized information) and details about your installations (e.g. exact Grafana version, how it was installed, OS details, …), you greatly enhance the chances of receiving accurate assistance and solutions.
1 Like
This issue typically occurs due to a mismatch in the redirect URI settings. Ensure the following:
- Redirect URI in GitLab: Verify that the redirect URI in your GitLab OAuth2 application matches the one configured in Grafana (
/login/gitlab
endpoint).
- Grafana Configuration: Check
grafana.ini
or environment variables to ensure the auth.gitlab.redirect_uri
matches the GitLab application setting.
- Base URL in Grafana: Set the correct
root_url
in grafana.ini
under [server]
to ensure the redirects use the correct domain.
1 Like
Resolved
There is a problem with the scopes configuration