https://auth.example.com 请换成你的 Casdoor 地址(Casdoor 云上类似 https://acme.casdoor.com),其他 example.com 地址也换成你自己的。用 Casdoor 配置 Grafana
- 1
在 Casdoor 中注册 Grafana
在 Casdoor 控制台打开 应用,为 Grafana 添加一个应用,在它的 OIDC/OAuth 标签页复制 客户端ID 和 客户端密钥。把下面的地址加到 重定向URLs:
https://grafana.example.com/login/generic_oauth
要用群组的话,先在应用所属的组织里创建群组(例如
grafana-adminsandgrafana-editors)并加入用户,再在同一个标签页把 Token 中的群组格式 设成 Name,这样令牌里是grafana-admins,而不是<组织>/grafana-admins。 - 2
Configure Grafana
Add this section to
grafana.ini, or set the same keys asGF_AUTH_GENERIC_OAUTH_*environment variables.root_urlmust be the address people open in the browser, because Grafana builds the callback URL from it.[server] root_url = https://grafana.example.com/ [auth.generic_oauth] enabled = true name = Casdoor client_id = <client ID> client_secret = <client secret> scopes = openid profile email auth_url = https://auth.example.com/login/oauth/authorize token_url = https://auth.example.com/api/login/oauth/access_token api_url = https://auth.example.com/api/userinfo use_pkce = true allow_sign_up = true login_attribute_path = preferred_username email_attribute_path = email groups_attribute_path = groups role_attribute_path = contains(groups[*], 'grafana-admins') && 'Admin' || contains(groups[*], 'grafana-editors') && 'Editor' || 'Viewer' - 3
Sign in
Restart Grafana. The login page now has a Sign in with Casdoor button. Members of
grafana-adminsbecome Admins, members ofgrafana-editorsEditors, and everyone else a Viewer.
注意事项
- Grafana evaluates
role_attribute_pathagainst the ID token first, then the userinfo response. Casdoor's ID token also lists the user's roles as objects, socontains(roles[*].name, 'admin')works too if you prefer Casdoor roles to groups. - Grafana needs an email address for every user, so make sure your Casdoor users have one.
Grafana 的设置取自它的官方文档(核对于 2026年10月:Grafana Generic OAuth);另见Casdoor 文档。Grafana 是其所有者的商标。
常见问题
Can I use SAML instead?
Grafana's SAML sign-in is part of Grafana Enterprise and Grafana Cloud. On open-source Grafana, OpenID Connect through Generic OAuth, as shown here, is the way to connect Casdoor.
Do Casdoor groups become Grafana teams?
groups_attribute_path feeds Grafana's Team Sync, which is a Grafana Enterprise and Grafana Cloud feature. On open-source Grafana, use the groups to set roles as shown above.
更多应用集成
查看全部Argo CD
应用集成Connect Argo CD to Casdoor over OpenID Connect: oidc.config in argocd-cm, the client secret, PKCE, CLI login and RBAC from Casdoor groups.
Gitea
应用集成Add Casdoor to Gitea as an OpenID Connect authentication source: the add-oauth command, callback URL, and admins from a Casdoor group.
GitLab
应用集成Configure self-managed GitLab to sign users in with Casdoor over OpenID Connect: gitlab.rb provider settings, account creation and group-based admins.
