2022-09-14 22:05:21 +00:00
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config" ;
2022-12-22 16:03:08 +00:00
import { docLink } from "@goauthentik/common/global" ;
2022-09-14 22:05:21 +00:00
import "@goauthentik/elements/CodeMirror" ;
import "@goauthentik/elements/forms/HorizontalFormElement" ;
import { ModelForm } from "@goauthentik/elements/forms/ModelForm" ;
2022-06-25 15:44:17 +00:00
2021-04-03 17:26:43 +00:00
import { t } from "@lingui/macro" ;
2021-09-21 09:31:37 +00:00
2021-10-28 07:48:51 +00:00
import { TemplateResult , html } from "lit" ;
2021-11-04 21:34:48 +00:00
import { customElement } from "lit/decorators.js" ;
import { ifDefined } from "lit/directives/if-defined.js" ;
2021-09-21 09:31:37 +00:00
2021-10-28 07:48:51 +00:00
import { PropertymappingsApi , SAMLPropertyMapping } from "@goauthentik/api" ;
2021-09-21 09:31:37 +00:00
2021-03-31 21:31:24 +00:00
@customElement ( "ak-property-mapping-saml-form" )
2023-03-06 18:39:08 +00:00
export class PropertyMappingSAMLForm extends ModelForm < SAMLPropertyMapping , string > {
2021-05-11 09:48:34 +00:00
loadInstance ( pk : string ) : Promise < SAMLPropertyMapping > {
2021-05-16 12:43:42 +00:00
return new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsSamlRetrieve ( {
2021-05-11 09:48:34 +00:00
pmUuid : pk ,
2021-03-31 21:31:24 +00:00
} ) ;
}
getSuccessMessage ( ) : string {
2021-05-11 09:48:34 +00:00
if ( this . instance ) {
2021-04-03 17:26:43 +00:00
return t ` Successfully updated mapping. ` ;
2021-03-31 21:31:24 +00:00
} else {
2021-04-03 17:26:43 +00:00
return t ` Successfully created mapping. ` ;
2021-03-31 21:31:24 +00:00
}
}
send = ( data : SAMLPropertyMapping ) : Promise < SAMLPropertyMapping > = > {
2021-05-11 09:48:34 +00:00
if ( this . instance ) {
2021-03-31 21:31:24 +00:00
return new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsSamlUpdate ( {
2021-05-11 09:48:34 +00:00
pmUuid : this.instance.pk || "" ,
2021-08-03 15:52:21 +00:00
sAMLPropertyMappingRequest : data ,
2021-03-31 21:31:24 +00:00
} ) ;
} else {
return new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsSamlCreate ( {
2021-08-03 15:52:21 +00:00
sAMLPropertyMappingRequest : data ,
2021-03-31 21:31:24 +00:00
} ) ;
}
} ;
renderForm ( ) : TemplateResult {
return html ` <form class="pf-c-form pf-m-horizontal">
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Name ` } ? required = $ { true } name = "name" >
< input
type = "text"
value = "${ifDefined(this.instance?.name)}"
class = "pf-c-form-control"
required
/ >
2021-03-31 21:31:24 +00:00
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` SAML Attribute Name ` }
2021-03-31 21:31:24 +00:00
? required = $ { true }
2021-08-03 15:52:21 +00:00
name = "samlName"
>
< input
type = "text"
value = "${ifDefined(this.instance?.samlName)}"
class = "pf-c-form-control"
required
/ >
2021-03-31 21:31:24 +00:00
< p class = "pf-c-form__helper-text" >
2021-04-03 17:26:43 +00:00
$ { t ` Attribute name used for SAML Assertions. Can be a URN OID, a schema reference, or a any other string. If this property mapping is used for NameID Property, this field is discarded. ` }
2021-03-31 21:31:24 +00:00
< / p >
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Friendly Name ` } name = "friendlyName" >
< input
type = "text"
value = "${ifDefined(this.instance?.friendlyName || " ")}"
class = "pf-c-form-control"
/ >
2021-03-31 21:31:24 +00:00
< p class = "pf-c-form__helper-text" >
2021-04-03 17:26:43 +00:00
$ { t ` Optionally set the 'FriendlyName' value of the Assertion attribute. ` }
2021-03-31 21:31:24 +00:00
< / p >
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Expression ` } ? required = $ { true } name = "expression" >
2021-05-11 09:48:34 +00:00
< ak - codemirror mode = "python" value = "${ifDefined(this.instance?.expression)}" >
2021-03-31 21:31:24 +00:00
< / a k - c o d e m i r r o r >
< p class = "pf-c-form__helper-text" >
2021-04-03 18:42:08 +00:00
$ { t ` Expression using Python. ` }
2021-08-03 15:52:21 +00:00
< a
target = "_blank"
2022-12-22 16:03:08 +00:00
href = "${docLink(" / docs / property - mappings / expression ? utm_source = authentik ")}"
2021-08-03 15:52:21 +00:00
>
2021-04-03 18:42:08 +00:00
$ { t ` See documentation for a list of all variables. ` }
< / a >
2021-03-31 21:31:24 +00:00
< / p >
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< / form > ` ;
}
}