Authentication
OAuth2 authentication guide for the Yipii IoT API
The Yipii IoT API uses OAuth2 with the Client Credentials flow for server-to-server authentication. This guide covers how to authenticate and manage access tokens.
OAuth2 Client Credentials Flow
The Client Credentials flow is designed for machine-to-machine authentication where your application directly accesses the API without user interaction.
Flow Overview
- Your application sends client credentials to the token endpoint
- The API validates credentials and returns an access token
- Use the access token in the Authorization header for API requests
- Refresh the token before it expires
Obtaining Tokens
Token Endpoint
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
grant_type | string | Yes | Must be client_credentials |
client_id | string | Yes | Your OAuth2 client ID |
client_secret | string | Yes | Your OAuth2 client secret |
scope | string | No | Space-separated list of scopes (optional) |
Code Examples
cURL
JavaScript (Node.js)
JavaScript (Fetch API)
PHP
Python
Token Response
| Field | Description |
|---|---|
access_token | The JWT token to use for API requests |
token_type | Always Bearer |
expires_in | Token lifetime in seconds (typically 1 year) |
Using Access Tokens
Include the access token in the Authorization header of all API requests:
JavaScript Example
PHP Example
Account Key
The account key is a unique identifier for your account, used in all API endpoints:
Finding Your Account Key
-
From the Dashboard URL: Your account key appears in the URL when logged in:
-
From the User Endpoint: Call the user profile endpoint:
Response includes your accounts:
Token Management
Token Expiration
Access tokens have a long lifetime (typically 1 year), but you should:
- Store tokens securely - Never expose tokens in client-side code or logs
- Handle 401 responses - Refresh the token if you receive an unauthorized error
- Rotate periodically - Consider refreshing tokens proactively for security
Handling Expired Tokens
Security Best Practices
Never expose your Client Secret in client-side code, public repositories, or logs.
Do
- Store credentials in environment variables or a secure vault
- Use HTTPS for all API requests
- Rotate credentials periodically
- Implement proper error handling for authentication failures
Don't
- Hardcode credentials in source code
- Log access tokens or credentials
- Share credentials between environments
- Use the same credentials for development and production
Environment Variable Example
Error Responses
Invalid Credentials
Expired Token
HTTP Status: 401 Unauthorized
Next Steps
- API Keys - Create and manage API keys for simpler authentication
- Quick Start Examples - Common API usage patterns
- Reporting Service Guide - Async report generation with WebSocket
- IoT-BE API Reference - Full API documentation
Was this page helpful?