Ported from gitlab to gitea
This commit is contained in:
parent
c687058a06
commit
2ea430817f
@ -24,22 +24,28 @@ pub struct GitlabUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub static REDIRECT_URL: Lazy<String> = Lazy::new(|| CONFIG.gitlab_redirect_url.clone() + "/api/auth/gitlab_callback");
|
pub static REDIRECT_URL: Lazy<String> = Lazy::new(|| CONFIG.gitlab_redirect_url.clone() + "/api/auth/gitlab_callback");
|
||||||
pub static TOKEN_URL: Lazy<String> = Lazy::new(|| format!("{}/oauth/token", CONFIG.gitlab_api_url.clone()));
|
pub static TOKEN_URL: Lazy<String> = Lazy::new(|| format!("{}/login/oauth/access_token", CONFIG.gitlab_api_url.clone()));
|
||||||
pub static USER_URL: Lazy<String> = Lazy::new(|| format!("{}/api/v4/user", CONFIG.gitlab_api_url.clone()));
|
pub static USER_URL: Lazy<String> = Lazy::new(|| format!("{}/api/v1/user", CONFIG.gitlab_api_url.clone()));
|
||||||
pub static AUTHORIZE_URL: Lazy<String> = Lazy::new(|| format!("{}/oauth/authorize", CONFIG.gitlab_url.clone()));
|
pub static AUTHORIZE_URL: Lazy<String> = Lazy::new(|| format!("{}/login/oauth/authorize", CONFIG.gitlab_url.clone()));
|
||||||
|
|
||||||
pub fn get_gitlab_token(span: &Span, code_or_token: String, token: bool) -> Option<GitlabTokens> {
|
pub fn get_gitlab_token(span: &Span, code_or_token: String, token: bool) -> Option<GitlabTokens> {
|
||||||
let _span = metrics::span("get_gitlab_token", span);
|
let _span = metrics::span("get_gitlab_token", span);
|
||||||
let mut req = ureq::post(&TOKEN_URL)
|
let grant_type = match token {
|
||||||
.query("redirect_uri", &REDIRECT_URL)
|
true => "refresh_token",
|
||||||
.query("client_id", &CONFIG.gitlab_id)
|
false => "authorization_code"
|
||||||
.query("client_secret", &CONFIG.gitlab_secret);
|
};
|
||||||
if token {
|
let code_name = match token {
|
||||||
req = req.query("refresh_token", &code_or_token).query("grant_type", "refresh_token");
|
true => "refresh_token",
|
||||||
} else {
|
false => "code"
|
||||||
req = req.query("code", &code_or_token).query("grant_type", "authorization_code");
|
};
|
||||||
}
|
ureq::post(&TOKEN_URL)
|
||||||
req.call().ok()?.into_json().ok()
|
.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<GitlabUser> {
|
pub fn get_gitlab_user(span: &Span, token: String) -> Option<GitlabUser> {
|
||||||
|
@ -102,7 +102,7 @@ const columns: DataTableColumn<Responses.GetUsersEntry>[] = [
|
|||||||
title: 'Type',
|
title: 'Type',
|
||||||
key: 'gitlab',
|
key: 'gitlab',
|
||||||
render(user) {
|
render(user) {
|
||||||
return user.gitlab ? 'Gitlab' : 'Password';
|
return user.gitlab ? 'Gitea' : 'Password';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -3,17 +3,7 @@ import type { TokenInjectType } from '@/api';
|
|||||||
import { ref, inject } from 'vue';
|
import { ref, inject } from 'vue';
|
||||||
import { Auth, FS, isErrorResponse } from '@/api';
|
import { Auth, FS, isErrorResponse } from '@/api';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import {
|
import { useMessage, NInput, NGrid, NGi, NButton, NH4, NCard } from 'naive-ui';
|
||||||
useMessage,
|
|
||||||
NInput,
|
|
||||||
NGrid,
|
|
||||||
NGi,
|
|
||||||
NButton,
|
|
||||||
NIcon,
|
|
||||||
NH4,
|
|
||||||
NCard
|
|
||||||
} from 'naive-ui';
|
|
||||||
import { LogoGitlab } from '@vicons/ionicons5';
|
|
||||||
import { loadingMsgWrapper } from '@/utils';
|
import { loadingMsgWrapper } from '@/utils';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -105,14 +95,11 @@ function onKey(event: KeyboardEvent) {
|
|||||||
<n-gi style="text-align: right">
|
<n-gi style="text-align: right">
|
||||||
<n-button
|
<n-button
|
||||||
ghost
|
ghost
|
||||||
color="#fc6d27"
|
color="#16ab39"
|
||||||
text-color="#000"
|
text-color="#000"
|
||||||
@click="loginGitlab"
|
@click="loginGitlab"
|
||||||
>
|
>
|
||||||
<template #icon>
|
Login with gitea
|
||||||
<n-icon color="#fc6d27"><LogoGitlab /></n-icon>
|
|
||||||
</template>
|
|
||||||
Login with gitlab
|
|
||||||
</n-button>
|
</n-button>
|
||||||
</n-gi>
|
</n-gi>
|
||||||
<n-gi>
|
<n-gi>
|
||||||
|
Loading…
Reference in New Issue
Block a user