2021-04-01 13:39:59 +00:00
import { CryptoApi , FlowDesignationEnum , FlowsApi , ProvidersApi , ProxyProvider } from "authentik-api" ;
2021-04-03 17:26:43 +00:00
import { t } from "@lingui/macro" ;
2021-04-01 13:39:59 +00:00
import { customElement , property } from "lit-element" ;
import { html , TemplateResult } from "lit-html" ;
import { DEFAULT_CONFIG } from "../../../api/Config" ;
import { Form } from "../../../elements/forms/Form" ;
import { until } from "lit-html/directives/until" ;
import { ifDefined } from "lit-html/directives/if-defined" ;
import "../../../elements/forms/HorizontalFormElement" ;
2021-04-03 10:08:35 +00:00
import "../../../elements/forms/FormGroup" ;
import { first } from "../../../utils" ;
2021-04-01 13:39:59 +00:00
@customElement ( "ak-provider-proxy-form" )
export class ProxyProviderFormPage extends Form < ProxyProvider > {
set providerUUID ( value : number ) {
new ProvidersApi ( DEFAULT_CONFIG ) . providersProxyRead ( {
id : value ,
} ) . then ( provider = > {
this . provider = provider ;
} ) ;
}
@property ( { attribute : false } )
provider? : ProxyProvider ;
getSuccessMessage ( ) : string {
if ( this . provider ) {
2021-04-03 17:26:43 +00:00
return t ` Successfully updated provider. ` ;
2021-04-01 13:39:59 +00:00
} else {
2021-04-03 17:26:43 +00:00
return t ` Successfully created provider. ` ;
2021-04-01 13:39:59 +00:00
}
}
send = ( data : ProxyProvider ) : Promise < ProxyProvider > = > {
if ( this . provider ) {
return new ProvidersApi ( DEFAULT_CONFIG ) . providersProxyUpdate ( {
id : this.provider.pk || 0 ,
data : data
} ) ;
} else {
return new ProvidersApi ( DEFAULT_CONFIG ) . providersProxyCreate ( {
data : data
} ) ;
}
} ;
renderForm ( ) : TemplateResult {
return html ` <form class="pf-c-form pf-m-horizontal">
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Name ` }
2021-04-01 13:39:59 +00:00
? required = $ { true }
name = "name" >
< input type = "text" value = "${ifDefined(this.provider?.name)}" class = "pf-c-form-control" required >
< / 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 ` Authorization flow ` }
2021-04-01 13:39:59 +00:00
? required = $ { true }
name = "authorizationFlow" >
< select class = "pf-c-form-control" >
$ { until ( new FlowsApi ( DEFAULT_CONFIG ) . flowsInstancesList ( {
ordering : "pk" ,
designation : FlowDesignationEnum.Authorization ,
} ) . then ( flows = > {
return flows . results . map ( flow = > {
2021-04-02 10:48:09 +00:00
return html ` <option value= ${ ifDefined ( flow . pk ) } ?selected= ${ this . provider ? . authorizationFlow === flow . pk } > ${ flow . name } ( ${ flow . slug } )</option> ` ;
2021-04-01 13:39:59 +00:00
} ) ;
} ) ) }
< / select >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Flow used when authorizing this provider. ` } < / p >
2021-04-01 13:39:59 +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 >
2021-04-03 10:08:35 +00:00
< ak - form - group .expanded = $ { true } >
< span slot = "header" >
2021-04-03 17:26:43 +00:00
$ { t ` Protocol settings ` }
2021-04-03 10:08:35 +00:00
< / span >
< div slot = "body" class = "pf-c-form" >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Internal host ` }
2021-04-03 10:08:35 +00:00
? required = $ { true }
name = "internalHost" >
< input type = "text" value = "${ifDefined(this.provider?.internalHost)}" class = "pf-c-form-control" required >
< / 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 name = "internalHostSslValidation" >
< div class = "pf-c-check" >
< input type = "checkbox" class = "pf-c-check__input" ? checked = $ { first ( this.provider ? .internalHostSslValidation , true ) } >
< label class = "pf-c-check__label" >
2021-04-03 17:26:43 +00:00
$ { t ` Internal host SSL Validation ` }
2021-04-03 10:08:35 +00:00
< / label >
< / div >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Validate SSL Certificates of upstream servers. ` } < / p >
2021-04-03 10:08:35 +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 ` External host ` }
2021-04-03 10:08:35 +00:00
? required = $ { true }
name = "externalHost" >
< input type = "text" value = "${ifDefined(this.provider?.externalHost)}" class = "pf-c-form-control" required >
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
2021-04-01 13:39:59 +00:00
< / div >
2021-04-03 10:08:35 +00:00
< / a k - f o r m - g r o u p >
2021-04-01 13:39:59 +00:00
2021-04-03 10:08:35 +00:00
< ak - form - group >
< span slot = "header" >
2021-04-03 17:26:43 +00:00
$ { t ` Advanced protocol settings ` }
2021-04-03 10:08:35 +00:00
< / span >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Certificate ` }
2021-04-03 10:08:35 +00:00
name = "certificate" >
< select class = "pf-c-form-control" >
$ { until ( new CryptoApi ( DEFAULT_CONFIG ) . cryptoCertificatekeypairsList ( {
ordering : "pk" ,
hasKey : "true" ,
} ) . then ( keys = > {
return keys . results . map ( key = > {
return html ` <option value= ${ ifDefined ( key . pk ) } ?selected= ${ this . provider ? . certificate === key . pk } > ${ key . name } </option> ` ;
} ) ;
} ) ) }
< / select >
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
2021-04-01 13:39:59 +00:00
2021-04-03 10:08:35 +00:00
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Skip path regex ` }
2021-04-03 10:08:35 +00:00
name = "skipPathRegex" >
< textarea class = "pf-c-form-control" > $ { this . provider ? . skipPathRegex } < / textarea >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Regular expressions for which authentication is not required. Each new line is interpreted as a new Regular Expression. ` } < / p >
2021-04-03 10:08:35 +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 >
2021-04-01 13:39:59 +00:00
2021-04-03 10:08:35 +00:00
< ak - form - element - horizontal name = "basicAuthEnabled" >
< div class = "pf-c-check" >
< input type = "checkbox" class = "pf-c-check__input" ? checked = $ { this.provider ? .basicAuthEnabled | | false } >
< label class = "pf-c-check__label" >
2021-04-03 17:26:43 +00:00
$ { t ` Set HTTP-Basic Authentication ` }
2021-04-03 10:08:35 +00:00
< / label >
< / div >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Set a custom HTTP-Basic Authentication header based on values from authentik. ` } < / p >
2021-04-03 10:08:35 +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 ` HTTP-Basic Username Key ` }
2021-04-03 10:08:35 +00:00
name = "basicAuthUserAttribute" >
< input type = "text" value = "${ifDefined(this.provider?.basicAuthUserAttribute)}" class = "pf-c-form-control" >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` User/Group Attribute used for the user part of the HTTP-Basic Header. If not set, the user's Email address is used. ` } < / p >
2021-04-03 10:08:35 +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 ` HTTP-Basic Password Key ` }
2021-04-03 10:08:35 +00:00
name = "basicAuthPasswordAttribute" >
< input type = "text" value = "${ifDefined(this.provider?.basicAuthPasswordAttribute)}" class = "pf-c-form-control" >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` User/Group Attribute used for the password part of the HTTP-Basic Header. ` } < / p >
2021-04-03 10:08:35 +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 >
2021-04-01 13:39:59 +00:00
< / div >
2021-04-03 10:08:35 +00:00
< / a k - f o r m - g r o u p >
2021-04-01 13:39:59 +00:00
< / form > ` ;
}
}