Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OIDC : Ajout automatique d'un utilisateur dans un accessgroup suivant ses affilation #1257

Open
FBrosset opened this issue Jan 31, 2025 · 0 comments

Comments

@FBrosset
Copy link
Collaborator

L'ajout automatique d'un utilisateur dans un acessgroup est prévu lors d'un authentification CAS ou LDAP mais pas pour OIDC.

Le fichier à modifier est /pod/authentication/backends.py

Ajouts =>
OIDC_CLAIM_AFFILIATION = getattr(settings, "OIDC_CLAIM_AFFILIATION", "affiliations")
class OIDCBackend(OIDCAuthenticationBackend):
def create_user(self, claims):
affiliations = claims.get(OIDC_CLAIM_AFFILIATION, "")
if affiliations:
for affiliation in affiliations:
if CREATE_GROUP_FROM_AFFILIATION:
accessgroup, group_created = AccessGroup.objects.get_or_create(code_name=affiliation)
if group_created:
accessgroup.display_name = affiliation
accessgroup.auto_sync = True
accessgroup.sites.add(Site.objects.get_current())
accessgroup.save()
user.owner.accessgroup_set.add(accessgroup)
else:
user.owner.accessgroup_set.add(accessgroup)
else:
user.owner.affiliation = OIDC_DEFAULT_AFFILIATION
for code_name in OIDC_DEFAULT_ACCESS_GROUP_CODE_NAMES:
try:
user.owner.accessgroup_set.add(AccessGroup.objects.get(code_name=code_name))
except ObjectDoesNotExist:
pass

def update_user(self, user, claims):

if affiliations:
for affiliation in affiliations:
if CREATE_GROUP_FROM_AFFILIATION:
accessgroup, group_created = AccessGroup.objects.get_or_create(code_name=affiliation)
if group_created:
accessgroup.display_name = affiliation
accessgroup.auto_sync = True
accessgroup.sites.add(Site.objects.get_current())
accessgroup.save()
user.owner.accessgroup_set.add(accessgroup)
else:
user.owner.accessgroup_set.add(accessgroup)
else:
user.owner.affiliation = OIDC_DEFAULT_AFFILIATION
for code_name in OIDC_DEFAULT_ACCESS_GROUP_CODE_NAMES:
try:
user.owner.accessgroup_set.add(AccessGroup.objects.get(code_name=code_name))
except ObjectDoesNotExist:
pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant