halo-sigs / plugin-oauth2

Halo 2.0 的 OAuth2 第三方登录插件。
https://halo.run/store/apps/app-ESVDK
GNU General Public License v3.0
20 stars 19 forks source link

请问是否可以开发支持通用的OAuth? 近期是否有计划?谢谢! #23

Open DarkWayne opened 1 year ago

DarkWayne commented 1 year ago

请问是否可以开发支持通用的OAuth(接入三方OAuth认证体系)? 近期是否有计划?望答复,谢谢!~~

ruibaby commented 1 year ago

本身是支持通过配置来适配其他的 OAuth 提供方的,你可以详细描述一下你期望的使用方式。

DarkWayne commented 1 year ago

@ruibaby 老大好! ~ 我的场景是,我自身有一套内部的IDaaS身份认证系统,想通过OAuth来进行内部用户的登录认证。 但是看咱们目前标准的OAuth插件,只是支持gitLab、gitee等外部系统对接; 看这个后续是有可以有支持内部认证系统的标准插件吗? 或者有什么临时的折中解决方案,多谢老大给予指导 [拱手][拱手]

JohnNiang commented 1 year ago

Hi @DarkWayne ,你可以试试根据下面的 AuthProvider 样例自己配置一个符合你的认证系统的 AuthProvider:

apiVersion: auth.halo.run/v1alpha1
kind: AuthProvider
metadata:
+ name: gitlab
  labels:
    auth.halo.run/auth-binding: "true"
spec:
+ displayName: GitLab
+ description: GitLab Inc. is an open-core company that operates GitLab, a DevOps software package which can develop, secure, and operate software.
+ logo: /plugins/plugin-oauth2/assets/static/gitlab.svg
+ website: https://gitlab.com
+ authenticationUrl: /oauth2/authorization/gitlab
+ bindingUrl: /apis/api.plugin.halo.run/v1alpha1/plugins/plugin-oauth2/connect/gitlab
+ unbindUrl: /apis/api.plugin.halo.run/v1alpha1/plugins/plugin-oauth2/disconnect/gitlab
  settingRef:
    name: generic-oauth2-setting
    group: genericOauth
  configMapRef:
+   name: oauth2-gitlab-config

然后通过 API 创建对应的 AuthProvider,示例如下(需要自行替换 URL、用户名和密码、请求体):

curl -X 'POST' \
  'http://localhost:8090/apis/auth.halo.run/v1alpha1/authproviders' \
  -u admin:admin \
  -H 'accept: */*' \
  -H 'Content-Type: */*' \
  -d '{
  "apiVersion": "auth.halo.run/v1alpha1",
  "kind": "AuthProvider",
  "metadata": {
    "name": "gitlab",
    "labels": {
      "auth.halo.run/auth-binding": "true"
    }
  },
  "spec": {
    "displayName": "GitLab",
    "description": "GitLab Inc. is an open-core company that operates GitLab, a DevOps software package which can develop, secure, and operate software.",
    "logo": "/plugins/plugin-oauth2/assets/static/gitlab.svg",
    "website": "https://gitlab.com",
    "authenticationUrl": "/oauth2/authorization/gitlab",
    "bindingUrl": "/apis/api.plugin.halo.run/v1alpha1/plugins/plugin-oauth2/connect/gitlab",
    "unbindUrl": "/apis/api.plugin.halo.run/v1alpha1/plugins/plugin-oauth2/disconnect/gitlab",
    "settingRef": {
      "name": "generic-oauth2-setting",
      "group": "genericOauth"
    },
    "configMapRef": {
      "name": "oauth2-gitlab-config"
    }
  }
}'
DarkWayne commented 1 year ago

@JohnNiang 感谢啊! 有个细节问一下:在创建自定义配置的情况下, redirect_uri 是多少? authenticationUrl / bindingUrl / unbindUrl 的 path 最后的 "gitlab" 是不是来自于 metadata.name ? 请给下指导 [拱手]

JohnNiang commented 1 year ago

https://github.com/halo-sigs/plugin-oauth2/issues/23#issuecomment-1524493085

Hi @DarkWayne ,还需要创建一个 Oauth2ClientRegistration 才行,示例如下:

apiVersion: oauth.halo.run/v1alpha1
kind: Oauth2ClientRegistration
metadata:
  name: gitlab
spec:
  clientAuthenticationMethod: "client_secret_basic"
  authorizationGrantType: "authorization_code"
  redirectUri: "{baseUrl}/login/oauth2/code/gitlab"
  scopes:
    - "read_user"
  authorizationUri: "https://gitlab.com/oauth/authorize"
  tokenUri: "https://gitlab.com/oauth/token"
  userInfoUri: "https://gitlab.com/api/v4/user"
  userInfoAuthenticationMethod: "header"
  userNameAttributeName: "username"
  clientName: "GitLab"
DarkWayne commented 1 year ago

@JohnNiang @ruibaby 大神好!我已经做了一下尝试,目前本地的认证服务已通过配置接入了,已经可获取内部用户凭证和信息。 但是仍有个问题,就是无法向halo里自动同步注册用户,看咱们的插件是否有什么解决方案或计划

DarkWayne commented 1 year ago

@JohnNiang @ruibaby 大神好!我已经做了一下尝试,目前本地的认证服务已通过配置接入了,已经可获取内部用户凭证和信息。 但是仍有个问题,就是无法向halo里自动同步注册用户,看咱们的插件是否有什么解决方案或计划

@JohnNiang @ruibaby 两位有空帮回复一下[拱手]

JohnNiang commented 1 year ago

/cc @guqing

guqing commented 1 year ago

你想实现使用 IDaas 已有账户就能登录到 Halo,可能需要一个类似自动注册的功能,比如登录时没有账号就自动注册 Halo 账号关联它,但是目前不支持自动注册只支持先创建 Halo 账号然后绑定第三方账号实现登录或者登录时没有账号需要注册再绑定。

自动注册的功能有计划支持,会提供一个选项比如开启自动注册后使用 OAuth2 登录时自动创建 Halo 账号

DarkWayne commented 1 year ago

@guqing 感谢感谢!看后续计划的大时间概会很久么?

guqing commented 1 year ago

@guqing 感谢感谢!看后续计划的大时间概会很久么?

不确定,因为目前要维护的仓库实在太多了,主要还是先紧 halo-dev/halo 主仓库的维护

guqing commented 1 year ago

/reopen issue 关联错误导致关闭,我将重新打开

f2c-ci-robot[bot] commented 1 year ago

@guqing: Reopened this issue.

In response to [this](https://github.com/halo-sigs/plugin-oauth2/issues/23#issuecomment-1617564315): >/reopen >issue 关联错误导致关闭,我将重新打开 Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
LGY07 commented 7 months ago

同样需要自定义OAuth和OICD

chenjuefei commented 5 months ago

同样需要自定义OAuth和OICD

hhhguany commented 4 months ago

同样需要自定义OAuth和OICD