diff --git a/backend/src/routes/auth/gitlab.rs b/backend/src/routes/auth/gitlab.rs index 4707e82..81cf5ae 100644 --- a/backend/src/routes/auth/gitlab.rs +++ b/backend/src/routes/auth/gitlab.rs @@ -24,22 +24,28 @@ pub struct GitlabUser { } pub static REDIRECT_URL: Lazy = Lazy::new(|| CONFIG.gitlab_redirect_url.clone() + "/api/auth/gitlab_callback"); -pub static TOKEN_URL: Lazy = Lazy::new(|| format!("{}/oauth/token", CONFIG.gitlab_api_url.clone())); -pub static USER_URL: Lazy = Lazy::new(|| format!("{}/api/v4/user", CONFIG.gitlab_api_url.clone())); -pub static AUTHORIZE_URL: Lazy = Lazy::new(|| format!("{}/oauth/authorize", CONFIG.gitlab_url.clone())); +pub static TOKEN_URL: Lazy = Lazy::new(|| format!("{}/login/oauth/access_token", CONFIG.gitlab_api_url.clone())); +pub static USER_URL: Lazy = Lazy::new(|| format!("{}/api/v1/user", CONFIG.gitlab_api_url.clone())); +pub static AUTHORIZE_URL: Lazy = Lazy::new(|| format!("{}/login/oauth/authorize", CONFIG.gitlab_url.clone())); pub fn get_gitlab_token(span: &Span, code_or_token: String, token: bool) -> Option { let _span = metrics::span("get_gitlab_token", span); - let mut req = ureq::post(&TOKEN_URL) - .query("redirect_uri", &REDIRECT_URL) - .query("client_id", &CONFIG.gitlab_id) - .query("client_secret", &CONFIG.gitlab_secret); - if token { - req = req.query("refresh_token", &code_or_token).query("grant_type", "refresh_token"); - } else { - req = req.query("code", &code_or_token).query("grant_type", "authorization_code"); - } - req.call().ok()?.into_json().ok() + let grant_type = match token { + true => "refresh_token", + false => "authorization_code" + }; + let code_name = match token { + true => "refresh_token", + false => "code" + }; + ureq::post(&TOKEN_URL) + .send_json(ureq::json! ({ + "grant_type": grant_type, + "client_id": &CONFIG.gitlab_id, + "client_secret": &CONFIG.gitlab_secret, + "redirect_uri": *REDIRECT_URL, + code_name: code_or_token + })).ok()?.into_json().ok() } pub fn get_gitlab_user(span: &Span, token: String) -> Option { diff --git a/frontend/src/views/AdminView.vue b/frontend/src/views/AdminView.vue index 75f612a..0f891c3 100644 --- a/frontend/src/views/AdminView.vue +++ b/frontend/src/views/AdminView.vue @@ -102,7 +102,7 @@ const columns: DataTableColumn[] = [ title: 'Type', key: 'gitlab', render(user) { - return user.gitlab ? 'Gitlab' : 'Password'; + return user.gitlab ? 'Gitea' : 'Password'; } }, { diff --git a/frontend/src/views/LoginView.vue b/frontend/src/views/LoginView.vue index 970a05b..a2ba416 100644 --- a/frontend/src/views/LoginView.vue +++ b/frontend/src/views/LoginView.vue @@ -3,17 +3,7 @@ import type { TokenInjectType } from '@/api'; import { ref, inject } from 'vue'; import { Auth, FS, isErrorResponse } from '@/api'; import { useRouter } from 'vue-router'; -import { - useMessage, - NInput, - NGrid, - NGi, - NButton, - NIcon, - NH4, - NCard -} from 'naive-ui'; -import { LogoGitlab } from '@vicons/ionicons5'; +import { useMessage, NInput, NGrid, NGi, NButton, NH4, NCard } from 'naive-ui'; import { loadingMsgWrapper } from '@/utils'; const router = useRouter(); @@ -105,14 +95,11 @@ function onKey(event: KeyboardEvent) { - - Login with gitlab + Login with gitea