UNPKG

@gohcltech/bitbucket-mcp

Version:

Bitbucket integration for Claude via Model Context Protocol

137 lines 5.15 kB
/** * @fileoverview Authentication service for token-based Bitbucket API authentication. * * This module provides a simple, stateless authentication service that supports * two methods of authentication: * 1. API Token Authentication (HTTP Basic Auth with username + token) * 2. Repository Token Authentication (Bearer token) * * Unlike the v1.0 OAuth service, this implementation: * - Does not require token refresh (tokens don't expire) * - Uses simple HTTP Basic Auth or Bearer token authentication * - No persistent web server or callback handling needed * - Stateless and efficient */ import { AuthConfig, AuthMethod } from './types.js'; import { AuthCapabilities } from './auth-capabilities.js'; /** * Authentication header interface for API requests. * Contains the header name and value needed for authentication. */ export interface AuthHeader { /** Header name (e.g., 'Authorization') */ name: 'Authorization'; /** Header value (e.g., 'Basic ...' or 'Bearer ...') */ value: string; } /** * Simple, stateless authentication service for token-based Bitbucket API access. * * Supports dual authentication methods without needing token refresh or persistent storage. * All methods are pure functions that generate auth headers from the configured credentials. * * @example * ```typescript * const authConfig = ConfigManager.getInstance().getAuthConfig(); * const authService = new AuthService(authConfig); * const authHeader = authService.getAuthHeader(); * // Use authHeader in API requests: headers[authHeader.name] = authHeader.value * ``` */ export declare class AuthService { private config; private capabilities; /** * Creates a new AuthService instance. * * @param config - Authentication configuration (from ConfigManager) * @throws {Error} If configuration is invalid */ constructor(config: AuthConfig); /** * Gets the authentication header for API requests. * * Returns the appropriate header based on the configured authentication method: * - API Token: Returns HTTP Basic Auth header (username:token in base64) * - Repository Token: Returns Bearer token header * * @returns Authorization header object with name and value * @throws {Error} If authentication method is not properly configured */ getAuthHeader(): AuthHeader; /** * Gets HTTP Basic Auth header for API Token authentication. * * API Token authentication uses HTTP Basic Auth with username and API token. * The format is: Authorization: Basic base64(username:apiToken) * * @private * @returns Authorization header with Basic auth value * @throws {Error} If API token credentials are missing */ private getBasicAuthHeader; /** * Gets Bearer token header for Repository Token authentication. * * Repository Token authentication uses Bearer token authentication. * The format is: Authorization: Bearer <repositoryToken> * * @private * @returns Authorization header with Bearer token value * @throws {Error} If repository token is missing */ private getBearerAuthHeader; /** * Gets the current authentication method being used. * * @returns The configured authentication method (API_TOKEN or REPOSITORY_TOKEN) */ getAuthMethod(): AuthMethod; /** * Gets the configured workspace (if any). * * The workspace is an optional configuration that can be used as a default * workspace for API requests when not otherwise specified. * * @returns The configured workspace name, or undefined if not set */ getWorkspace(): string | undefined; /** * Gets a human-readable description of the current authentication configuration. * * Useful for logging and debugging without exposing sensitive credentials. * Credentials are masked in the output. * * @returns Description of authentication configuration (credentials redacted) */ getAuthDescription(): string; /** * Validates that the authentication configuration is properly set up. * * This is a basic validation to ensure required fields are present. * More thorough validation (actual token validity) should be done by TokenValidator. * * @returns Object with isValid flag and error messages (if any) */ validate(): { isValid: boolean; errors: string[]; }; /** * Gets the authentication capabilities for this service. * * Capabilities determine which tools and features are available based on * the authentication method and its associated permissions. * * @returns AuthCapabilities instance with available capabilities and tool access */ getCapabilities(): AuthCapabilities; } /** * Convenience function to create an AuthService from configuration. * * @param config - Authentication configuration * @returns Initialized AuthService instance */ export declare function createAuthService(config: AuthConfig): AuthService; //# sourceMappingURL=auth-service.d.ts.map