mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
refactor(schema): simplify validation and OpenAPI generation (#2709)
This commit is contained in:
1 parent
4bc5593f9f
commit
de1fd95a99
510 files changed
+29494
-36131
No files matched your search
@@ -23,7 +23,6 @@ import {
|
||||
RevokeRequestForm,
|
||||
TokenRequest,
|
||||
} from '@fluxer/schema/src/domains/oauth/OAuthSchemas';
|
||||
import type {z} from 'zod';
|
||||
import {Config} from '../Config';
|
||||
import {DefaultUserOnly, LoginRequiredAllowSuspicious} from '../middleware/AuthMiddleware';
|
||||
import {requireOAuth2BearerToken, requireOAuth2Scope} from '../middleware/OAuth2ScopeMiddleware';
|
||||
@@ -119,7 +118,7 @@ export function OAuth2Controller(app: HonoApp) {
|
||||
'User grants permission for an OAuth2 application to access authorized scopes. Used in authorization code flow to complete the authorization process after user review.',
|
||||
}),
|
||||
async (ctx) => {
|
||||
const body: z.infer<typeof AuthorizeConsentRequest> = ctx.req.valid('json');
|
||||
const body: AuthorizeConsentRequest = ctx.req.valid('json');
|
||||
const user = ctx.get('user');
|
||||
return ctx.json(
|
||||
await ctx.get('oauth2RequestService').authorizeConsent({
|
||||
@@ -263,13 +262,13 @@ export function OAuth2Controller(app: HonoApp) {
|
||||
RateLimitMiddleware(RateLimitConfigs.OAUTH_DEV_CLIENTS_LIST),
|
||||
OpenAPI({
|
||||
operationId: 'get_current_user_applications',
|
||||
summary: 'List current user applications',
|
||||
summary: 'Get current bot application',
|
||||
responseSchema: ApplicationsMeResponse,
|
||||
statusCode: 200,
|
||||
security: [],
|
||||
security: ['botToken'],
|
||||
tags: ['OAuth2'],
|
||||
description:
|
||||
'Lists all OAuth2 applications registered by the authenticated user. Includes application credentials and metadata. Requires valid OAuth2 access token.',
|
||||
'Retrieves the application associated with the authenticated bot, including its owner and bot profile. Requires a valid bot token.',
|
||||
}),
|
||||
async (ctx) => {
|
||||
const response = await ctx
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {type UserAuthenticatorType, UserAuthenticatorTypes} from '@fluxer/constants/src/UserConstants';
|
||||
import type {
|
||||
ApplicationBotResponse,
|
||||
ApplicationResponse,
|
||||
BotProfileResponse,
|
||||
BotTokenResetResponse,
|
||||
} from '@fluxer/schema/src/domains/oauth/OAuthSchemas';
|
||||
import {stripBannerForUser} from '../infrastructure/AssetEntitlementUtils';
|
||||
import type {Application} from '../models/Application';
|
||||
import type {User} from '../models/User';
|
||||
import {mapUserToPartialResponse} from '../user/UserMappers';
|
||||
import type {ApplicationBotResponse, ApplicationResponse} from './OAuth2Types';
|
||||
|
||||
function getActiveAuthenticatorTypes(user: User): Array<UserAuthenticatorType> {
|
||||
return Array.from(user.authenticatorTypes ?? []).filter(
|
||||
@@ -63,14 +68,14 @@ export function mapApplicationToResponse(
|
||||
return baseResponse;
|
||||
}
|
||||
|
||||
export function mapBotTokenResetResponse(user: User, token: string) {
|
||||
export function mapBotTokenResetResponse(user: User, token: string): BotTokenResetResponse {
|
||||
return {
|
||||
token,
|
||||
bot: mapBotUserToResponse(user),
|
||||
};
|
||||
}
|
||||
|
||||
export function mapBotProfileToResponse(user: User) {
|
||||
export function mapBotProfileToResponse(user: User): BotProfileResponse {
|
||||
const partial = mapUserToPartialResponse(user);
|
||||
return {
|
||||
id: partial.id,
|
||||
|
||||
@@ -33,7 +33,6 @@ import type {
|
||||
TokenRequest,
|
||||
} from '@fluxer/schema/src/domains/oauth/OAuthSchemas';
|
||||
import type {Context} from 'hono';
|
||||
import type {z} from 'zod';
|
||||
import type {ApiContext} from '../ApiContext';
|
||||
import type {SudoVerificationBody} from '../auth/services/SudoVerificationService';
|
||||
import {requireSudoMode} from '../auth/services/SudoVerificationService';
|
||||
@@ -74,7 +73,7 @@ export class OAuth2RequestService {
|
||||
) {}
|
||||
|
||||
async tokenExchange(params: {
|
||||
form: z.infer<typeof TokenRequest>;
|
||||
form: TokenRequest;
|
||||
authorizationHeader?: string;
|
||||
logPrefix: string;
|
||||
}): Promise<OAuth2TokenResponse> {
|
||||
@@ -149,7 +148,7 @@ export class OAuth2RequestService {
|
||||
};
|
||||
}
|
||||
|
||||
async revoke(params: {form: z.infer<typeof RevokeRequestForm>; authorizationHeader?: string}): Promise<void> {
|
||||
async revoke(params: {form: RevokeRequestForm; authorizationHeader?: string}): Promise<void> {
|
||||
const {clientId: clientIdStr, clientSecret: secret} = parseClientCredentials(
|
||||
params.authorizationHeader,
|
||||
params.form.client_id,
|
||||
@@ -165,7 +164,7 @@ export class OAuth2RequestService {
|
||||
}
|
||||
|
||||
async introspect(params: {
|
||||
form: z.infer<typeof IntrospectRequestForm>;
|
||||
form: IntrospectRequestForm;
|
||||
authorizationHeader?: string;
|
||||
}): Promise<OAuth2IntrospectResponse> {
|
||||
const {clientId: clientIdStr, clientSecret: secret} = parseClientCredentials(
|
||||
@@ -194,7 +193,7 @@ export class OAuth2RequestService {
|
||||
}
|
||||
|
||||
async authorizeConsent(params: {
|
||||
body: z.infer<typeof AuthorizeConsentRequest>;
|
||||
body: AuthorizeConsentRequest;
|
||||
userId: UserID;
|
||||
requestCache: RequestCache;
|
||||
}): Promise<OAuth2ConsentResponse> {
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import type {UserAuthenticatorType} from '@fluxer/constants/src/UserConstants';
|
||||
|
||||
export interface ApplicationBotResponse {
|
||||
id: string;
|
||||
username: string;
|
||||
discriminator: string;
|
||||
avatar?: string | null;
|
||||
banner?: string | null;
|
||||
bio: string | null;
|
||||
token?: string;
|
||||
mfa_enabled?: boolean;
|
||||
authenticator_types?: Array<UserAuthenticatorType>;
|
||||
flags: number;
|
||||
}
|
||||
|
||||
export interface ApplicationResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
redirect_uris: Array<string>;
|
||||
bot_public: boolean;
|
||||
bot_require_code_grant: boolean;
|
||||
client_secret?: string;
|
||||
bot?: ApplicationBotResponse;
|
||||
}
|
||||
Reference in new issue
Block a user