diff --git a/src/blueapi/client/rest.py b/src/blueapi/client/rest.py index 2ec60a1c7..85adc6a51 100644 --- a/src/blueapi/client/rest.py +++ b/src/blueapi/client/rest.py @@ -5,6 +5,7 @@ from pydantic import TypeAdapter from blueapi.config import RestConfig +from blueapi.service.authentication import Authentication, AuthenticationType from blueapi.service.model import ( DeviceModel, DeviceResponse, @@ -127,10 +128,16 @@ def _request_and_deserialize( get_exception: Callable[[requests.Response], Exception | None] = _exception, ) -> T: url = self._url(suffix) + auth = Authentication(AuthenticationType.DEVICE) + access_token = auth.load_token()["access_token"] + headers = { + "content-type": "application/json; charset=UTF-8", + "Authorization": f"Bearer {access_token}", + } if data: - response = requests.request(method, url, json=data) + response = requests.request(method, url, json=data, headers=headers) else: - response = requests.request(method, url) + response = requests.request(method, url, headers=headers) exception = get_exception(response) if exception is not None: raise exception diff --git a/src/blueapi/service/authentication.py b/src/blueapi/service/authentication.py index 41c09e771..ecf56324b 100644 --- a/src/blueapi/service/authentication.py +++ b/src/blueapi/service/authentication.py @@ -142,8 +142,9 @@ def load_token(self): with open("token.txt", "rb") as token_file: token = token_file.read() token = cipher_suite.decrypt(token).decode() - # This print is just for testing purposes + # TODO: This print is just for testing purposes print(token) + return json.loads(token) def start_device_flow(self): response = requests.post(