Skip to content

Commit a92e72b

Browse files
committed
Add login method to BlueapiClient
1 parent 2ab482a commit a92e72b

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/blueapi/client/client.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
MissingStompConfigurationError,
2222
)
2323
from blueapi.core.bluesky_types import DataEvent
24-
from blueapi.service.authentication import SessionManager
24+
from blueapi.service.authentication import SessionCacheManager, SessionManager
2525
from blueapi.service.model import (
2626
DeviceModel,
2727
DeviceResponse,
@@ -729,3 +729,18 @@ def get_python_env(
729729
"""
730730

731731
return self._rest.get_python_environment(name=name, source=source)
732+
733+
def login(self, token_path: Path | None = None):
734+
try:
735+
auth: SessionManager = SessionManager.from_cache(token_path)
736+
access_token = auth.get_valid_access_token()
737+
assert access_token
738+
print("Logged in")
739+
except Exception:
740+
if oidc := self.oidc_config:
741+
auth = SessionManager(
742+
oidc, cache_manager=SessionCacheManager(token_path)
743+
)
744+
auth.start_device_flow()
745+
else:
746+
print("Server is not configured to use authentication!")

0 commit comments

Comments
 (0)