File tree Expand file tree Collapse file tree 4 files changed +24
-7
lines changed
Expand file tree Collapse file tree 4 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -275,9 +275,20 @@ def run():
275275 rich_handler .setLevel (logging .DEBUG if args .debug else logging .INFO )
276276
277277 # Set up websocket app and handler
278- client_id = requests .get (
278+ client_id_response = requests .get (
279279 f"{ murfey_url .geturl ()} { url_path_for ('session_control.router' , 'new_client_id' )} "
280- ).json ()
280+ )
281+ if client_id_response .status_code == 401 :
282+ exit (
283+ "This instrument is not authorised to run the TUI app; please use the "
284+ "Murfey web UI instead"
285+ )
286+ elif client_id_response .status_code != 200 :
287+ exit (
288+ "Unable to establish connection to Murfey server: \n "
289+ f"{ client_id_response .json ()} "
290+ )
291+ client_id : dict = client_id_response .json ()
281292 ws = murfey .client .websocket .WSApp (
282293 server = args .server ,
283294 id = client_id ["new_id" ],
Original file line number Diff line number Diff line change 77
88import murfey
99import murfey .client .update
10+ import murfey .client .websocket
1011from murfey .client .customlogging import CustomHandler
1112from murfey .util import LogFilter
1213from murfey .util .client import read_config
Original file line number Diff line number Diff line change @@ -175,12 +175,16 @@ async def validate_instrument_token(
175175 if expiry_time := decoded_data .get ("expiry_time" ):
176176 if expiry_time < time .time ():
177177 raise JWTError
178+ # Check that the decoded session corresponds to the visit
178179 elif decoded_data .get ("session" ) is not None :
179- # Check that the decoded session corresponds to the visit
180180 if not validate_session_against_visit (
181181 decoded_data ["session" ], decoded_data ["visit" ]
182182 ):
183183 raise JWTError
184+ # Verify 'user' token if enabled
185+ elif security_config .allow_user_token :
186+ if not decoded_data .get ("user" ):
187+ raise JWTError
184188 else :
185189 raise JWTError
186190 except JWTError :
Original file line number Diff line number Diff line change @@ -124,13 +124,14 @@ class Security(BaseModel):
124124 ispyb_credentials : Optional [Path ] = None
125125
126126 # Murfey server connection settings
127+ auth_url : str = ""
128+ auth_type : Literal ["password" , "cookie" ] = "password"
127129 auth_algorithm : str = ""
128130 auth_key : str = ""
129- auth_type : Literal ["password" , "cookie" ] = "password"
130- auth_url : str = ""
131- instrument_auth_type : Literal ["token" , "" ] = "token"
132- instrument_auth_url : str = ""
133131 cookie_key : str = ""
132+ instrument_auth_url : str = ""
133+ instrument_auth_type : Literal ["token" , "" ] = "token"
134+ allow_user_token : bool = False # TUI 'user' token support
134135 session_validation : str = ""
135136 session_token_timeout : Optional [int ] = None
136137 allow_origins : list [str ] = ["*" ]
You can’t perform that action at this time.
0 commit comments