Skip to content

Commit

Permalink
✨ [#4980] Add json schema definition to static variables
Browse files Browse the repository at this point in the history
The schema for the registration variables are left out for now, as they can't be selected in the JSON dump plugin options
  • Loading branch information
viktorvanwijk committed Jan 8, 2025
1 parent 47e1ef1 commit e7df98f
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 1 deletion.
162 changes: 162 additions & 0 deletions src/openforms/authentication/static_variables/static_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class SubmissionID(BaseStaticVariable):
def get_initial_value(self, submission: Submission | None = None) -> str:
return str(submission.uuid) if submission else ""

@staticmethod
def as_json_schema():
return {
"title": "Submission identifier",
"description": "UUID of the submission",
"type": "string",
"format": "uuid",
}


@register_static_variable("language_code")
class LanguageCode(BaseStaticVariable):
Expand All @@ -32,6 +41,14 @@ class LanguageCode(BaseStaticVariable):
def get_initial_value(self, submission: Submission | None = None) -> str:
return submission.language_code if submission else ""

@staticmethod
def as_json_schema():
return {
"title": "Language code",
"description": "Abbreviation of the used langauge.",
"type": "string",
}


@register_static_variable("auth")
class Auth(BaseStaticVariable):
Expand All @@ -52,6 +69,11 @@ def get_initial_value(

return auth_data

@staticmethod
def as_json_schema():
# NOTE: this has been made 'vague' on purpose, see the comment on AuthContext.
return {"title": "Authentication summary", "type": "object"}


@register_static_variable("auth_type")
class AuthType(BaseStaticVariable):
Expand All @@ -63,6 +85,22 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
return ""
return submission.auth_info.attribute

@staticmethod
def as_json_schema():
return {
"title": "Authentication type",
# "description": "Type of authentication set for the form",
"type": "string",
# TODO-4980: add enum? If yes, need to convert to string or will it happen
# automatically when sending the data.
"enum": [
str(AuthAttribute.bsn),
str(AuthAttribute.kvk),
str(AuthAttribute.pseudo),
str(AuthAttribute.employee_id),
],
}


def get_auth_value(submission: Submission | None, attribute: AuthAttribute) -> str:
if not submission or not submission.is_authenticated:
Expand All @@ -82,6 +120,19 @@ class AuthBSN(BaseStaticVariable):
def get_initial_value(self, submission: Submission | None = None) -> str:
return get_auth_value(submission, AuthAttribute.bsn)

@staticmethod
def as_json_schema():
return {
"title": "BSN",
"description": (
"Uniquely identifies the authenticated person. This value follows the "
"rules for Dutch social security numbers."
),
"type": "string",
"pattern": "^\\d{9}$",
"format": "nl-bsn",
}


@register_static_variable("auth_kvk")
class AuthKvK(BaseStaticVariable):
Expand All @@ -91,6 +142,19 @@ class AuthKvK(BaseStaticVariable):
def get_initial_value(self, submission: Submission | None = None) -> str:
return get_auth_value(submission, AuthAttribute.kvk)

@staticmethod
def as_json_schema():
return {
"title": "KVK",
"description": (
"Chamber of commerce number (KVK-nummer) that uniquely identifies the "
"company."
),
"type": "string",
"pattern": "^\\d{8}$",
"format": "urn:etoegang:1.9:EntityConcernedID:KvKnr",
}


@register_static_variable("auth_pseudo")
class AuthPseudo(BaseStaticVariable):
Expand All @@ -100,6 +164,11 @@ class AuthPseudo(BaseStaticVariable):
def get_initial_value(self, submission: Submission | None = None) -> str:
return get_auth_value(submission, AuthAttribute.pseudo)

@staticmethod
def as_json_schema():
# TODO-4980: what is this and does it have a pattern?
return {"type": "string", "format": "eIDAS"}


@register_static_variable("auth_context")
class AuthContext(BaseStaticVariable):
Expand All @@ -113,6 +182,20 @@ def get_initial_value(self, submission: Submission | None = None):
return None
return submission.auth_info.to_auth_context_data()

@staticmethod
def as_json_schema():
# NOTE: `auth_context` includes all relevant options for the authentication
# plugin, which means its values are plugin dependent. Therefore, to discourage
# users from using this, no specific object information will be provided here.
# Instead, variables like `auth_bsn` and `auth_kvk` should be used for
# extracting information about authentication (they are strictly defined with a
# schema)
return {
"title": "Authentication options",
"description": "Options for the selected authentication plugin",
"type": "object",
}


@register_static_variable("auth_context_source")
class AuthContextSource(BaseStaticVariable):
Expand All @@ -125,6 +208,14 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
auth_context = submission.auth_info.to_auth_context_data()
return auth_context["source"]

@staticmethod
def as_json_schema():
return {
"title": "Authentication source",
"description": "Name of the authentication source",
"type": "string",
}


@register_static_variable("auth_context_loa")
class AuthContextLOA(BaseStaticVariable):
Expand All @@ -137,6 +228,18 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
auth_context = submission.auth_info.to_auth_context_data()
return auth_context["levelOfAssurance"]

@staticmethod
def as_json_schema():
return {
"title": "Authentication level of assurance",
"description": (
"afsprakenstelsel.etoegang.nl defines the available levels of "
"assurance *and* prescribes what the minimum level must be. Note that "
"a minimum of loa2plus is required these days."
),
"type": "string",
}


@register_static_variable("auth_context_representee_identifier_type")
class AuthContextRepresenteeType(BaseStaticVariable):
Expand All @@ -151,6 +254,14 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
return ""
return auth_context["representee"]["identifierType"]

@staticmethod
def as_json_schema():
return {
"title": "Representee authentication type",
"description": "Authentication type of the representee",
"type": "string",
}


@register_static_variable("auth_context_representee_identifier")
class AuthContextRepresenteeIdentifier(BaseStaticVariable):
Expand All @@ -165,6 +276,14 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
return ""
return auth_context["representee"]["identifier"]

@staticmethod
def as_json_schema():
return {
"title": "Representee authentication identifier",
"description": "Authentication identifier of the representee.",
"type": "string",
}


@register_static_variable("auth_context_legal_subject_identifier_type")
class AuthContextLegalSubjectIdentifierType(BaseStaticVariable):
Expand All @@ -177,6 +296,17 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
auth_context = submission.auth_info.to_auth_context_data()
return auth_context["authorizee"]["legalSubject"]["identifierType"]

@staticmethod
def as_json_schema():
return {
"title": "Legal subject authentication type",
"description": (
"Authentication type of the legal subject (mandated to act on behalf "
"of the representee)",
),
"type": "string",
}


@register_static_variable("auth_context_legal_subject_identifier")
class AuthContextLegalSubjectIdentifier(BaseStaticVariable):
Expand All @@ -189,6 +319,17 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
auth_context = submission.auth_info.to_auth_context_data()
return auth_context["authorizee"]["legalSubject"]["identifier"]

@staticmethod
def as_json_schema():
return {
"title": "Legal subject authentication identifier",
"description": (
"Authentication identifier of the legal subject (mandated to act on "
"behalf of the representee)",
),
"type": "string",
}


@register_static_variable("auth_context_branch_number")
class AuthContextBranchNumber(BaseStaticVariable):
Expand All @@ -204,6 +345,17 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
legal_subject = auth_context["authorizee"]["legalSubject"]
return legal_subject.get("branchNumber", "")

@staticmethod
def as_json_schema():
return {
"title": "Authentication branch number",
"description": (
"The branch number imposes a restriction on the acting subject - it is "
"limited to act only on this particular branch of the legal subject."
),
"type": "string",
}


@register_static_variable("auth_context_acting_subject_identifier_type")
class AuthContextActingSubjectIdentifierType(BaseStaticVariable):
Expand All @@ -218,6 +370,11 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
return ""
return auth_context["authorizee"]["actingSubject"]["identifierType"]

@staticmethod
def as_json_schema():
# TODO-4980: description?
return {"title": "Acting subject authentication type", "type": "string"}


@register_static_variable("auth_context_acting_subject_identifier")
class AuthContextActingSubjectIdentifier(BaseStaticVariable):
Expand All @@ -231,3 +388,8 @@ def get_initial_value(self, submission: Submission | None = None) -> str:
if "actingSubject" not in auth_context["authorizee"]:
return ""
return auth_context["authorizee"]["actingSubject"]["identifier"]

@staticmethod
def as_json_schema():
# TODO-4980: desctiption?
return {"title": "Acting subject authentication identifier", "type": "string"}
Loading

0 comments on commit e7df98f

Please sign in to comment.