mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(server): add api key to openapi spec (#2362)
* feat(server): add api key to openapi spec * regenerate api
This commit is contained in:
parent
af7da9d2c9
commit
15a498fd60
19 changed files with 903 additions and 87 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { IMMICH_API_KEY_NAME } from '@app/domain';
|
||||
import { applyDecorators, SetMetadata } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiCookieAuth, ApiQuery } from '@nestjs/swagger';
|
||||
import { ApiBearerAuth, ApiCookieAuth, ApiQuery, ApiSecurity } from '@nestjs/swagger';
|
||||
|
||||
interface AuthenticatedOptions {
|
||||
admin?: boolean;
|
||||
|
|
@ -12,10 +13,13 @@ export enum Metadata {
|
|||
SHARED_ROUTE = 'shared_route',
|
||||
}
|
||||
|
||||
export const Authenticated = (options?: AuthenticatedOptions) => {
|
||||
const decorators: MethodDecorator[] = [ApiBearerAuth(), ApiCookieAuth(), SetMetadata(Metadata.AUTH_ROUTE, true)];
|
||||
|
||||
options = options || {};
|
||||
export const Authenticated = (options: AuthenticatedOptions = {}) => {
|
||||
const decorators: MethodDecorator[] = [
|
||||
ApiBearerAuth(),
|
||||
ApiCookieAuth(),
|
||||
ApiSecurity(IMMICH_API_KEY_NAME),
|
||||
SetMetadata(Metadata.AUTH_ROUTE, true),
|
||||
];
|
||||
|
||||
if (options.admin) {
|
||||
decorators.push(SetMetadata(Metadata.ADMIN_ROUTE, true));
|
||||
|
|
|
|||
|
|
@ -9,8 +9,15 @@ import { AppModule } from './app.module';
|
|||
import { RedisIoAdapter } from '@app/infra';
|
||||
import { json } from 'body-parser';
|
||||
import { patchOpenAPI } from './utils/patch-open-api.util';
|
||||
import { getLogLevels, MACHINE_LEARNING_ENABLED } from '@app/domain';
|
||||
import { SERVER_VERSION, IMMICH_ACCESS_COOKIE, SearchService } from '@app/domain';
|
||||
import {
|
||||
getLogLevels,
|
||||
MACHINE_LEARNING_ENABLED,
|
||||
SERVER_VERSION,
|
||||
IMMICH_ACCESS_COOKIE,
|
||||
SearchService,
|
||||
IMMICH_API_KEY_HEADER,
|
||||
IMMICH_API_KEY_NAME,
|
||||
} from '@app/domain';
|
||||
|
||||
const logger = new Logger('ImmichServer');
|
||||
|
||||
|
|
@ -41,6 +48,14 @@ async function bootstrap() {
|
|||
in: 'header',
|
||||
})
|
||||
.addCookieAuth(IMMICH_ACCESS_COOKIE)
|
||||
.addApiKey(
|
||||
{
|
||||
type: 'apiKey',
|
||||
in: 'header',
|
||||
name: IMMICH_API_KEY_HEADER,
|
||||
},
|
||||
IMMICH_API_KEY_NAME,
|
||||
)
|
||||
.addServer('/api')
|
||||
.build();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue