Skip to content

Commit db3b9c6

Browse files
[ICAT-SSO] - Initial work an adapting AbstractLims and integration with SSO
1 parent bb3f4c7 commit db3b9c6

30 files changed

+845
-625
lines changed

demo/mxcube-web/server.yaml

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
---
22

33
server:
4-
SECRET_KEY: "ASECRETKEY"
5-
SECURITY_PASSWORD_SALT: "ASALT"
4+
SECRET_KEY: ASECRETKEY
5+
SECURITY_PASSWORD_SALT: ASALT
66
PERMANENT_SESSION_LIFETIME: 60
7+
CERT: NONE
78

89
DEBUG: false
910

1011
ALLOWED_CORS_ORIGINS:
11-
- "http://localhost:8081"
12-
- "http://127.0.0.1:8081"
13-
- "http://localhost:5173"
14-
- "http://127.0.0.1:5173"
15-
- "ws://localhost:8000"
16-
- "ws://127.0.0.1:8000"
12+
- http://localhost:8081
13+
- http://127.0.0.1:8081
14+
- http://localhost:5173
15+
- http://127.0.0.1:5173
16+
- ws://localhost:8000
17+
- ws://127.0.0.1:8000
18+
19+
sso:
20+
USE_SSO: false
21+
ISSUER: https://websso.[site].[com]/realms/[site]/
22+
LOGOUT_URI: ""
23+
TOKEN_INFO_URI: ""
24+
CLIENT_SECRET: ASECRETKEY
25+
CLIENT_ID: mxcube
26+
SCOPE: openid email profile
27+
CODE_CHALLANGE_METHOD: S256
1728

1829
mxcube:
1930
USE_EXTERNAL_STREAMER: true
2031
VIDEO_FORMAT: MPEG1
21-
VIDEO_STREAM_URL: "ws://localhost:8000/ws"
32+
VIDEO_STREAM_URL: ws://localhost:8000/ws
2233

2334
# At which port to stream from
2435
VIDEO_STREAM_PORT: 8000

docs/source/dev/login.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Login
2+
3+
## Authentication and authorization
4+
5+
The authentication and authorization of a user have traditionally been performed in one step via the `ISPYBClient` hardware object. The authentication step has either been done through LDAP or delegated to ISPyB. `ISPYBClient` has been replaced by `ISPyBAbstractLIMS` and exists in two variants, one for user-based login (`UserTypeISPyBLims`) and another one for proposal (`ProposalTypeISPyBLims`) both of which support authentication via LDAP or ISPyB. The possibility to authenticate via LIMS will be removed in the future, and authentication has to be delegated to a process dedicated to authentication. The authorization for a user to use a beamline is performed via the user portal or LIMS system.
6+
7+
### Authentication with single sign on
8+
9+
MXCUBE can be configured to use Single sign-on (SSO) through OpenIDConnect for user authentication. The OpenIDConnect configuration is located in the `server.yaml` file, which should contain an `sso` section like the one below.
10+
11+
```
12+
sso:
13+
USE_SSO: false # True to use SSO false otherwise
14+
ISSUER: https://websso.[site].[com]/realms/[site]/ # OpenIDConnect issuer URI
15+
LOGOUT_URI: "" # OpenIDConnect logout URI
16+
TOKEN_INFO_URI: "" # OpenIDConnect token info URI
17+
CLIENT_SECRET: ASECRETKEY # OpenIDConnect client secret
18+
CLIENT_ID: mxcube # OpenIDConnect client ID
19+
SCOPE: openid email profile # OpenIDConnect defualt scopes, none scope is actually beeing used
20+
CODE_CHALLANGE_METHOD: S256 # OpenIDConnect challange method
21+
```
22+
23+
User authorization is delegated to the LIMS client inheriting `AbstractLims` and is performed in the `login` method.
24+
25+
## HTTP Session management
26+
27+
MXCuBE web sessions are meant to expire when there is no activity
28+
29+
For this purpose:
30+
31+
- Flask configuration setting `PERMANENT_SESSION_LIFETIME` is set
32+
to the preferred value (seconds).
33+
34+
- Flask configuration setting `SESSION_REFRESH_EACH_REQUEST` is set,
35+
which is the default anyway.
36+
37+
- Flask session setting `session.permanent` is set
38+
right after successful authentication.
39+
40+
- The front-end calls the `/mxcube/api/v0.1/login/refresh_session` endpoint
41+
regularly (hardcoded value: 9000 milliseconds)
42+
for as long as the browser tab is open.
43+
44+
Every time the _refresh_ endpoint is called,
45+
the browser session cookie is refreshed,
46+
meaning its expiration timestamp is pushed back in the future
47+
for as much as the value stored in `PERMANENT_SESSION_LIFETIME`.

docs/source/dev/login.rst

-26
This file was deleted.

mxcubeweb/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
AppConfigModel,
1313
FlaskConfigModel,
1414
MXCUBEAppConfigModel,
15+
SSOConfigModel,
1516
UIPropertiesListModel,
1617
)
1718

@@ -36,6 +37,7 @@ class Config:
3637

3738
flask: FlaskConfigModel
3839
app: MXCUBEAppConfigModel
40+
sso: SSOConfigModel
3941

4042
def __init__(self, fpath):
4143
Config.CONFIG_ROOT_PATH = fpath
@@ -45,6 +47,7 @@ def __init__(self, fpath):
4547
self.flask = app_config.server
4648
self.app = app_config.mxcube
4749
self.app.ui_properties = uiprop
50+
self.sso = app_config.sso
4851

4952
def load_config(self, component_name, schema):
5053
fpath = os.path.join(Config.CONFIG_ROOT_PATH, f"{component_name}.yaml")

mxcubeweb/core/components/harvester.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def send_data_collection_info_to_crims(self) -> bool:
160160
crystal_uuid = ""
161161

162162
try:
163-
rest_token = HWR.beamline.lims.lims_rest.get_rest_token()
163+
rest_token = HWR.beamline.lims.get_rest_token()
164164
proposal = HWR.beamline.session.get_proposal()
165165

166166
crims_url = self.harvester_device.crims_upload_url

0 commit comments

Comments
 (0)