Authentication overview

Open Government, Singapore, provides a unified platform for developers to integrate with various government digital services. Authentication is a critical component for ensuring secure and authorized access to these services and their underlying data. The Singapore Government Developer Portal, accessible via developer.gov.sg/docs, serves as the central hub for managing API access, credentials, and documentation related to authentication. The specific authentication method required can vary based on the sensitivity of the data or service being accessed, aligning with the principle of least privilege.

Developers interacting with APIs such as the Singpass API or Myinfo API will typically encounter robust authentication mechanisms designed to protect personal and sensitive government data. These mechanisms are established to comply with data protection regulations like the Personal Data Protection Act (PDPA) in Singapore, ensuring that only authorized applications and users can retrieve or submit information. The portal guides developers through the necessary steps to register applications, obtain credentials, and correctly implement authentication flows, ensuring secure integration with the public sector's digital infrastructure.

Supported authentication methods

Open Government, Singapore's developer portal supports multiple authentication methods, each suited for different use cases and security requirements. The choice of method often depends on the specific API being consumed and the nature of the application integrating with it. Developers should consult the individual API documentation on the Open Government, Singapore API reference to determine the exact requirements.

Overview of Authentication Methods
Method When to Use Security Level
API Keys For simple API access, typically less sensitive data, or internal server-to-server communication where the key can be securely stored. Moderate (relies on key secrecy)
OAuth 2.0 For user-centric applications (e.g., web or mobile apps) where delegated authorization is required, allowing users to grant third-party applications limited access to their data without sharing credentials. Often used with Singpass and Myinfo for secure citizen data access. The OAuth 2.0 framework provides a secure standard for delegated authorization. High (token-based, user consent)
Digital Certificates (mTLS) For highly sensitive transactions and server-to-server communication requiring mutual authentication (client and server verify each other's identity). Ensures strong identity verification and secure channel establishment. Very High (cryptographic identity verification)
Singpass Login (as part of OAuth) When authenticating Singapore residents and enabling access to their personal data via Myinfo, using Singpass for identity verification. It integrates within an OAuth 2.0 flow. Very High (government-issued identity)

Getting your credentials

Accessing Open Government, Singapore APIs requires developers to register their applications and obtain the necessary authentication credentials. The process generally involves these steps, managed through the Singapore Government Developer Portal:

  1. Developer Account Registration: First, create a developer account on the portal. This establishes your identity as an integrating party.
  2. Application Registration: Register your application within the developer portal. During this step, you will typically provide details about your application, such as its name, description, and redirect URIs (for OAuth 2.0 flows).
  3. API Subscription: Subscribe your registered application to the specific APIs you intend to use (e.g., Singpass API, Myinfo API). Approval for sensitive APIs may require additional verification or documentation.
  4. Credential Issuance: Upon successful application registration and API subscription, the portal will issue your credentials. These can include:
    • Client ID: A public identifier for your application.
    • Client Secret: A confidential key used to authenticate your application. This must be kept secure.
    • API Key: A unique string passed with each request, often in a header or query parameter, for APIs that use this method.
    • Digital Certificates: For APIs requiring mutual TLS (mTLS), you will be provided with instructions on how to generate or obtain client certificates and private keys.
  5. Environment Setup: Differentiate between sandbox/staging credentials for development and testing, and production credentials for live deployments. Always obtain and use the appropriate credentials for each environment.

It is crucial to manage these credentials securely to prevent unauthorized access. The developer portal provides specific instructions for each API on how to generate, manage, and revoke credentials.

Authenticated request example

The following example demonstrates an authenticated request using an API key, a common method for less sensitive Open Government, Singapore APIs. For OAuth 2.0 or mTLS, the implementation would involve additional steps for token exchange or certificate handling.

Example: Authenticating with an API Key (using cURL)

Assume an API endpoint /data/v1/dataset requires an API key passed in an X-API-Key header.

curl -X GET \
  'https://api.data.gov.sg/data/v1/dataset' \
  -H 'X-API-Key: YOUR_API_KEY_HERE' \
  -H 'Accept: application/json'

Explanation:

  • -X GET: Specifies the HTTP GET method for retrieving data.
  • 'https://api.data.gov.sg/data/v1/dataset': The target API endpoint URL.
  • -H 'X-API-Key: YOUR_API_KEY_HERE': Sets the X-API-Key HTTP header with your unique API key. Replace YOUR_API_KEY_HERE with the actual key obtained from the developer portal.
  • -H 'Accept: application/json': Indicates that the client prefers to receive a JSON response.

For APIs requiring OAuth 2.0, requests would typically include an Authorization header with a Bearer Token, obtained after a successful authorization flow. For example:

curl -X GET \
  'https://api.singpass.gov.sg/v1/profile' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'Accept: application/json'

The Open Government, Singapore API reference provides specific examples for each API's authentication mechanism.

Security best practices

Implementing strong security practices is paramount when integrating with Open Government, Singapore APIs, especially given the sensitive nature of public sector data. Adhering to these guidelines helps protect both your application and citizen data:

  • Secure Credential Storage: Never hardcode API keys or client secrets directly into your application's source code. Store them in secure environment variables, secret management services (e.g., AWS Secrets Manager, Azure Key Vault, Google Secret Manager), or encrypted configuration files. For client-side applications, use token-based authentication (like OAuth 2.0) and avoid exposing credentials.
  • Use HTTPS/TLS Everywhere: Always use HTTPS for all API communication to ensure data is encrypted in transit. This protects against man-in-the-middle attacks. The Singapore Government Developer Portal mandates TLS 1.2 or higher for all API endpoints.
  • Implement Least Privilege: Request only the necessary permissions (scopes) for your application. If an API offers granular permissions, only select those essential for your application's functionality. This minimizes the impact of a potential breach.
  • Regular Credential Rotation: Periodically rotate your API keys and client secrets. This reduces the window of opportunity for attackers to exploit compromised credentials. The frequency of rotation should align with your organization's security policies and the sensitivity of the data accessed.
  • Validate and Sanitize Inputs: Always validate and sanitize all user inputs and data received from external sources before processing or storing them. This prevents common vulnerabilities like injection attacks.
  • Error Handling without Exposure: Implement robust error handling but avoid exposing sensitive information (e.g., stack traces, internal system details, raw API keys) in error messages accessible to end-users or logs that are not securely managed.
  • Monitor API Usage: Implement logging and monitoring for API access patterns and authentication failures. Unusual activity can indicate an attempted breach or misuse of credentials. Set up alerts for suspicious events.
  • Comply with PDPA: Ensure your application's data handling practices comply with Singapore's Personal Data Protection Act (PDPA) and any other applicable data privacy regulations. This includes obtaining proper consent and ensuring data security. The Personal Data Protection Commission (PDPC) website provides detailed guidance on PDPA.
  • Stay Updated: Regularly check the Singapore Government Developer Portal documentation for updates on security policies, recommended practices, and changes to authentication mechanisms.