Authentication overview

Authentication for Open Government, Slovakia APIs is a foundational security measure, verifying the identity of an application or a user attempting to access resources. This process is distinct from authorization, which determines what an authenticated entity is permitted to do OAuth 2.0 specification. The Open Government, Slovakia platform supports several authentication mechanisms, each suited for different integration scenarios, ranging from server-to-server communication to user-delegated access. Proper implementation of these methods is critical for protecting government data, ensuring regulatory compliance, and maintaining the trust of citizens and developers.

The chosen authentication method dictates how credentials are obtained, managed, and presented with each API request. Developers are expected to select the most appropriate method based on the application's architecture, the type of data being accessed, and the level of user interaction involved. All authentication methods rely on secure communication channels, primarily HTTPS/TLS 1.2 or higher, to encrypt data in transit and prevent eavesdropping or tampering.

Supported authentication methods

Open Government, Slovakia APIs primarily support two robust authentication methods: API Keys and OAuth 2.0. Each method serves distinct use cases and offers varying levels of security and control.

API Keys

API Keys are simple, unique identifiers generated by the Open Government, Slovakia developer portal. They are typically used to authenticate applications rather than individual users, providing access to public or application-specific data. An API Key acts as a secret token that the application includes with every API request. This method is suitable for:

  • Server-to-server communication where user context is not required.
  • Accessing publicly available, non-sensitive data that requires application identification for rate limiting or analytics.
  • Internal services or batch processing where a single application account manages access.

While straightforward, API Keys require careful management due to their static nature. If an API Key is compromised, it must be revoked and reissued promptly.

OAuth 2.0

OAuth 2.0 is an industry-standard protocol for authorization that provides delegated access to resources. It allows an application to access a user's resources on the Open Government, Slovakia platform without ever handling the user's credentials. Instead, the application obtains an access token from the authorization server, which is then used to make requests to the resource server on behalf of the user RFC 6749, The OAuth 2.0 Authorization Framework. OAuth 2.0 is recommended for:

  • Third-party applications that need to access user-specific data (e.g., personal citizen information) with explicit user consent.
  • Applications requiring granular control over permissions (scopes).
  • Environments where user context is essential for auditing and logging.
  • Mobile and web applications where direct handling of user credentials is a security risk.

The Open Government, Slovakia platform supports the following OAuth 2.0 grant types:

  • Authorization Code Grant: The most secure and widely used flow for public and confidential clients, particularly web applications. It involves redirecting the user to the Open Government, Slovakia login page to grant consent, after which an authorization code is exchanged for an access token and refresh token.
  • Client Credentials Grant: Used for server-to-server authentication where an application authenticates itself to access its own resources, not on behalf of a user. It bypasses user interaction and provides direct access tokens based on client ID and client secret.

The following table summarizes the supported authentication methods:

Method When to Use Security Level
API Key Server-to-server, public data access, simple application identification. Moderate (requires secure key management)
OAuth 2.0 (Authorization Code Grant) User-delegated access, third-party web/mobile apps, sensitive user data. High (no credential sharing, token revocation)
OAuth 2.0 (Client Credentials Grant) Server-to-server, application-specific data, internal services. High (client secret management, no user context)

Getting your credentials

Access to Open Government, Slovakia APIs begins with registering your application and obtaining the necessary credentials through the official developer portal. The process varies slightly depending on the chosen authentication method.

For API Keys

  1. Register an Application: Navigate to the Open Government, Slovakia developer portal and register a new application. You will typically provide details such as your application name, description, and intended use.
  2. Generate API Key: Once registered, the portal will provide an option to generate an API Key. This key is usually a long, alphanumeric string.
  3. Record and Secure: Immediately record your API Key. It will be displayed only once. Treat it as a sensitive secret and store it securely, ideally in environment variables or a secrets management service, not directly in your code repository.

For OAuth 2.0

  1. Register an OAuth Application: On the Open Government, Slovakia developer portal, register your application, specifying that it will use OAuth 2.0. You will need to provide:
    • Application Name: A descriptive name for your application.
    • Redirect URIs (Callback URLs): These are the URLs to which the user will be redirected after authorizing your application. For web applications, this might be a specific endpoint on your server. For mobile apps, custom URL schemes are common. Ensure these URIs are precisely configured to prevent security vulnerabilities.
    • Scopes: Define the specific permissions your application will request from users (e.g., read:citizen_profile, write:tax_declarations).
  2. Obtain Client ID and Client Secret: Upon registration, the portal will issue a Client ID (a public identifier) and a Client Secret (a confidential key). The Client Secret must be kept strictly confidential, similar to an API Key.
  3. Configure Your Application: Integrate the Client ID, Client Secret, and Redirect URIs into your application's OAuth client configuration.

Authenticated request example

This section provides examples of how to include authentication credentials in API requests using common methods.

API Key Authentication

When using an API Key, it is typically passed in a custom HTTP header or as a query parameter. The Open Government, Slovakia APIs generally prefer the use of an Authorization header for API Keys, following the pattern X-Api-Key: YOUR_API_KEY.

GET /api/v1/public-data/registry-records HTTP/1.1
Host: api.slovensko.sk
X-Api-Key: sk_live_your_generated_api_key_here

Or, for a cURL example:

curl -X GET \
  'https://api.slovensko.sk/api/v1/public-data/registry-records' \
  -H 'X-Api-Key: sk_live_your_generated_api_key_here'

OAuth 2.0 Authentication (Authorization Code Grant)

After completing the OAuth 2.0 authorization flow and obtaining an access token, it must be included in the Authorization header of subsequent API requests using the Bearer scheme.

GET /api/v1/user-data/my-profile HTTP/1.1
Host: api.slovensko.sk
Authorization: Bearer your_oauth2_access_token_here

cURL example:

curl -X GET \
  'https://api.slovensko.sk/api/v1/user-data/my-profile' \
  -H 'Authorization: Bearer your_oauth2_access_token_here'

The access token is typically short-lived. When it expires, your application will need to use the refresh token (if obtained during the initial authorization) to request a new access token without requiring the user to re-authorize Google's OAuth 2.0 refresh token guide.

Security best practices

Adhering to security best practices is paramount for developers integrating with Open Government, Slovakia APIs to protect sensitive data and maintain the integrity of government services.

Protect Your Credentials

  • Never hardcode secrets: API Keys, Client Secrets, and refresh tokens should never be directly embedded in your application's source code, especially in publicly accessible repositories.
  • Use environment variables: Store credentials in environment variables for server-side applications.
  • Secrets management services: For more complex or microservices architectures, consider using dedicated secrets management services (e.g., AWS Secrets Manager, Azure Key Vault, Google Secret Manager) to securely store and retrieve credentials.
  • Client-side applications: For browser-based or mobile applications, avoid storing sensitive credentials (like Client Secrets or API Keys for sensitive operations) directly on the client. Utilize OAuth 2.0 Authorization Code Flow with PKCE (Proof Key for Code Exchange) to mitigate interception risks.

Secure Communication

  • Always use HTTPS: Ensure all API requests are made over HTTPS (TLS 1.2 or higher). This encrypts data in transit, preventing man-in-the-middle attacks. The Open Government, Slovakia APIs enforce HTTPS.
  • Validate SSL certificates: Ensure your application is configured to validate SSL/TLS certificates to prevent connections to malicious or fraudulent endpoints.

Token Management (for OAuth 2.0)

  • Short-lived access tokens: Access tokens should have a short lifespan to minimize the impact of compromise.
  • Secure refresh tokens: Store refresh tokens securely (encrypted, if possible) and revoke them immediately if suspected of compromise. Refresh tokens should only be used to obtain new access tokens and should not be directly exposed.
  • Scope management: Request only the necessary scopes (permissions) for your application to function. Over-requesting permissions increases the attack surface.
  • Token revocation: Implement mechanisms to revoke access and refresh tokens when a user logs out, deauthorizes your application, or if a security incident occurs.

Error Handling and Logging

  • Avoid verbose error messages: Do not reveal sensitive information (e.g., database errors, internal system details) in API error responses.
  • Implement secure logging: Log authentication successes and failures, but ensure credentials or sensitive user data are never logged. Use robust logging practices to detect and respond to potential security incidents.

Rate Limiting and Abuse Prevention

  • Respect rate limits: Open Government, Slovakia APIs implement rate limiting to prevent abuse. Design your application to handle 429 Too Many Requests responses gracefully, typically by implementing exponential backoff.
  • Monitor for suspicious activity: Regularly monitor your application's API usage patterns for anomalies that could indicate unauthorized access attempts or credential stuffing attacks.