n8n
Version:
n8n Workflow Automation Tool
39 lines (38 loc) • 1.9 kB
TypeScript
import type { CreateApiKeyRequestDto, UpdateApiKeyRequestDto } from '@n8n/api-types';
import type { User } from '@n8n/db';
import { ApiKey, ApiKeyRepository } from '@n8n/db';
import type { ApiKeyScope, AuthPrincipal } from '@n8n/permissions';
import type { EntityManager } from '@n8n/typeorm';
import { JwtService } from './jwt.service';
export declare const API_KEY_AUDIENCE = "public-api";
export declare const API_KEY_ISSUER = "n8n";
export declare const PREFIX_LEGACY_API_KEY = "n8n_api_";
export declare class PublicApiKeyService {
private readonly apiKeyRepository;
private readonly jwtService;
constructor(apiKeyRepository: ApiKeyRepository, jwtService: JwtService);
createPublicApiKeyForUser(user: User, { label, expiresAt, scopes }: CreateApiKeyRequestDto): Promise<ApiKey>;
getRedactedApiKeysForUser(user: User): Promise<{
apiKey: string;
expiresAt: number | null;
user: User;
userId: string;
label: string;
scopes: ApiKeyScope[];
audience: import("n8n-workflow").ApiKeyAudience;
id: string;
generateId(): void;
createdAt: Date;
updatedAt: Date;
setUpdateDate(): void;
}[]>;
deleteApiKeyForUser(user: User, apiKeyId: string): Promise<void>;
deleteAllApiKeysForUser(user: User, tx?: EntityManager): Promise<import("@n8n/typeorm").DeleteResult[]>;
updateApiKeyForUser(user: User, apiKeyId: string, { label, scopes }: UpdateApiKeyRequestDto): Promise<void>;
redactApiKey(apiKey: string): string;
private generateApiKey;
private getApiKeyExpiration;
apiKeyHasValidScopesForRole(role: AuthPrincipal, apiKeyScopes: ApiKeyScope[]): boolean;
apiKeyHasValidScopes(apiKey: string, endpointScope: ApiKeyScope): Promise<boolean>;
removeOwnerOnlyScopesFromApiKeys(user: User, tx?: EntityManager): Promise<import("@n8n/typeorm").UpdateResult[]>;
}