Skip to content

Commit b5e791e

Browse files
✨ [#3967] Add 'auth_context_branch_number' static variable
For eherkenning authentication, this will contain the branch number that the employee is authenticated/authorized for.
1 parent b3dbcc6 commit b5e791e

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

docs/manual/forms/variables.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ authenticatiecontextdatamodel_. De structuur is als volgt:
112112
"authorizee": {
113113
"legalSubject": {
114114
"identifierType": "string",
115-
"identifier": "string"
115+
"identifier": "string",
116+
"branchNumber": "string"
116117
},
117118
"actingSubject": {
118119
"identifierType": "string",
@@ -169,6 +170,10 @@ De onderdelen van deze structuur worden ook als individuele variabelen aangebode
169170
Identificatie van de (wettelijke) vertegenwoordiger. Leeg indien het formulier
170171
zonder inloggen gestart is.
171172

173+
``auth_context_branch_number``
174+
Vestigingsnummer waarvoor de medewerker ingelogd is. Leeg indien het geen
175+
eHerkenning-login betreft.
176+
172177
``auth_context_acting_subject_identifier_type``
173178
In de praktijk zal de waarde altijd ``opaque`` of leeg zijn. Geeft aan hoe de
174179
identificatie van de handelende persoon ("de persoon aan de knoppen")

src/openforms/authentication/static_variables/static_variables.py

+15
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
192192
return auth_context["authorizee"]["legalSubject"]["identifier"]
193193

194194

195+
@register_static_variable("auth_context_branch_number")
196+
class AuthContextBranchNumber(BaseStaticVariable):
197+
name = _("Authentication context data: branch number")
198+
data_type = FormVariableDataTypes.string
199+
200+
def get_initial_value(self, submission: Submission | None = None) -> str:
201+
if submission is None or not submission.is_authenticated:
202+
return ""
203+
auth_context = submission.auth_info.to_auth_context_data()
204+
if auth_context["source"] != "eherkenning":
205+
return ""
206+
legal_subject = auth_context["authorizee"]["legalSubject"]
207+
return legal_subject.get("branchNumber", "")
208+
209+
195210
@register_static_variable("auth_context_acting_subject_identifier_type")
196211
class AuthContextActingSubjectIdentifierType(BaseStaticVariable):
197212
name = _("Authentication context data: authorizee, acting subject identifier type")

src/openforms/authentication/tests/test_static_variables.py

+59
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,62 @@ def test_language_code_variable(self):
7777
}
7878

7979
self.assertEqual(static_data["language_code"], "nl")
80+
81+
def test_branch_number_variable(self):
82+
cases = (
83+
(
84+
AuthInfoFactory.create(
85+
is_digid=True,
86+
legal_subject_service_restriction="foo",
87+
),
88+
"",
89+
),
90+
(
91+
AuthInfoFactory.create(
92+
is_digid_machtigen=True,
93+
legal_subject_service_restriction="foo",
94+
),
95+
"",
96+
),
97+
(
98+
AuthInfoFactory.create(
99+
is_eh=True,
100+
legal_subject_service_restriction="123456789012",
101+
),
102+
"123456789012",
103+
),
104+
(
105+
AuthInfoFactory.create(
106+
is_eh_bewindvoering=True,
107+
legal_subject_service_restriction="123456789012",
108+
),
109+
"123456789012",
110+
),
111+
(
112+
AuthInfoFactory.create(
113+
is_eh=True,
114+
legal_subject_service_restriction="",
115+
),
116+
"",
117+
),
118+
(
119+
AuthInfoFactory.create(
120+
is_eh_bewindvoering=True,
121+
legal_subject_service_restriction="",
122+
),
123+
"",
124+
),
125+
)
126+
for auth_info, expected in cases:
127+
with self.subTest(
128+
attribute=auth_info.attribute,
129+
service_restriction=auth_info.legal_subject_service_restriction,
130+
):
131+
static_data = {
132+
variable.key: variable.initial_value
133+
for variable in get_static_variables(
134+
submission=auth_info.submission
135+
)
136+
}
137+
138+
self.assertEqual(static_data["auth_context_branch_number"], expected)

0 commit comments

Comments
 (0)