CloudSignal Docs
GuidesAuth Providers

Auth providers

Integrate external identity providers like Supabase, Firebase, and Auth0 with CloudSignal MQTT.

Auth providers let users authenticate with your existing identity system and exchange tokens for temporary CloudSignal MQTT credentials. Use this when you already manage user accounts in Supabase, Firebase, Auth0, or Clerk and want to skip a second credential system.

Native authentication is always available. Auth providers add additional authentication methods, they don't replace the built-in client credentials system.

How it works

Token exchange flow
User app
Identity provider
CloudSignal
MQTT broker
Log in
JWT token
Exchange JWT
MQTT credentials (temporary)
Connect with username + password
  1. User logs in to your app via your auth provider
  2. Your app calls CloudSignal's token exchange endpoint with the provider's JWT
  3. CloudSignal validates the token and returns temporary MQTT credentials
  4. User connects to MQTT with the temporary credentials

Supported providers

Why use auth providers?

Single sign-on experience

Users log in once with their existing account.

SetupSteps
Without auth providersUser logs in to your app, then needs separate MQTT credentials, and you manage two authentication systems
With auth providersUser logs in to your app, the app exchanges the token for MQTT credentials, and the user connects to MQTT

Automatic credential management

PropertyBehavior
No password storageCredentials are temporary and auto-generated
Automatic expirationTokens expire (default: 60 minutes)
User-scopedEach user gets unique credentials tied to their identity

Simplified access control

Link MQTT permissions to your user's identity:

User: john@example.com (from Supabase)
  becomes
MQTT username: john_example_com@org-abc123
  matched by ACL on "john_example_com"
    Can publish to: users/john_example_com/#
    Can subscribe to: notifications/john_example_com/#

Quick start

1. Configure auth provider

Go to ConnectionsAuth ProvidersAdd Provider.

Select your provider and enter the required configuration:

ProviderRequired config
SupabaseProject URL, JWT secret
FirebaseProject ID
Auth0Domain, audience
ClerkDev and/or prod frontend API

2. Test token exchange

Use the API to exchange a token:

curl -X POST https://api.cloudsignal.io/v2/tokens/exchange \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "supabase",
    "token": "eyJhbGciOiJIUzI1NiIs..."
  }'

Response:

{
  "mqtt_username": "user123@a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "mqtt_password": "temp_password_xyz",
  "expires_at": "2024-01-15T13:00:00Z",
  "expires_in": 3600
}

3. Connect to MQTT

Use the returned credentials:

const mqtt = require('mqtt');

// Exchange token first
const credentials = await exchangeToken(supabaseSession.access_token);

// Connect with temporary credentials
const client = mqtt.connect('mqtts://mqtt.cloudsignal.app:8883', {
  username: credentials.mqtt_username,
  password: credentials.mqtt_password
});

Best practices

Refresh tokens before expiry

// Track credential expiry
let mqttCredentials = null;
let expiresAt = null;

async function getCredentials() {
  // Refresh 5 minutes before expiry
  const refreshBuffer = 5 * 60 * 1000;

  if (!mqttCredentials || Date.now() > expiresAt - refreshBuffer) {
    const response = await exchangeToken(getAuthToken());
    mqttCredentials = response;
    expiresAt = new Date(response.expires_at).getTime();
  }

  return mqttCredentials;
}

Handle reconnection

client.on('close', async () => {
  // Get fresh credentials on reconnect
  const credentials = await getCredentials();
  client.options.username = credentials.mqtt_username;
  client.options.password = credentials.mqtt_password;
});

User-scoped ACL rules

Create ACL rules that leverage the user identity:

# Allow users to only access their own topics
User Pattern: %
Topic: users/%u/#
Permission: pubsub

The %u substitutes the username, so john_doe can only access users/john_doe/#.


Next steps

On this page