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"""
from typing import Iterable
from django.urls.base import reverse
from django.urls.base import reverse
from drf_spectacular.utils import extend_schema
from rest_framework import mixins
from rest_framework.decorators import action
@ -100,7 +100,8 @@ class StageViewSet(
user_settings.initial_data["object_uid"] = str(stage.pk)
if hasattr(stage, "configure_flow"):
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():
LOGGER.warning(user_settings.errors)

View File

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

View File

@ -1,4 +1,5 @@
"""SAMLSource API Views"""
from django.urls import reverse
from drf_spectacular.utils import extend_schema
from rest_framework.decorators import action
from rest_framework.request import Request
@ -46,4 +47,9 @@ class SAMLSourceViewSet(ModelViewSet):
"""Return metadata as XML string"""
source = self.get_object()
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:
type: string
readOnly: true
download_url:
type: string
readOnly: true
required:
- download_url
- metadata
SAMLPropertyMapping:
type: object

View File

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

View File

@ -23,7 +23,6 @@ import "../../policies/BoundPoliciesList";
import "./SAMLSourceForm";
import { SAMLSource, SourcesApi } from "authentik-api";
import { DEFAULT_CONFIG } from "../../../api/Config";
import { AppURLManager } from "../../../api/legacy";
import { EVENT_REFRESH } from "../../../constants";
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-w-75">
<div class="pf-c-card">
<div class="pf-c-card__body">
${until(new SourcesApi(DEFAULT_CONFIG).sourcesSamlMetadataRetrieve({
slug: this.source.slug,
}).then(m => {
return html`<ak-codemirror mode="xml" ?readOnly=${true} value="${ifDefined(m.metadata)}"></ak-codemirror>`;
})
)}
</div>
<div class="pf-c-card__footer">
<a class="pf-c-button pf-m-primary" target="_blank" href="${AppURLManager.sourceSAML(this.source.slug, "metadata/")}">
${t`Download`}
</a>
</div>
${until(new SourcesApi(DEFAULT_CONFIG).sourcesSamlMetadataRetrieve({
slug: this.source.slug,
}).then(m => {
return html`
<div class="pf-c-card__body">
<ak-codemirror mode="xml" ?readOnly=${true} value="${ifDefined(m.metadata)}"></ak-codemirror>
</div>
<div class="pf-c-card__footer">
<a class="pf-c-button pf-m-primary" target="_blank" href=${ifDefined(m.downloadUrl)}>
${t`Download`}
</a>
</div>
`;
})
)}
</div>
</div>
</div>