✨ feat(oauth): Add certification component for handling OAuth login callbacks and improve user authentication flow
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
|
||||
// API 更新时间:
|
||||
// API 唯一标识:
|
||||
import * as auth from './auth';
|
||||
import * as common from './common';
|
||||
import * as oauth from './oauth';
|
||||
export default {
|
||||
auth,
|
||||
oauth,
|
||||
common,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
import request from '@/utils/request';
|
||||
|
||||
/** Apple Login Callback POST /v1/auth/oauth/callback/apple */
|
||||
export async function appleLoginCallback(
|
||||
body: {
|
||||
code: string;
|
||||
id_token: string;
|
||||
state: string;
|
||||
},
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
const formData = new FormData();
|
||||
|
||||
Object.keys(body).forEach((ele) => {
|
||||
const item = (body as any)[ele];
|
||||
|
||||
if (item !== undefined && item !== null) {
|
||||
if (typeof item === 'object' && !(item instanceof File)) {
|
||||
if (item instanceof Array) {
|
||||
item.forEach((f) => formData.append(ele, f || ''));
|
||||
} else {
|
||||
formData.append(ele, JSON.stringify(item));
|
||||
}
|
||||
} else {
|
||||
formData.append(ele, item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return request<API.Response & { data?: any }>('/v1/auth/oauth/callback/apple', {
|
||||
method: 'POST',
|
||||
data: formData,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Facebook Login Callback GET /v1/auth/oauth/callback/facebook */
|
||||
export async function facebookLoginCallback(options?: { [key: string]: any }) {
|
||||
return request<API.Response & { data?: any }>('/v1/auth/oauth/callback/facebook', {
|
||||
method: 'GET',
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Google Login Callback GET /v1/auth/oauth/callback/google */
|
||||
export async function googleLoginCallback(
|
||||
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
||||
params: API.GoogleLoginCallbackParams,
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
return request<API.Response & { data?: any }>('/v1/auth/oauth/callback/google', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Telegram Login Callback GET /v1/auth/oauth/callback/telegram */
|
||||
export async function telegramLoginCallback(options?: { [key: string]: any }) {
|
||||
return request<API.Response & { data?: any }>('/v1/auth/oauth/callback/telegram', {
|
||||
method: 'GET',
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** OAuth login POST /v1/auth/oauth/login */
|
||||
export async function oAuthLogin(body: API.OAthLoginRequest, options?: { [key: string]: any }) {
|
||||
return request<API.Response & { data?: API.OAuthLoginResponse }>('/v1/auth/oauth/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
+40
@@ -10,6 +10,12 @@ declare namespace API {
|
||||
updated_at: number;
|
||||
};
|
||||
|
||||
type AppleLoginCallbackRequest = {
|
||||
code: string;
|
||||
id_token: string;
|
||||
state: string;
|
||||
};
|
||||
|
||||
type Application = {
|
||||
id: number;
|
||||
icon: string;
|
||||
@@ -19,6 +25,9 @@ declare namespace API {
|
||||
};
|
||||
|
||||
type ApplicationConfig = {
|
||||
app_id: number;
|
||||
encryption_key: string;
|
||||
encryption_method: string;
|
||||
domains: string[];
|
||||
startup_picture: string;
|
||||
startup_picture_skip_time: number;
|
||||
@@ -152,6 +161,7 @@ declare namespace API {
|
||||
invite: InviteConfig;
|
||||
currency: CurrencyConfig;
|
||||
subscribe: SubscribeConfig;
|
||||
oauth_methods: string[];
|
||||
};
|
||||
|
||||
type GetStatResponse = {
|
||||
@@ -169,6 +179,16 @@ declare namespace API {
|
||||
tos_content: string;
|
||||
};
|
||||
|
||||
type GoogleLoginCallbackParams = {
|
||||
code: string;
|
||||
state: string;
|
||||
};
|
||||
|
||||
type GoogleLoginCallbackRequest = {
|
||||
code: string;
|
||||
state: string;
|
||||
};
|
||||
|
||||
type Hysteria2 = {
|
||||
port: number;
|
||||
hop_ports: string;
|
||||
@@ -205,6 +225,26 @@ declare namespace API {
|
||||
last_at: number;
|
||||
};
|
||||
|
||||
type OAthLoginRequest = {
|
||||
/** google, facebook, apple, telegram, github etc. */
|
||||
method: string;
|
||||
redirect: string;
|
||||
};
|
||||
|
||||
type OAuthLoginResponse = {
|
||||
redirect: string;
|
||||
};
|
||||
|
||||
type OAuthMethod = {
|
||||
id: number;
|
||||
platform: string;
|
||||
config: Record<string, any>;
|
||||
redirect: string;
|
||||
enabled: boolean;
|
||||
created_at: number;
|
||||
updated_at: number;
|
||||
};
|
||||
|
||||
type OnlineUser = {
|
||||
uid: number;
|
||||
ip: string;
|
||||
|
||||
Reference in New Issue
Block a user