Skip to content

Commit c505943

Browse files
committed
Better saml_attribute handling in backend
1 parent 033b16c commit c505943

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

djangosaml2/backends.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ def _get_attribute_value(self, django_field: str, attributes: dict, attribute_ma
9595
for saml_attr, django_fields in attribute_mapping.items():
9696
if django_field in django_fields and saml_attr in attributes:
9797
saml_attribute = attributes.get(saml_attr, [None])
98-
if not saml_attribute or not saml_attribute[0]:
99-
logger.error('attributes[saml_attr] attribute '
100-
'value is missing. Probably the user '
101-
'session is expired.')
102-
return saml_attribute[0]
98+
99+
if saml_attribute:
100+
return saml_attribute[0]
101+
else:
102+
logger.error('attributes[saml_attr] attribute '
103+
'value is missing. Probably the user '
104+
'session is expired.')
103105

104106
def authenticate(self, request, session_info=None, attribute_mapping=None, create_unknown_user=True, **kwargs):
105107
if session_info is None or attribute_mapping is None:

0 commit comments

Comments
 (0)