【问题标题】:enabling oauth2 with pgadmin and gitlab使用 pgadmin 和 gitlab 启用 oauth2
【发布时间】:2021-10-09 09:14:41
【问题描述】:

我已经在 Kubernetes 上部署了 pgadmin,我正在尝试按照 pgadmin docs 启用 oauth2

这是我传入的 oauth 配置:

AUTHENTICATION_SOURCES = ['oauth2', 'internal']

OAUTH2_CONFIG = [
    {
        # The name of the of the oauth provider, ex: github, google
        'OAUTH2_NAME': 'gitlab',
        # The display name, ex: Google
        'OAUTH2_DISPLAY_NAME': 'Gitlab',
        # Oauth client id
        'OAUTH2_CLIENT_ID': 'my-client-id-here',
        # Oauth secret
        'OAUTH2_CLIENT_SECRET': 'my-client-secret-here',
        # URL to generate a token,
        # Ex: https://github.com/login/oauth/access_token
        'OAUTH2_TOKEN_URL': 'https://gitlab.com/oauth/token',
        # URL is used for authentication,
        # Ex: https://github.com/login/oauth/authorize
        'OAUTH2_AUTHORIZATION_URL': "https://gitlab.com/oauth/authorize",
        # Oauth base url, ex: https://api.github.com/
        'OAUTH2_API_BASE_URL': 'https://gitlab.com/api/v4/',
        # Name of the Endpoint, ex: user
        'OAUTH2_USERINFO_ENDPOINT': 'user',
        # Font-awesome icon, ex: fa-github
        'OAUTH2_ICON': 'fa-gitlab',
        # UI button colour, ex: #0000ff
        'OAUTH2_BUTTON_COLOR': '#E24329',
    }
]
OAUTH2_AUTO_CREATE_USER = True

我已经在 Gitlab 上添加了应用程序。重定向 URI 是:

https://pgadmin.nonprod.example.io/oauth2/authorize
http://pgadmin.nonprod.example.io/oauth2/authorize

我为应用程序提供了以下范围:

  • API
  • openid
  • 个人资料
  • 电子邮件

我正在使用 pgadmin ingress 和我的本地 minikube 集群在本地对其进行测试。单击“使用 Gitlab 登录”按钮时,我不断收到以下错误:

{
success: 0,
errormsg: "403 Client Error: Forbidden for url: https://gitlab.com/api/v4/user",
info: "",
result: null,
data: null
}

我相信我拥有所有必要的 gitlab 权限并且无法弄清楚我做错了什么。

【问题讨论】:

    标签: kubernetes oauth-2.0 gitlab pgadmin


    【解决方案1】:

    我认为在这种情况下,我们可以只使用 OIDC 端点来获取用户信息。对于 gitlab,它是:ttps://gitlab.com/oauth/userinfo。因此,您不需要api 范围,只需openid email profile

    所以以下配置实际上对我有用:

    AUTHENTICATION_SOURCES = ['oauth2', 'internal']
    
    OAUTH2_CONFIG = [
        {
            'OAUTH2_NAME': 'gitlab',
            'OAUTH2_DISPLAY_NAME': 'Gitlab',
            'OAUTH2_CLIENT_ID': 'my-client-id-here',
            'OAUTH2_CLIENT_SECRET': 'my-client-secret-here',
            'OAUTH2_TOKEN_URL': 'https://gitlab.com/oauth/token',
            'OAUTH2_AUTHORIZATION_URL': "https://gitlab.com/oauth/authorize",
            'OAUTH2_API_BASE_URL': 'https://gitlab.com/oauth/',
            'OAUTH2_USERINFO_ENDPOINT': 'userinfo',
            'OAUTH2_SCOPE': 'openid email profile',
            'OAUTH2_ICON': 'fa-gitlab',
            'OAUTH2_BUTTON_COLOR': '#E24329',
        }
    ]
    OAUTH2_AUTO_CREATE_USER = True
    

    【讨论】:

      猜你喜欢
      • 2023-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      相关资源
      最近更新 更多