Skip to main content
Glama

OpenAPI Lambda MCP Server

by ingeno
zoho_auth.py3.94 kB
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Zoho OAuth authentication provider.""" from awslabs.openapi_mcp_server import logger from awslabs.openapi_mcp_server.api.config import Config from awslabs.openapi_mcp_server.auth.auth_cache import cached_auth_data from awslabs.openapi_mcp_server.auth.auth_errors import MissingCredentialsError from awslabs.openapi_mcp_server.auth.base_auth import BaseAuthProvider from typing import Dict class ZohoAuthProvider(BaseAuthProvider): """Zoho OAuth authentication provider. This provider adds an Authorization header with Zoho's custom OAuth format (Zoho-oauthtoken) to all HTTP requests. Zoho CRM uses OAuth 2.0 with a custom authorization header format: Authorization: Zoho-oauthtoken {access_token} For production use, you should provide a refresh token and implement automatic token refresh using Zoho's OAuth token endpoint. """ def __init__(self, config: Config): """Initialize with configuration. Args: config: Application configuration """ self._token = config.auth_token self._token_ttl = getattr(config, 'auth_token_ttl', 3600) super().__init__(config) def _validate_config(self) -> bool: """Validate the configuration. Returns: bool: True if token is provided, False otherwise Raises: MissingCredentialsError: If token is missing """ if not self._token: raise MissingCredentialsError( 'Zoho authentication requires a valid OAuth token', { 'help': 'Provide an OAuth access token or refresh token using --auth-token or AUTH_TOKEN environment variable', 'documentation': 'https://www.zoho.com/crm/developer/docs/api/v8/access-refresh.html' }, ) return True def _log_validation_error(self) -> None: """Log validation error messages.""" logger.error( 'Zoho authentication requires a valid OAuth token. ' 'When using Zoho authentication, an access token or refresh token must be provided.' ) logger.error( 'Please provide a token using --auth-token command line argument or AUTH_TOKEN environment variable.' ) def _initialize_auth(self) -> None: """Initialize authentication data after validation.""" self._auth_headers = self._generate_auth_headers(self._token) @cached_auth_data(ttl=3600) def _generate_auth_headers(self, token: str) -> Dict[str, str]: """Generate authentication headers. This method is cached to avoid regenerating headers for the same token. Args: token: Zoho OAuth token (access token or refresh token) Returns: Dict[str, str]: Authentication headers with Zoho's custom format """ logger.debug('Generating Zoho OAuth headers') token_length = len(token) if token else 0 logger.debug(f'Token length: {token_length} characters') return {'Authorization': f'Zoho-oauthtoken {token}'} @property def provider_name(self) -> str: """Get the name of the authentication provider. Returns: str: Name of the authentication provider """ return 'zoho'

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ingeno/mcp-openapi-lambda'

If you have feedback or need assistance with the MCP directory API, please join our Discord server