Overview

This guide walks you through setting up OAuth 2.0 authentication for the GetBill API. OAuth 2.0 provides secure, standardized authorization that allows your application to access GetBill data on behalf of your company.

Why OAuth 2.0?

Security

Your credentials are never stored in the client application. Tokens can be revoked without changing passwords.

Scoped Access

Request only the permissions your application needs. Users can see exactly what access they’re granting.

Standardized

OAuth 2.0 is an industry standard supported by all major platforms and programming languages.

Scalable

Suitable for everything from simple scripts to large enterprise integrations.

Step 1: Create an OAuth Client

Access Your Dashboard

  1. Log in to your GetBill account
  2. Navigate to Company
  3. Find the API Client Management section
  4. Click Create New OAuth Client

Configure Your Client

API clients use Client Credentials automatically for server-to-server authentication. There is no authentication flow to select.

Save Your Credentials

After creating the client, you’ll receive:
string
Public identifier for your application (safe to store in client-side code)
string
Secret key for your application (keep this secure!)
Store your Client Secret securely! Never commit it to version control or expose it in client-side code.

Step 2: Request an Access Token

Client Credentials Flow

Best for: Server-to-server applications, background jobs, automated systems When to use:
  • Your application runs on a secure server
  • No user interaction is required
  • You’re accessing your own company’s data
Flow:
  1. Your application requests a token directly from the authorization server
  2. No user authorization step is required
  3. Token is returned immediately

Step 3: Implementation Examples

Client Credentials Implementation

Step 4: Security Best Practices

Secure Token Storage

  • Use environment variables for client secrets
  • Store tokens securely (encrypted database, secure session storage)
  • Never log or expose tokens in error messages

Minimal Scopes

  • Request only the scopes your integration needs
  • Review granted scopes regularly
  • Remove permissions that are no longer required

HTTPS Only

  • Always use HTTPS for all OAuth flows
  • Validate SSL certificates
  • Never send tokens over unencrypted connections

Token Management

  • Request a new token before expiration
  • Handle token expiration gracefully
  • Revoke tokens when no longer needed

Environment Variables Example

Step 5: Testing Your Setup

Test Client Credentials

Troubleshooting

Cause: Incorrect client ID or secretSolution:
  • Double-check your client credentials
  • Ensure you’re using the correct environment (test vs production)
  • Verify the client is active in your dashboard
Cause: Requesting scopes not granted to your clientSolution:
  • Check your client configuration in the dashboard
  • Request only the scopes you need
  • Contact support if you need additional scopes
Cause: Invalid or unsupported grant typeSolution:
  • Send grant_type=client_credentials
  • Use the /oauth/token endpoint
  • Check that the request body uses form encoding

Production Considerations

Scaling OAuth

  • Token Caching: Cache tokens in Redis or similar for multiple server instances
  • Secure Storage: Store client credentials in a secrets manager
  • Rate Limiting: Avoid unnecessary token requests by reusing valid access tokens
  • Monitoring: Monitor token issuance and API authentication failures

Security Hardening

  • Certificate Pinning: Pin SSL certificates for additional security
  • Token Rotation: Regularly rotate client secrets
  • Audit Logging: Log all OAuth events for security monitoring
  • Scope Minimization: Use the minimum required scopes

Next Steps

Once OAuth is set up:
  1. Make your first API call
  2. Explore the API Reference documentation
  3. Set up webhooks for real-time updates
  4. Review best practices for production use
Need help? Contact our support team at contact@getbill.io