stages/authenticator_sms: add generic provider (#1595)
* stages/sms: New SMS provider, aka wrapper for outside API * web/pages/authenicator_sms: Conditionally show options based on provider. * stages/authenicator_sms: Fixing up the model. * Whoops * stages/authenicator_sms: Adding supported auth types for Generic provider. * web/pages/stages/authenicator_sms: Added auth type for generic provider * web/pages/stages/authenicator_sms: Fixing up my generic provider options. * stages/authenicator/sms: Working version of generic provider. * stages/authenicator/sms: Cleanup and creating an event on error. * web/ages/stages/authenicator_sms: Made a default for Auth Type and cleaned up the non-needed name attribute. * stages/authenicator_validate: Fixing up the migration as it had no SMS. * stages/authenicator_sms: Removd non-needed migration and better error code handling. * stages/authenicator_sms: Removd non-needed migration and better error code handling. * web/pages/stages/authenicator_sms: Provider default is not empty anymore. Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:

committed by
Jens Langhammer

parent
10fc33f7d3
commit
634375c43f
@ -1,16 +1,17 @@
|
||||
import { t } from "@lingui/macro";
|
||||
|
||||
import { html, TemplateResult } from "lit";
|
||||
import { customElement } from "lit/decorators";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { until } from "lit/directives/until";
|
||||
|
||||
import {
|
||||
FlowsApi,
|
||||
StagesApi,
|
||||
FlowsInstancesListDesignationEnum,
|
||||
AuthenticatorSMSStage,
|
||||
AuthTypeEnum,
|
||||
FlowsApi,
|
||||
FlowsInstancesListDesignationEnum,
|
||||
ProviderEnum,
|
||||
StagesApi,
|
||||
} from "@goauthentik/api";
|
||||
|
||||
import { DEFAULT_CONFIG } from "../../../api/Config";
|
||||
@ -26,6 +27,14 @@ export class AuthenticatorSMSStageForm extends ModelForm<AuthenticatorSMSStage,
|
||||
});
|
||||
}
|
||||
|
||||
@property({ type: Boolean })
|
||||
shouldShowTwilio = false;
|
||||
@property({ type: Boolean })
|
||||
shouldShowGeneric = false;
|
||||
|
||||
@property({ type: Boolean })
|
||||
shouldShowAuthPassword = false;
|
||||
|
||||
getSuccessMessage(): string {
|
||||
if (this.instance) {
|
||||
return t`Successfully updated stage.`;
|
||||
@ -47,6 +56,26 @@ export class AuthenticatorSMSStageForm extends ModelForm<AuthenticatorSMSStage,
|
||||
}
|
||||
};
|
||||
|
||||
onProviderChange(provider: string): void {
|
||||
if (provider === ProviderEnum.Twilio) {
|
||||
this.shouldShowTwilio = true;
|
||||
this.shouldShowGeneric = false;
|
||||
}
|
||||
if (provider === ProviderEnum.Generic) {
|
||||
this.shouldShowGeneric = true;
|
||||
this.shouldShowTwilio = false;
|
||||
}
|
||||
}
|
||||
|
||||
onAuthTypeChange(auth_type: string): void {
|
||||
if (auth_type === AuthTypeEnum.Basic) {
|
||||
this.shouldShowAuthPassword = true;
|
||||
}
|
||||
if (auth_type === AuthTypeEnum.Bearer) {
|
||||
this.shouldShowAuthPassword = false;
|
||||
}
|
||||
}
|
||||
|
||||
renderForm(): TemplateResult {
|
||||
return html`<form class="pf-c-form pf-m-horizontal">
|
||||
<div class="form-help-text">
|
||||
@ -68,13 +97,25 @@ export class AuthenticatorSMSStageForm extends ModelForm<AuthenticatorSMSStage,
|
||||
?required=${true}
|
||||
name="provider"
|
||||
>
|
||||
<select name="users" class="pf-c-form-control">
|
||||
<select
|
||||
class="pf-c-form-control"
|
||||
@change=${(ev: Event) => {
|
||||
const current = (ev.target as HTMLInputElement).value;
|
||||
this.onProviderChange(current);
|
||||
}}
|
||||
>
|
||||
<option
|
||||
value="${ProviderEnum.Twilio}"
|
||||
?selected=${this.instance?.provider === ProviderEnum.Twilio}
|
||||
>
|
||||
${t`Twilio`}
|
||||
</option>
|
||||
<option
|
||||
value="${ProviderEnum.Generic}"
|
||||
?selected=${this.instance?.provider === ProviderEnum.Generic}
|
||||
>
|
||||
${t`Generic`}
|
||||
</option>
|
||||
</select>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
@ -92,14 +133,16 @@ export class AuthenticatorSMSStageForm extends ModelForm<AuthenticatorSMSStage,
|
||||
${t`Number the SMS will be sent from.`}
|
||||
</p>
|
||||
</ak-form-element-horizontal>
|
||||
|
||||
<ak-form-element-horizontal
|
||||
label=${t`Twilio Account SID`}
|
||||
?hidden=${!this.shouldShowTwilio}
|
||||
?required=${true}
|
||||
name="twilioAccountSid"
|
||||
name="accountSid"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
value="${ifDefined(this.instance?.twilioAccountSid || "")}"
|
||||
value="${ifDefined(this.instance?.accountSid || "")}"
|
||||
class="pf-c-form-control"
|
||||
required
|
||||
/>
|
||||
@ -109,12 +152,13 @@ export class AuthenticatorSMSStageForm extends ModelForm<AuthenticatorSMSStage,
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${t`Twilio Auth Token`}
|
||||
?hidden=${!this.shouldShowTwilio}
|
||||
?required=${true}
|
||||
name="twilioAuth"
|
||||
name="auth"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
value="${ifDefined(this.instance?.twilioAuth || "")}"
|
||||
value="${ifDefined(this.instance?.auth || "")}"
|
||||
class="pf-c-form-control"
|
||||
required
|
||||
/>
|
||||
@ -122,6 +166,72 @@ export class AuthenticatorSMSStageForm extends ModelForm<AuthenticatorSMSStage,
|
||||
${t`Get this value from https://console.twilio.com`}
|
||||
</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${t`Auth Type`}
|
||||
?hidden=${!this.shouldShowGeneric}
|
||||
@change=${(ev: Event) => {
|
||||
const current = (ev.target as HTMLInputElement).value;
|
||||
this.onAuthTypeChange(current);
|
||||
}}
|
||||
?required=${true}
|
||||
name="authType"
|
||||
>
|
||||
<select class="pf-c-form-control">
|
||||
<option
|
||||
value="${AuthTypeEnum.Bearer}"
|
||||
?selected=${this.instance?.authType === AuthTypeEnum.Bearer}
|
||||
>
|
||||
${t`Bearer Token`}
|
||||
</option>
|
||||
<option value="${AuthTypeEnum.Basic}">${t`Basic Auth`}</option>
|
||||
</select>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${t`External API URL`}
|
||||
?hidden=${!this.shouldShowGeneric}
|
||||
?required=${true}
|
||||
name="accountSid"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
value="${ifDefined(this.instance?.accountSid || "")}"
|
||||
class="pf-c-form-control"
|
||||
required
|
||||
/>
|
||||
<p class="pf-c-form__helper-text">
|
||||
${t`This is the full endpoint to send POST requests to.`}
|
||||
</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${t`API Auth Username`}
|
||||
?hidden=${!this.shouldShowGeneric}
|
||||
?required=${true}
|
||||
name="auth"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
value="${ifDefined(this.instance?.auth || "")}"
|
||||
class="pf-c-form-control"
|
||||
/>
|
||||
<p class="pf-c-form__helper-text">
|
||||
${t`This is the username to be used with basic auth or the token when used with bearer token`}
|
||||
</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${t`API Auth password`}
|
||||
?hidden=${!this.shouldShowGeneric || !this.shouldShowAuthPassword}
|
||||
?required=${false}
|
||||
name="authPassword"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
value="${ifDefined(this.instance?.authPassword || "null")}"
|
||||
class="pf-c-form-control"
|
||||
/>
|
||||
<p class="pf-c-form__helper-text">
|
||||
${t`This is the password to be used with basic auth`}
|
||||
</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal label=${t`Configuration flow`} name="configureFlow">
|
||||
<select class="pf-c-form-control">
|
||||
<option
|
||||
|
Reference in New Issue
Block a user