fix: OpenRemote auth via client credentials (service account)
This commit is contained in:
11
simulator.py
11
simulator.py
@@ -544,17 +544,16 @@ def publish_frost(sid: str, sensor: dict, field: str, value: float) -> bool:
|
|||||||
_or_token_cache = {"token": "", "expires": 0}
|
_or_token_cache = {"token": "", "expires": 0}
|
||||||
|
|
||||||
def _get_or_token() -> str:
|
def _get_or_token() -> str:
|
||||||
"""Obtient un token OpenRemote avec cache (admin-cli pour écriture)."""
|
"""Obtient un token OpenRemote via client credentials (service account)."""
|
||||||
import time
|
import time
|
||||||
if _or_token_cache["token"] and _or_token_cache["expires"] > time.time() + 60:
|
if _or_token_cache["token"] and _or_token_cache["expires"] > time.time() + 60:
|
||||||
return _or_token_cache["token"]
|
return _or_token_cache["token"]
|
||||||
try:
|
try:
|
||||||
# Utiliser admin-cli qui a directAccessGrantsEnabled
|
# Utiliser le client openremote avec client secret (service account)
|
||||||
data = urllib.parse.urlencode({
|
data = urllib.parse.urlencode({
|
||||||
"grant_type": "password",
|
"grant_type": "client_credentials",
|
||||||
"client_id": "admin-cli",
|
"client_id": OR_CLIENT_ID,
|
||||||
"username": OR_ADMIN_USER,
|
"client_secret": OR_CLIENT_SECRET,
|
||||||
"password": OR_ADMIN_PASS,
|
|
||||||
}).encode()
|
}).encode()
|
||||||
req = urllib.request.Request(OR_TOKEN_URL, data=data)
|
req = urllib.request.Request(OR_TOKEN_URL, data=data)
|
||||||
with urllib.request.urlopen(req, timeout=5) as resp:
|
with urllib.request.urlopen(req, timeout=5) as resp:
|
||||||
|
|||||||
Reference in New Issue
Block a user