Course contentsShow
← AI Engineering
Lesson 1808 of 1,88644. Integrations and EcosystemFree lesson

Authentication with CRM APIs

Implementing OAuth 2.0 flows and API key management for secure CRM connections.

Authentication with CRM APIs

You'll learn how to securely connect AI systems to CRM platforms using OAuth 2.0 flows and API key management.

Why Authentication Matters for CRM Integration

When your AI agent needs to read customer data, create contacts, or update deals in a CRM like Salesforce, HubSpot, or Dynamics 365, you can't just knock on the door—you need proper credentials. CRM systems hold sensitive business data, so authentication is both a security requirement and a trust mechanism.

OAuth 2.0: The Industry Standard

OAuth 2.0 is the authorization protocol most modern CRMs use. Think of it like getting a valet key for your car: you grant limited, specific access without handing over the master key.

Common OAuth flows for CRM:

  • Authorization Code Flow: Your app redirects users to the CRM's login page, receives a temporary code, then exchanges it for an access token. Best for user-facing applications.
  • Client Credentials Flow: Your backend service authenticates directly with client ID and secret. Ideal for server-to-server AI workflows.
  • Refresh Tokens: Access tokens expire (often after 1-2 hours). Refresh tokens let you obtain new access tokens without re-prompting users.

API Key Management

Some CRMs also support simpler API keys. These are like long-lived passwords that sit in your environment variables:

HUBSPOT_API_KEY=abc123xyz

Best practices:

  • Store keys in secret management systems (AWS Secrets Manager, HashiCorp Vault)
  • Rotate keys regularly
  • Use separate keys for dev/staging/production
  • Never commit keys to version control

Scope and Permissions

Both OAuth and API keys require defining scopes—what your AI can access. Request only the minimum permissions needed (e.g., read:contacts instead of admin:all).

Key Takeaway: Secure CRM connections for AI systems require OAuth 2.0 flows for user authorization or client credentials for service accounts, with careful API key management and least-privilege access scopes.