providers/proxy: return token_validity as total seconds instead of expression

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-25 15:44:16 +02:00
parent 4dcb15af46
commit f7408626a8
2 changed files with 16 additions and 8 deletions

View file

@ -1,6 +1,7 @@
"""ProxyProvider API Views""" """ProxyProvider API Views"""
from typing import Any from typing import Any
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema_field from drf_spectacular.utils import extend_schema_field
from rest_framework.exceptions import ValidationError from rest_framework.exceptions import ValidationError
from rest_framework.fields import CharField, ListField, SerializerMethodField 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.providers import ProviderSerializer
from authentik.core.api.used_by import UsedByMixin from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import PassiveSerializer 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.oauth2.views.provider import ProviderInfoView
from authentik.providers.proxy.models import ProxyMode, ProxyProvider from authentik.providers.proxy.models import ProxyMode, ProxyProvider
@ -106,6 +108,17 @@ class ProxyOutpostConfigSerializer(ModelSerializer):
"""Proxy provider serializer for outposts""" """Proxy provider serializer for outposts"""
oidc_configuration = SerializerMethodField() 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: class Meta:
@ -130,11 +143,6 @@ class ProxyOutpostConfigSerializer(ModelSerializer):
"token_validity", "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): class ProxyOutpostConfigViewSet(ReadOnlyModelViewSet):
"""ProxyProvider Viewset""" """ProxyProvider Viewset"""

View file

@ -27379,14 +27379,14 @@ components:
cookie_domain: cookie_domain:
type: string type: string
token_validity: token_validity:
type: string type: integer
description: 'Tokens not valid on or after current time + this value (Format: readOnly: true
hours=1;minutes=2;seconds=3).'
required: required:
- external_host - external_host
- name - name
- oidc_configuration - oidc_configuration
- pk - pk
- token_validity
ProxyProvider: ProxyProvider:
type: object type: object
description: ProxyProvider Serializer description: ProxyProvider Serializer