Skip to content

Commit

Permalink
Merge branch 'csghub-main' into csghub__refactor-get-current-user
Browse files Browse the repository at this point in the history
  • Loading branch information
hiveer committed Dec 3, 2024
2 parents 8649418 + c7166f2 commit 81a9cba
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 52 deletions.
54 changes: 15 additions & 39 deletions docs/user_system_cn.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
# 用户系统概述

我们的开源平台支持两种用户系统的接入方式:
- 平台默认提供一个简单的用户登录授权系统,支持用户注册和登录,但不支持密码修改。
- 通过环境变量或系统配置,可以接入支持 OIDC 的用户登录授权系统。

## 如何切换两种用户登录系统

- 我们提供一个环境变量 `ON_PREMISE`,当其值为 `true` 时,系统将使用内置的用户系统进行用户登录授权验证。
- 当其值为 `false` 时,系统将通过接入外部的 OIDC 系统进行授权登录验证。

## OIDC 配置

所需的 OIDC 相关的配置项如下:

1. 用于建立 OIDC 连接
- identifier: 客户端ID
- secret: 客户端密钥
- authorization_endpoint: 授权接口
- token_endpoint: 获取 access token 接口
- userinfo_endpoint: 获取用户信息接口
- redirect_uri: callback URL

2. 用于登录注册
- login_url: OIDC 登录入口
- signup_url: OIDC 注册入口

可以通过两种方式提供 OIDC 配置项:

1. 通过环境变量
- OIDC_IDENTIFIER
- OIDC_SECRET
- OIDC_REDIRECT_URI
- OIDC_AUTHORIZATION_ENDPOINT
- OIDC_TOKEN_ENDPOINT
- OIDC_USERINFO_ENDPOINT
- LOGIN_URL
- SIGNUP_URL

2. 通过管理员后台进行系统设置
CSGHub 平台通过对接 Casdoor 实现了用户的登录授权,Casdoor 自身具备单点登录和第三方登录的能力,用户可以方便的进行配置和集成。

## 集成方式
在 csghub-server 的 user service 可以通过如下环境变量的配置进行 Casdoor 的接入:
- STARHUB_SERVER_CASDOOR_CLIENT_ID: ${STARHUB_SERVER_CASDOOR_CLIENT_ID}
- STARHUB_SERVER_CASDOOR_CLIENT_SECRET: ${STARHUB_SERVER_CASDOOR_CLIENT_SECRET}
- STARHUB_SERVER_CASDOOR_ENDPOINT: ${STARHUB_SERVER_CASDOOR_ENDPOINT}
- STARHUB_SERVER_CASDOOR_CERTIFICATE: <casdoor_stg_cert-token_jwt_key.pem>
- STARHUB_SERVER_CASDOOR_ORGANIZATION_NAME: ${STARHUB_SERVER_CASDOOR_ORGANIZATION_NAME}
- STARHUB_SERVER_CASDOOR_APPLICATION_NAME: ${STARHUB_SERVER_CASDOOR_APPLICATION_NAME}

## 特别注意
1. 第三方登录的用户,因为各个集成的第三方系统的差异(可能会没有用户名,或者用户名为中文等情况),这些差异跟我们自身系统不兼容
所以对于第三方登录的用户,我们强制要求用户对用户名进行更新,且只能更新一次
2. 目前 csghub-server 还未完成 casdoor 密码回写的集成,所以系统暂不支持更新用户密码
16 changes: 6 additions & 10 deletions frontend/src/components/application_spaces/NewApplicationSpace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<p class="font-semibold text-md">Streamlit</p>
</el-radio>
<el-radio
v-if="isAdmin"
v-if="userStore.isAdmin"
class="rounded-md !border-[2px] !h-[120px] flex justify-center"
size="large"
label="nginx"
Expand All @@ -225,7 +225,7 @@
<p class="font-semibold text-md">Nginx</p>
</el-radio>
<el-radio
v-if="!isAdmin"
v-if="!userStore.isAdmin"
class="rounded-md !border-[2px] !h-[120px] flex justify-center"
size="large"
label="docker"
Expand Down Expand Up @@ -338,22 +338,18 @@
import { useI18n } from 'vue-i18n'
import useFetchApi from '../../packs/useFetchApi'
import useUserStore from '../../stores/UserStore'
import { useCookies } from 'vue3-cookies'
import PublicAndPrivateRadioGroup from '../shared/form/PublicAndPrivateRadioGroup.vue'
const userStore = useUserStore()
const props = defineProps({
licenses: Array
})
const { cookies } = useCookies()
const userStore = useUserStore()
const dataFormRef = ref(null)
const imageUploaded = ref(false)
const images = ref([])
const { t } = useI18n()
const nameRule = inject('nameRule')
const isAdmin = cookies.isKey('admin_user')
const props = defineProps({
licenses: Array
})
const dataForm = ref({
owner: '',
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/stores/UserStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ const useUserStore = defineStore('User', () => {
const uuid = ref('')
const homepage = ref('')
const bio = ref('')
const roles = ref('')
const roles = ref([])
const orgs = ref([])
const lastLoginTime = ref('')
const initialized = ref(false)

const isLoggedIn = computed(() => username.value !== '')
const isAdmin = computed(() => roles.value.includes('admin') || roles.value.includes('super_user'))
const isSuperUser = computed(() => roles.value.includes('super_user'))

async function initialize(initialData) {
username.value = initialData.username || ''
Expand Down Expand Up @@ -48,7 +50,9 @@ const useUserStore = defineStore('User', () => {
roles,
orgs,
lastLoginTime,
initialized
initialized,
isAdmin,
isSuperUser
}
})

Expand Down
1 change: 0 additions & 1 deletion internal/handlers/render/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func (i *SessionHandlerImpl) Create(ctx *gin.Context) {
user.SetRoles(userResp.Roles...)

ctx.SetCookie("login_identity", user.LoginIdentity, cookieMaxAge, "/", "", false, false)
ctx.SetCookie("admin_user", fmt.Sprintf("%t", user.IsAdmin()), cookieMaxAge, "/", "", false, false)

user.SessionIP = ctx.ClientIP()
err = i.userModel.Update(ctx, user)
Expand Down

0 comments on commit 81a9cba

Please sign in to comment.