diff --git a/app.example.ini b/app.example.ini index 2d6f86e3..000fc020 100644 --- a/app.example.ini +++ b/app.example.ini @@ -8,6 +8,13 @@ StartCmd = login Database = database CADir = Demo = +CasdoorEndpoint = +CasdoorClientId = +CasdoorClientSecret = +CasdoorCertificate = +CasdoorOrganization = +CasdoorApplication = +CasdoorRedirectUri = [nginx] AccessLogPath = /var/log/nginx/access.log diff --git a/frontend/src/api/auth.ts b/frontend/src/api/auth.ts index 35363e89..f33d72f2 100644 --- a/frontend/src/api/auth.ts +++ b/frontend/src/api/auth.ts @@ -13,6 +13,15 @@ const auth = { login(r.token) }) }, + async casdoorLogin(code: string, state: string) { + await http.post("/casdoor_callback", { + code: code, + state: state, + }) + .then((r) => { + login(r.token) + }) + }, logout() { return http.delete('/logout').then(async () => { logout() diff --git a/frontend/src/views/other/Login.vue b/frontend/src/views/other/Login.vue index fba54ce1..8964ea10 100644 --- a/frontend/src/views/other/Login.vue +++ b/frontend/src/views/other/Login.vue @@ -8,6 +8,8 @@ import {Form, message} from 'ant-design-vue' import auth from '@/api/auth' import install from '@/api/install' import SetLanguage from '@/components/SetLanguage/SetLanguage.vue' +import http from '@/lib/http' +import {onMounted} from 'vue' const thisYear = new Date().getFullYear() @@ -70,6 +72,37 @@ watch(() => gettext.current, () => { clearValidate() }) +const has_casdoor = ref(false) +const casdoor_uri = ref('') + +http.get("/casdoor_uri") + .then((response) => { + if (response?.uri) { + has_casdoor.value = true + casdoor_uri.value = response.uri + } + }) + .catch((e) => { + message.error($gettext(e.message ?? 'Server error')) + }); + +const loginWithCasdoor = () => { + window.location.href = casdoor_uri.value +} + +if (route.query?.code != undefined && route.query?.state != undefined) { + loading.value = true + auth.casdoorLogin(route.query.code.toString(), route.query.state.toString()).then(async () => { + message.success($gettext('Login successful'), 1) + const next = (route.query?.next || '').toString() || '/' + await router.push(next) + }).catch(e => { + message.error($gettext(e.message ?? 'Server error')) + }) + loading.value = false +} + +