tokens WIP
This commit is contained in:
@@ -256,7 +256,7 @@ async def automation_progress_event_stream() -> AsyncGenerator[str, None]:
|
||||
return
|
||||
|
||||
@app.post("/token")
|
||||
async def login(request: Request, form_data: OAuth2PasswordRequestForm = Depends()):
|
||||
async def login(request: Request):
|
||||
"""
|
||||
Authenticate a user and return an access token.
|
||||
|
||||
|
||||
@@ -351,11 +351,8 @@ class BECClientWorker:
|
||||
else:
|
||||
method = "sample"
|
||||
|
||||
if method == "beamline":
|
||||
if method in {"beamline", "sample", "sample_environment"}:
|
||||
self.position_devices, self.planner = self.__init_beamline_environment()
|
||||
elif method in {"sample", "sample_environment"}:
|
||||
self.position_devices = self.__initialise_sample_environment_devices()
|
||||
self.planner = self.__planner()
|
||||
else:
|
||||
raise ValueError(
|
||||
"Invalid BEC reinitialisation method. "
|
||||
|
||||
+5
-19
@@ -1,4 +1,3 @@
|
||||
import json
|
||||
import subprocess
|
||||
import jwt
|
||||
|
||||
@@ -23,11 +22,7 @@ def auth(base_url: str | None, cert_path: str | None) -> str:
|
||||
cacert = f"{cert_path}"
|
||||
try:
|
||||
token_result = subprocess.run(
|
||||
['curl', '-s', '--cacert', cacert,
|
||||
'--negotiate', '-u', ':',
|
||||
'-X', 'POST', url,
|
||||
'-d', 'username=&password=',
|
||||
'-H', 'Content-Type: application/x-www-form-urlencoded'],
|
||||
['curl', '-s', '--cacert', cacert, '--negotiate', '-u', ':', url, "-XPOST"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=18.0,
|
||||
@@ -60,21 +55,12 @@ def auth(base_url: str | None, cert_path: str | None) -> str:
|
||||
"Check Kerberos ticket is valid (kinit) and server is reachable."
|
||||
)
|
||||
|
||||
try:
|
||||
response_json = json.loads(token_result.stdout)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Token response not JSON. stdout: {token_result.stdout[:500]}")
|
||||
token = token_result.stdout.strip()
|
||||
if not token:
|
||||
logger.error(f"Empty token response. stderr: {token_result.stderr[:500]}")
|
||||
raise RuntimeError(
|
||||
"Authentication failed (invalid server response). "
|
||||
"Authentication failed (empty server response). "
|
||||
"The server may be starting up or misconfigured."
|
||||
) from e
|
||||
|
||||
token = response_json.get("access_token")
|
||||
if not token or not isinstance(token, str):
|
||||
logger.error(f"Missing access_token. Keys: {list(response_json.keys())}. Server response {response_json}")
|
||||
raise RuntimeError(
|
||||
"Authentication failed (missing token in server response). "
|
||||
"The server may be starting up."
|
||||
)
|
||||
|
||||
return token
|
||||
@@ -137,6 +137,7 @@ def main():
|
||||
try:
|
||||
splash.set_progress(50, f"Connecting to {base_url or 'backend'}...")
|
||||
token = auth(base_url, cert_path)
|
||||
logger.info(f"Authentication token: {token}")
|
||||
if not token or token.count(".") != 2:
|
||||
raise RuntimeError(
|
||||
"Authentication did not return a valid token. "
|
||||
|
||||
Reference in New Issue
Block a user