UNPKG

@gohcltech/bitbucket-mcp

Version:

Bitbucket integration for Claude via Model Context Protocol

120 lines 4.29 kB
/** * @fileoverview Token validation service for Bitbucket API authentication. * * This module provides token validation by testing authentication credentials * against the Bitbucket API. It validates that tokens are properly formatted * and actually have access to the Bitbucket API. */ import { AuthService } from './auth-service.js'; /** * Token validation result interface. * Contains information about whether a token is valid and any error details. */ export interface TokenValidationResult { /** Whether the token is valid and has API access */ isValid: boolean; /** Optional error message if validation failed */ errorMessage?: string; /** Optional error code (e.g., 401, 403) */ errorCode?: number; /** Optional error details for debugging */ details?: any; } /** * Token validator service that tests authentication credentials against Bitbucket API. * * Validates tokens by making a simple GET request to Bitbucket API endpoints: * - For API Token: Uses /user endpoint to validate user account access * - For Repository Token: Uses /workspaces/{workspace} endpoint * * This ensures tokens: * - Are properly formatted * - Have valid credentials * - Have appropriate permissions * - Are not expired or revoked * * @example * ```typescript * const authService = new AuthService(authConfig); * const validator = new TokenValidator(authService); * const result = await validator.validateToken(); * if (result.isValid) { * console.log('Token is valid and authenticated'); * } else { * console.error('Token validation failed:', result.errorMessage); * } * ``` */ export declare class TokenValidator { private authService; private apiBaseUrl; /** * Creates a new TokenValidator instance. * * @param authService - AuthService instance with configured credentials */ constructor(authService: AuthService); /** * Validates the configured authentication token. * * Makes a test request to the Bitbucket API to verify: * - Token format is correct * - Credentials are valid * - Token has not expired or been revoked * - User/repository has appropriate permissions * * @returns Validation result with isValid flag and any error details */ validateToken(): Promise<TokenValidationResult>; /** * Gets the appropriate Bitbucket API endpoint for token validation. * * For API Token: Uses /user endpoint to validate user account * For Repository Token: Uses /workspaces/{workspace} endpoint (repository-scoped tokens * don't have access to /user endpoint, so we validate against workspace level) * * @private * @returns API endpoint path for validation */ private getValidationEndpoint; /** * Handles validation errors and extracts meaningful error information. * * Maps HTTP status codes to user-friendly error messages: * - 401: Invalid credentials (bad token or wrong format) * - 403: Forbidden (token valid but lacks permissions) * - 404: Not found (workspace may not exist) * - 5xx: Server error * * @private * @param error - Error from axios request * @returns Validation result with error details */ private handleValidationError; /** * Validates token format without making API requests. * * Performs basic format validation: * - API Token: Checks that it starts with ATBBT * - Repository Token: Checks that it's not empty * * @returns Validation result (only basic format checks, not API access) */ validateFormat(): TokenValidationResult; /** * Gets a description of what will be validated. * * Useful for logging what validation checks are being performed. * * @returns Description of validation being performed */ getValidationDescription(): string; } /** * Convenience function to create and validate a token in one operation. * * @param authService - AuthService instance with configured credentials * @returns Validation result from token validation */ export declare function validateAuthenticationToken(authService: AuthService): Promise<TokenValidationResult>; //# sourceMappingURL=token-validator.d.ts.map