Integrates CERN databases and login with Invenio
Project description
.. Copyright (C) 2024 CERN.
Invenio-CERN-sync is free software; you can redistribute it and/or modify it
under the terms of the MIT License; see LICENSE file for more details.
Invenio-CERN-sync
Integrates CERN databases and SSO login with Invenio.
SSO login
This module provides configurable integration with the CERN SSO login.
To integrate the CERN SSO, add this to your application configuration:
from invenio_cern_sync.sso import cern_remote_app_name, cern_keycloak
OAUTHCLIENT_REMOTE_APPS = {
cern_remote_app_name: cern_keycloak.remote_app,
}
CERN_APP_CREDENTIALS = {
"consumer_key": "CHANGE ME",
"consumer_secret": "CHANGE ME",
}
from invenio_cern_sync.sso.api import confirm_registration_form
OAUTHCLIENT_SIGNUP_FORM = confirm_registration_form
OAUTHCLIENT_CERN_REALM_URL = cern_keycloak.realm_url
OAUTHCLIENT_CERN_USER_INFO_URL = cern_keycloak.user_info_url
OAUTHCLIENT_CERN_VERIFY_EXP = True
OAUTHCLIENT_CERN_VERIFY_AUD = False
OAUTHCLIENT_CERN_USER_INFO_FROM_ENDPOINT = True
Define, use the env var to inject the right configuration for your env (local, prod, etc.):
- INVENIO_CERN_SYNC_KEYCLOAK_BASE_URL
- INVENIO_SITE_UI_URL
Sync users and groups
You can sync users and groups from the CERN AuthZ service or LDAP with the local Invenio db.
First, decide what fields you would like to get from the CERN database.
By default, only the field in invenio_cern_sync.users.profile.CERNUserProfileSchema
are kept when syncing.
If you need to customize that, you will need to:
- Provide your own schema class, and assign it the config var
ACCOUNTS_USER_PROFILE_SCHEMA - Change the mappers, to serialize the fetched users from the CERN format to your
local format. If you are using AuthZ, assign your custom serializer func
to
CERN_SYNC_AUTHZ_USERPROFILE_MAPPER. If you are using LDAP, assign it toCERN_SYNC_LDAP_USERPROFILE_MAPPER. - You can also customize what extra data can be stored in the RemoteAccount.extra_data fields
via the config
CERN_SYNC_AUTHZ_USER_EXTRADATA_MAPPERorCERN_SYNC_LDAP_USER_EXTRADATA_MAPPER.
If are only using the CERN SSO as unique login method, you will probably also configure:
ACCOUNTS_DEFAULT_USER_VISIBILITY = True
ACCOUNTS_DEFAULT_EMAIL_VISIBILITY = True
AuthZ
In your app, define the following configuration:
CERN_SYNC_KEYCLOAK_BASE_URL = "<url>"
CERN_SYNC_AUTHZ_BASE_URL = "<url>"
The above CERN_APP_CREDENTIALS configuration must be already configured.
You will also need to make sure that those credentials are allowed to fetch
the entire CERN database of user and groups.
Then, create a new celery task and sync users:
from invenio_cern_sync.users.sync import sync
def sync_users_task():
user_ids = sync(method="AuthZ")
# you can optionally pass extra kwargs for the AuthZ client APIs.
# make sure that you re-index users if needed. For example, in InvenioRDM:
# from invenio_users_resources.services.users.tasks import reindex_users
# reindex_users.delay(user_ids)
To fetch groups:
from invenio_cern_sync.groups.sync import sync
def sync_groups_task():
roles_ids = sync()
LDAP
You can use LDAP instead. Install this module with the ldap extra dependency:
pip install invenio-cern-sync[ldap]
Define the LDAP url:
CERN_SYNC_LDAP_URL = "<url>"
Then, create a new celery task and sync users:
from invenio_cern_sync.users.sync import sync
def sync_users_task():
user_ids = sync(method="LDAP")
# you can optionally pass extra kwargs for the LDAP client APIs.
.. Copyright (C) 2024 CERN.
Invenio-CERN-sync is free software; you can redistribute it and/or modify it
under the terms of the MIT License; see LICENSE file for more details.
Changes
Version 0.3.0 (released 2025-05-05)
- client: replace offset with token #8
Version 0.2.0 (released 2025-03-10)
- installation: upgrade invenio dependencies
Version 0.1.1 (released 2024-11-18)
- users: skip usernames starting with underscore
- groups: limit description to 255 characters
Version 0.1.0 (released 2024-11-13)
- Initial public release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file invenio_cern_sync-0.3.0.tar.gz.
File metadata
- Download URL: invenio_cern_sync-0.3.0.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5930e05c3b6d6949a3b0db87354719156327631a205fd5522f4e7d233c443acb
|
|
| MD5 |
d7ae2382619fc94105f24775dd38e3d9
|
|
| BLAKE2b-256 |
2968fddb16c0b6df5ddc85bb5280c761210ecdceeb3c42c16653bf8ddbe61c02
|
File details
Details for the file invenio_cern_sync-0.3.0-py2.py3-none-any.whl.
File metadata
- Download URL: invenio_cern_sync-0.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 26.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1aca69417b785a26903b64a2c90d7a169f38a1b7c9fe52ca2a1313213f373b2
|
|
| MD5 |
050320cebbd7a319810c5a6dedae2b7c
|
|
| BLAKE2b-256 |
d38aa0418993d752a3a3771c0e756dfea5bd2eee7ba5c8f5a40e1c41b8d528cf
|