Authentication overview
Hirak OCR secures access to its API services primarily through API key authentication. This mechanism allows developers to identify their applications and control access to the various OCR and document processing functionalities Hirak OCR offers, such as the Hirak OCR API reference. When an authenticated request is made, the provided API key is validated against Hirak OCR's systems to ensure the requesting entity has the necessary permissions to perform the requested operation.
API keys serve as a token that authenticates the calling application, not an individual user. They are foundational for tracking API usage, enforcing rate limits, and securing data processing operations. For applications integrating with Hirak OCR, understanding the proper handling and security of these keys is essential for maintaining the integrity and confidentiality of processed documents.
All communication with the Hirak OCR API endpoints is expected to occur over HTTPS (TLS-encrypted connections). This ensures that API keys and any sensitive document data transmitted during OCR processing are encrypted in transit, protecting against eavesdropping and tampering. The use of HTTPS is a standard security practice for web APIs, as detailed in web security guidelines like those from the Mozilla Developer Network's secure contexts documentation.
Supported authentication methods
Hirak OCR exclusively supports API key authentication for accessing its services. This method is straightforward to implement and manage, making it suitable for a wide range of integration scenarios, from backend services to client-side applications that securely proxy requests.
The API key acts as a secret token that clients include with their API requests. Hirak OCR's system then verifies this key to grant or deny access. While other authentication methods like OAuth 2.0 might be used for user-centric authorization, API keys are preferred for service-to-service authentication where an application needs direct access to its own resources and capabilities within the Hirak OCR platform.
The following table outlines the key aspects of Hirak OCR's authentication method:
| Method | When to Use | Security Level |
|---|---|---|
| API Key | Direct application access to Hirak OCR services; server-to-server communication; when simplicity and direct access control are priorities. | Moderate (when handled securely, comparable to a password; requires careful management to prevent exposure). |
Getting your credentials
To begin using Hirak OCR, you must first obtain an API key from your Hirak OCR account dashboard. This key serves as your unique credential for authenticating all API requests.
- Sign Up/Log In: Navigate to the Hirak OCR homepage and either sign up for a new account or log in to an existing one. Hirak OCR offers a free tier that includes 500 pages per month, allowing you to generate and test your API key without immediate cost.
- Access Dashboard: Once logged in, locate your account dashboard. The exact navigation may vary, but typically there will be a section labeled "API Keys," "Developer Settings," or similar.
- Generate API Key: Within the API Keys section, you will find an option to generate a new API key. It is recommended to create separate API keys for different applications or environments (e.g., development, staging, production) to facilitate easier key rotation and revocation if a key is compromised.
- Store Your Key Securely: After generation, your API key will be displayed. Copy this key immediately and store it in a secure location. For security reasons, Hirak OCR often displays the key only once upon generation and may not allow you to retrieve it again. If lost, you would typically need to generate a new key and invalidate the old one.
For detailed, step-by-step instructions on generating and managing your API keys, refer to the official Hirak OCR documentation.
Authenticated request example
Once you have your API key, you can include it in your API requests. For Hirak OCR, the API key is typically passed in the Authorization header of your HTTP request, using the Bearer scheme. This is a common and recommended practice for API key transmission, providing a clear separation from other request parameters.
Here's an example of how to make an authenticated request using cURL, a common command-line tool for making HTTP requests:
curl -X POST \ https://api.hirak-ocr.com/v1/process \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "document_url": "https://example.com/invoice.pdf", "output_format": "json" }'
In this example:
YOUR_API_KEYshould be replaced with the actual API key you obtained from your Hirak OCR dashboard.- The
-H "Authorization: Bearer YOUR_API_KEY"header is crucial for authentication. - The
-H "Content-Type: application/json"header specifies the format of the request body. - The
-dflag provides the JSON request body, which might contain parameters like the document URL and desired output format.
Hirak OCR also provides SDKs for Python, Node.js, and Java, which abstract away the HTTP request details and simplify authentication. For instance, in Python, an authenticated request might look like this:
import os
from hirak_ocr import HirakOCRClient
api_key = os.environ.get("HIRAK_OCR_API_KEY")
client = HirakOCRClient(api_key=api_key)
try:
result = client.process_document(
document_url="https://example.com/receipt.jpg",
output_format="json"
)
print(result)
except Exception as e:
print(f"Error processing document: {e}")
In this Python example, the API key is passed directly to the HirakOCRClient constructor, and the SDK handles the construction of the authenticated HTTP request.
Security best practices
Securing your Hirak OCR API keys is paramount to protect your account from unauthorized access and potential misuse. Adhering to these best practices will help maintain the security of your integrations:
- Treat API Keys as Sensitive Secrets: Consider your API keys as critical as passwords. Do not hardcode them directly into your application's source code, especially for client-side applications or publicly accessible repositories.
- Use Environment Variables or Secret Management Services: For server-side applications, store API keys in environment variables. For more complex deployments or microservice architectures, consider using dedicated secret management services like AWS Secrets Manager, Google Secret Manager, or Azure Key Vault. This centralizes credential management and reduces the risk of accidental exposure.
- Restrict Access to API Keys: Limit who has access to your API keys within your organization. Implement role-based access control (RBAC) to ensure only authorized personnel can view or manage these credentials.
- Avoid Exposure in Public Repositories: Never commit API keys to version control systems like Git, even in private repositories. Use
.gitignorefiles to exclude configuration files containing API keys. - Transmit Securely (HTTPS/TLS): Always ensure that all API requests to Hirak OCR are made over HTTPS. This encrypts the communication channel, protecting your API key and data from interception during transit. Hirak OCR mandates HTTPS for all API interactions.
- Implement Key Rotation: Regularly rotate your API keys. This practice minimizes the window of opportunity for a compromised key to be exploited. Hirak OCR's dashboard should provide functionality to generate new keys and revoke old ones.
- Revoke Compromised Keys Immediately: If you suspect an API key has been compromised, revoke it immediately through your Hirak OCR dashboard. Generate a new key and update all applications using the compromised key.
- Apply Principle of Least Privilege: If Hirak OCR offers different types of API keys or scopes, use keys with the minimum necessary permissions required for a specific task. This limits the damage if a key is compromised.
- Monitor API Usage: Regularly review your API usage logs in the Hirak OCR dashboard. Unusual spikes or patterns in usage could indicate unauthorized activity or a compromised key.
- Client-Side Considerations: If your application involves client-side code interacting with Hirak OCR, ensure that API calls are proxied through your secure backend. Exposing API keys directly in client-side code (e.g., JavaScript in a browser) makes them easily discoverable and exploitable. Your backend can then add the API key before forwarding the request to Hirak OCR.
By diligently following these security practices, you can significantly enhance the protection of your Hirak OCR integration and ensure the secure processing of your documents.