sources/saml: include metadata download link in API response

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-06-08 17:22:03 +02:00
parent 75404f1345
commit 029d58191e
6 changed files with 30 additions and 20 deletions

View File

@ -1,7 +1,7 @@
"""Flow Stage API Views""" """Flow Stage API Views"""
from typing import Iterable from typing import Iterable
from django.urls.base import reverse
from django.urls.base import reverse
from drf_spectacular.utils import extend_schema from drf_spectacular.utils import extend_schema
from rest_framework import mixins from rest_framework import mixins
from rest_framework.decorators import action from rest_framework.decorators import action
@ -100,7 +100,8 @@ class StageViewSet(
user_settings.initial_data["object_uid"] = str(stage.pk) user_settings.initial_data["object_uid"] = str(stage.pk)
if hasattr(stage, "configure_flow"): if hasattr(stage, "configure_flow"):
user_settings.initial_data["configure_flow"] = reverse( user_settings.initial_data["configure_flow"] = reverse(
"authentik_flows:configure", kwargs={"stage_uuid": stage.uuid.hex}, "authentik_flows:configure",
kwargs={"stage_uuid": stage.uuid.hex},
) )
if not user_settings.is_valid(): if not user_settings.is_valid():
LOGGER.warning(user_settings.errors) LOGGER.warning(user_settings.errors)

View File

@ -60,6 +60,7 @@ class SAMLMetadataSerializer(PassiveSerializer):
"""SAML Provider Metadata serializer""" """SAML Provider Metadata serializer"""
metadata = ReadOnlyField() metadata = ReadOnlyField()
download_url = ReadOnlyField(required=False)
class SAMLProviderImportSerializer(PassiveSerializer): class SAMLProviderImportSerializer(PassiveSerializer):

View File

@ -1,4 +1,5 @@
"""SAMLSource API Views""" """SAMLSource API Views"""
from django.urls import reverse
from drf_spectacular.utils import extend_schema from drf_spectacular.utils import extend_schema
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.request import Request from rest_framework.request import Request
@ -46,4 +47,9 @@ class SAMLSourceViewSet(ModelViewSet):
"""Return metadata as XML string""" """Return metadata as XML string"""
source = self.get_object() source = self.get_object()
metadata = MetadataProcessor(source, request).build_entity_descriptor() metadata = MetadataProcessor(source, request).build_entity_descriptor()
return Response({"metadata": metadata}) return Response(
{
"metadata": metadata,
"download_url": reverse("authentik_sources_saml:metadata"),
}
)

View File

@ -24313,7 +24313,11 @@ components:
metadata: metadata:
type: string type: string
readOnly: true readOnly: true
download_url:
type: string
readOnly: true
required: required:
- download_url
- metadata - metadata
SAMLPropertyMapping: SAMLPropertyMapping:
type: object type: object

View File

@ -1,8 +1,5 @@
export class AppURLManager { export class AppURLManager {
static sourceSAML(slug: string, rest: string): string {
return `/source/saml/${slug}/${rest}`;
}
static sourceOAuth(slug: string, action: string): string { static sourceOAuth(slug: string, action: string): string {
return `/source/oauth/${action}/${slug}/`; return `/source/oauth/${action}/${slug}/`;
} }

View File

@ -23,7 +23,6 @@ import "../../policies/BoundPoliciesList";
import "./SAMLSourceForm"; import "./SAMLSourceForm";
import { SAMLSource, SourcesApi } from "authentik-api"; import { SAMLSource, SourcesApi } from "authentik-api";
import { DEFAULT_CONFIG } from "../../../api/Config"; import { DEFAULT_CONFIG } from "../../../api/Config";
import { AppURLManager } from "../../../api/legacy";
import { EVENT_REFRESH } from "../../../constants"; import { EVENT_REFRESH } from "../../../constants";
import { ifDefined } from "lit-html/directives/if-defined"; import { ifDefined } from "lit-html/directives/if-defined";
@ -135,19 +134,21 @@ export class SAMLSourceViewPage extends LitElement {
<div class="pf-u-display-flex pf-u-justify-content-center"> <div class="pf-u-display-flex pf-u-justify-content-center">
<div class="pf-u-w-75"> <div class="pf-u-w-75">
<div class="pf-c-card"> <div class="pf-c-card">
<div class="pf-c-card__body">
${until(new SourcesApi(DEFAULT_CONFIG).sourcesSamlMetadataRetrieve({ ${until(new SourcesApi(DEFAULT_CONFIG).sourcesSamlMetadataRetrieve({
slug: this.source.slug, slug: this.source.slug,
}).then(m => { }).then(m => {
return html`<ak-codemirror mode="xml" ?readOnly=${true} value="${ifDefined(m.metadata)}"></ak-codemirror>`; return html`
}) <div class="pf-c-card__body">
)} <ak-codemirror mode="xml" ?readOnly=${true} value="${ifDefined(m.metadata)}"></ak-codemirror>
</div> </div>
<div class="pf-c-card__footer"> <div class="pf-c-card__footer">
<a class="pf-c-button pf-m-primary" target="_blank" href="${AppURLManager.sourceSAML(this.source.slug, "metadata/")}"> <a class="pf-c-button pf-m-primary" target="_blank" href=${ifDefined(m.downloadUrl)}>
${t`Download`} ${t`Download`}
</a> </a>
</div> </div>
`;
})
)}
</div> </div>
</div> </div>
</div> </div>