Skip to content

Commit 12ebd3b

Browse files
core: fix non-expiring service accounts and app passwords (#19913)
core: fix datetime (de)?serialization We aim to fix #19911 in the next patch release, so this commit shouldn't include an API change, which is why we do it a bit awkwardly. Additionally, `serializeForm` has no typechecking for its return value (`return json as unknown as T`), and should be refactored for type safety if at all possible. There are at least two bugs we're solving in this commit: 1. Type checking fails on `serializeForm`, which results in `expires: null` POSTed in a `UserServiceAccountRequest`, where it is not allowed. The backend "correctly" returns a 400. For now we address this by returning `undefined` from `serializeForm` on a `datetime-local` input element when it is unset. 2. The schema allows for `expires: null` in `TokenModel`, but fails with a 500 when that is actually sent. For now we address this with a `None` check. (Note: this bug will not be encountered by the frontend after the change from `null` to `undefined`, but it's still nice to fix.) Both of these issues should eventually be solved by the backend handling `ExpiringModel` in an `ExpiringModelSerializer` instead of the current ad hoc way. Introduced by #19561 Co-authored-by: Simonyi Gergő <gergo@goauthentik.io>
1 parent 7d473d7 commit 12ebd3b

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

authentik/core/api/tokens.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def validate(self, attrs: dict[Any, str]) -> dict[Any, str]:
7575
except ValueError:
7676
pass
7777

78-
if "expires" in attrs and attrs.get("expires") > max_token_lifetime_dt:
78+
expires = attrs.get("expires")
79+
if expires is not None and expires > max_token_lifetime_dt:
7980
raise ValidationError(
8081
{
8182
"expires": (

web/src/elements/forms/Form.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function serializeForm<T = Record<string, unknown>>(elements: Iterable<AK
118118
const valueAsNumber = inputElement.valueAsNumber;
119119
return assignValue(
120120
inputElement,
121-
isNaN(valueAsNumber) ? null : dateToUTC(new Date(valueAsNumber)),
121+
isNaN(valueAsNumber) ? undefined : dateToUTC(new Date(valueAsNumber)),
122122
json,
123123
);
124124
}
@@ -129,7 +129,7 @@ export function serializeForm<T = Record<string, unknown>>(elements: Iterable<AK
129129
const date = new Date(inputElement.value);
130130
return assignValue(
131131
inputElement,
132-
isNaN(date.getTime()) ? null : dateToUTC(date),
132+
isNaN(date.getTime()) ? undefined : dateToUTC(date),
133133
json,
134134
);
135135
}

0 commit comments

Comments
 (0)