Authentication
You'll need to authenticate your requests to access the IMMUNE API endpoints. In this guide, we'll look at how authentication works. IMMUNE offers two ways to authenticate your API requests: API key authentication and OAuth2 with bearer tokens — OAuth2 is recommended for production environments.
API Key authentication
For quick testing and development, you can use API key authentication. Each request should include your API key in the Authorization header:
Example request with API key
curl https://api.immune.dev/v1/sensors \
-H "Authorization: ApiKey your-api-key"
Never share or commit your API keys. Keep them secure and use environment variables in your applications.
OAuth2 with bearer token
The recommended way to authenticate with the IMMUNE API in production is using OAuth2. When establishing a connection using OAuth2, you will need your access token — you will find it in the IMMUNE dashboard under API settings. Here's how to add the token to the request header:
Example request with bearer token
curl https://api.immune.dev/v1/sensors \
-H "Authorization: Bearer {token}"
Obtaining an access token
To get an access token:
- Register your application in the IMMUNE dashboard
- Configure your OAuth2 credentials
- Use the OAuth2 flow to obtain an access token
Example OAuth2 token request
curl -X POST https://auth.immune.dev/oauth/token \
-d "grant_type=client_credentials" \
-d "client_id=your-client-id" \
-d "client_secret=your-client-secret"
Using an SDK
If you use one of our official SDKs, authentication is handled automatically. Simply initialize the client with your credentials:
import { ImmuneClient } from '@immune/api'
// Using API key
const client = new ImmuneClient('your-api-key')
// Using OAuth2
const client = new ImmuneClient({
clientId: 'your-client-id',
clientSecret: 'your-client-secret'
})
Security best practices
When integrating with IMMUNE, follow these security guidelines:
- Use OAuth2 in production environments
- Rotate your credentials regularly
- Use environment variables to store sensitive credentials
- Implement proper token management and refresh flows
- Monitor API usage through the dashboard