Authentication
SmartElektroHub supports two authentication methods: API Keys for server-side integrations and OAuth 2.0 when building third-party applications on behalf of other SmartElektroHub accounts.
API Keys
Every SmartElektroHub account has two types of API key, available in the Dashboard → Settings → API Keys section:
| Key type | Prefix | Where to use |
|---|---|---|
| Secret Key | eh_sk_… |
Server-side only. Full API access. Never expose publicly. |
| Publishable Key | eh_pk_… |
Safe for browser / mobile apps. Read-only scope + subscriber token creation. |
Using an API key
Pass the key in the Authorization header as a Bearer token:
curl https://api.smart-elektro.ru/v2/streams \
-H "Authorization: Bearer eh_sk_••••••••••••••••"
// JavaScript SDK — key is passed at initialization
const client = new SmartElektroHub({ apiKey: 'eh_sk_••••••••••••••••' });
Rotating keys
To rotate a key, open Dashboard → Settings → API Keys, click Roll key, and update your environment variables. Old keys are invalidated immediately.
OAuth 2.0
Use the Authorization Code flow when your application acts on behalf of other SmartElektroHub accounts (e.g., a third-party dashboard or integration platform).
1 — Redirect the user
GET https://auth.smart-elektro.ru/oauth/authorize
?client_id=YOUR_CLIENT_ID
&redirect_uri=https%3A%2F%2Fyourapp.example%2Fcallback
&response_type=code
&scope=streams%3Aread%20streams%3Awrite%20reports%3Aread
&state=RANDOM_CSRF_TOKEN
2 — Exchange the code for tokens
curl -X POST https://auth.smart-elektro.ru/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "code=AUTH_CODE_FROM_REDIRECT" \
-d "redirect_uri=https://yourapp.example/callback" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET"
Token response
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9…",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "rt_01kp27cxn8jm4tqbvz9r3wf",
"scope": "streams:read streams:write reports:read"
}
3 — Refresh an access token
curl -X POST https://auth.smart-elektro.ru/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token" \
-d "refresh_token=rt_01kp27cxn8jm4tqbvz9r3wf" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET"
Available scopes
| Scope | Access granted |
|---|---|
streams:read | List and retrieve streams |
streams:write | Create, update, and delete streams |
reports:read | List and retrieve reports and records |
reports:write | Create, update, and publish records |
webhooks:read | List webhook configurations |
webhooks:write | Create and delete webhook configurations |
account:read | Read account and billing information |
Authentication Errors
| Code | Status | Meaning |
|---|---|---|
missing_token | 401 | No Authorization header provided |
invalid_token | 401 | Token malformed or signature invalid |
token_expired | 401 | Access token has expired — refresh it |
insufficient_scope | 403 | Token lacks required scope for this action |
key_revoked | 401 | API key has been revoked |
Аутентификация
SmartElektroHub поддерживает два метода аутентификации: API-ключи для серверных интеграций и OAuth 2.0 — когда ваше приложение действует от имени других аккаунтов SmartElektroHub.
API-ключи
В каждом аккаунте SmartElektroHub есть два типа ключей — в разделе Dashboard → Settings → API Keys:
| Тип ключа | Префикс | Где использовать |
|---|---|---|
| Секретный ключ | eh_sk_… |
Только на сервере. Полный доступ к API. Никогда не раскрывайте публично. |
| Публичный ключ | eh_pk_… |
Безопасен для браузера и мобильных приложений. Только чтение + создание токенов подписчика. |
Использование API-ключа
Передайте ключ в заголовке Authorization как Bearer-токен:
curl https://api.smart-elektro.ru/v2/streams \
-H "Authorization: Bearer eh_sk_••••••••••••••••"
// JavaScript SDK — ключ передаётся при инициализации
const client = new SmartElektroHub({ apiKey: 'eh_sk_••••••••••••••••' });
Ротация ключей
Для смены ключа перейдите в Dashboard → Settings → API Keys, нажмите Сменить ключ и обновите переменные окружения. Старые ключи аннулируются немедленно.
OAuth 2.0
Используйте поток Authorization Code, когда ваше приложение действует от имени других аккаунтов SmartElektroHub (например, сторонний дашборд или платформа интеграций).
1 — Перенаправьте пользователя
GET https://auth.smart-elektro.ru/oauth/authorize
?client_id=YOUR_CLIENT_ID
&redirect_uri=https%3A%2F%2Fyourapp.example%2Fcallback
&response_type=code
&scope=streams%3Aread%20streams%3Awrite%20reports%3Aread
&state=RANDOM_CSRF_TOKEN
2 — Обменяйте код на токены
curl -X POST https://auth.smart-elektro.ru/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "code=AUTH_CODE_FROM_REDIRECT" \
-d "redirect_uri=https://yourapp.example/callback" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET"
Ответ с токенами
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9…",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "rt_01kp27cxn8jm4tqbvz9r3wf",
"scope": "streams:read streams:write reports:read"
}
3 — Обновление access-токена
curl -X POST https://auth.smart-elektro.ru/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token" \
-d "refresh_token=rt_01kp27cxn8jm4tqbvz9r3wf" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET"
Доступные скоупы
| Скоуп | Предоставляемый доступ |
|---|---|
streams:read | Просмотр списка и данных потоков |
streams:write | Создание, обновление и удаление потоков |
reports:read | Просмотр отчётов и записей |
reports:write | Создание, обновление и публикация записей |
webhooks:read | Просмотр настроенных вебхуков |
webhooks:write | Создание и удаление вебхуков |
account:read | Информация об аккаунте и биллинге |
Ошибки аутентификации
| Код | Статус | Описание |
|---|---|---|
missing_token | 401 | Заголовок Authorization не предоставлен |
invalid_token | 401 | Токен повреждён или подпись недействительна |
token_expired | 401 | Срок действия access-токена истёк — обновите его |
insufficient_scope | 403 | Токен не имеет нужного скоупа для данного действия |
key_revoked | 401 | API-ключ был отозван |