Skip to content

Commit 570e08a

Browse files
skorandac00kiemon5ter
authored andcommitted
Support SAML NameID emailAddress and unspecified in response
Add logic that allows support for SAML NameID of types urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified to be sent in the authentication response sent to SAML SPs. This commit does not add any logic to help set the value for the NameID but if it is set, say by a microservice, and if the metadata for the SP specifies one of those types or one of those types is specified by the SP in the authentication request, then this commit allows the value to make it through and be set in the response.
1 parent 1ffac81 commit 570e08a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/satosa/frontends/saml2.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
from saml2.config import IdPConfig
1717
from saml2.extension.ui import NAMESPACE as UI_NAMESPACE
1818
from saml2.metadata import create_metadata_string
19-
from saml2.saml import NameID, NAMEID_FORMAT_TRANSIENT, NAMEID_FORMAT_PERSISTENT
19+
from saml2.saml import NameID, NAMEID_FORMAT_TRANSIENT, \
20+
NAMEID_FORMAT_PERSISTENT, NAMEID_FORMAT_EMAILADDRESS, \
21+
NAMEID_FORMAT_UNSPECIFIED
2022
from saml2.samlp import name_id_policy_from_string
2123
from saml2.server import Server
2224

@@ -45,6 +47,10 @@ def saml_name_id_format_to_hash_type(name_format):
4547
"""
4648
if name_format == NAMEID_FORMAT_PERSISTENT:
4749
return UserIdHashType.persistent
50+
elif name_format == NAMEID_FORMAT_EMAILADDRESS:
51+
return UserIdHashType.emailaddress
52+
elif name_format == NAMEID_FORMAT_UNSPECIFIED:
53+
return UserIdHashType.unspecified
4854

4955
return UserIdHashType.transient
5056

@@ -62,6 +68,11 @@ def hash_type_to_saml_name_id_format(hash_type):
6268
return NAMEID_FORMAT_TRANSIENT
6369
elif hash_type is UserIdHashType.persistent:
6470
return NAMEID_FORMAT_PERSISTENT
71+
elif hash_type is UserIdHashType.emailaddress:
72+
return NAMEID_FORMAT_EMAILADDRESS
73+
elif hash_type is UserIdHashType.unspecified:
74+
return NAMEID_FORMAT_UNSPECIFIED
75+
6576
return NAMEID_FORMAT_PERSISTENT
6677

6778

src/satosa/internal_data.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import hashlib
77
from enum import Enum
88

9-
109
class UserIdHashType(Enum):
1110
"""
1211
All different user id hash types
@@ -15,6 +14,8 @@ class UserIdHashType(Enum):
1514
persistent = 2
1615
pairwise = 3
1716
public = 4
17+
emailaddress = 5
18+
unspecified = 6
1819

1920
@classmethod
2021
def from_string(cls, str):
@@ -88,6 +89,9 @@ def hash_id(salt, user_id, requester, state):
8889
user_id = "{req}{id}".format(req=requester, id=user_id)
8990
elif hash_type == UserIdHashType.public:
9091
user_id = "{id}".format(id=user_id)
92+
elif hash_type == UserIdHashType.emailaddress or \
93+
hash_type == UserIdHashType.unspecified:
94+
return user_id
9195
else:
9296
raise ValueError("Unknown hash type: '{}'".format(hash_type))
9397

0 commit comments

Comments
 (0)