diff --git a/authentik/providers/proxy/api.py b/authentik/providers/proxy/api.py index aa974ab28..8e965e9a3 100644 --- a/authentik/providers/proxy/api.py +++ b/authentik/providers/proxy/api.py @@ -1,6 +1,7 @@ """ProxyProvider API Views""" from typing import Any +from drf_spectacular.types import OpenApiTypes from drf_spectacular.utils import extend_schema_field from rest_framework.exceptions import ValidationError from rest_framework.fields import CharField, ListField, SerializerMethodField @@ -10,6 +11,7 @@ from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet from authentik.core.api.providers import ProviderSerializer from authentik.core.api.used_by import UsedByMixin from authentik.core.api.utils import PassiveSerializer +from authentik.lib.utils.time import timedelta_from_string from authentik.providers.oauth2.views.provider import ProviderInfoView from authentik.providers.proxy.models import ProxyMode, ProxyProvider @@ -106,6 +108,17 @@ class ProxyOutpostConfigSerializer(ModelSerializer): """Proxy provider serializer for outposts""" oidc_configuration = SerializerMethodField() + token_validity = SerializerMethodField() + + @extend_schema_field(OpenIDConnectConfigurationSerializer) + def get_oidc_configuration(self, obj: ProxyProvider): + """Embed OpenID Connect provider information""" + return ProviderInfoView(request=self.context["request"]._request).get_info(obj) + + @extend_schema_field(OpenApiTypes.INT) + def get_token_validity(self, obj: ProxyProvider) -> int: + """Get token validity as second count""" + return timedelta_from_string(obj.token_validity).total_seconds() class Meta: @@ -130,11 +143,6 @@ class ProxyOutpostConfigSerializer(ModelSerializer): "token_validity", ] - @extend_schema_field(OpenIDConnectConfigurationSerializer) - def get_oidc_configuration(self, obj: ProxyProvider): - """Embed OpenID Connect provider information""" - return ProviderInfoView(request=self.context["request"]._request).get_info(obj) - class ProxyOutpostConfigViewSet(ReadOnlyModelViewSet): """ProxyProvider Viewset""" diff --git a/schema.yml b/schema.yml index 989ec2cd9..3b4217381 100644 --- a/schema.yml +++ b/schema.yml @@ -27379,14 +27379,14 @@ components: cookie_domain: type: string token_validity: - type: string - description: 'Tokens not valid on or after current time + this value (Format: - hours=1;minutes=2;seconds=3).' + type: integer + readOnly: true required: - external_host - name - oidc_configuration - pk + - token_validity ProxyProvider: type: object description: ProxyProvider Serializer