web/admin/providers/oauth2: add generated defaults for clientId and secret
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
66d7d598fb
commit
aaa1f92945
|
@ -2,6 +2,7 @@ import { gettext } from "django";
|
||||||
import { customElement, html, property, TemplateResult } from "lit-element";
|
import { customElement, html, property, TemplateResult } from "lit-element";
|
||||||
import { EVENT_REFRESH } from "../../constants";
|
import { EVENT_REFRESH } from "../../constants";
|
||||||
import { ModalButton } from "../buttons/ModalButton";
|
import { ModalButton } from "../buttons/ModalButton";
|
||||||
|
import "../buttons/SpinnerButton";
|
||||||
import { MessageLevel } from "../messages/Message";
|
import { MessageLevel } from "../messages/Message";
|
||||||
import { showMessage } from "../messages/MessageContainer";
|
import { showMessage } from "../messages/MessageContainer";
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { EVENT_REFRESH } from "../../constants";
|
||||||
import { ModalButton } from "../buttons/ModalButton";
|
import { ModalButton } from "../buttons/ModalButton";
|
||||||
import { MessageLevel } from "../messages/Message";
|
import { MessageLevel } from "../messages/Message";
|
||||||
import { showMessage } from "../messages/MessageContainer";
|
import { showMessage } from "../messages/MessageContainer";
|
||||||
|
import "../buttons/SpinnerButton";
|
||||||
|
|
||||||
@customElement("ak-forms-delete")
|
@customElement("ak-forms-delete")
|
||||||
export class DeleteForm extends ModalButton {
|
export class DeleteForm extends ModalButton {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { customElement, html, property, TemplateResult } from "lit-element";
|
||||||
import { EVENT_REFRESH } from "../../constants";
|
import { EVENT_REFRESH } from "../../constants";
|
||||||
import { ModalButton } from "../buttons/ModalButton";
|
import { ModalButton } from "../buttons/ModalButton";
|
||||||
import { Form } from "./Form";
|
import { Form } from "./Form";
|
||||||
|
import "../buttons/SpinnerButton";
|
||||||
|
|
||||||
@customElement("ak-forms-modal")
|
@customElement("ak-forms-modal")
|
||||||
export class ModalForm extends ModalButton {
|
export class ModalForm extends ModalButton {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as base64js from "base64-js";
|
import * as base64js from "base64-js";
|
||||||
|
import { hexEncode } from "../../../utils";
|
||||||
|
|
||||||
export function b64enc(buf: Uint8Array): string {
|
export function b64enc(buf: Uint8Array): string {
|
||||||
return base64js.fromByteArray(buf)
|
return base64js.fromByteArray(buf)
|
||||||
|
@ -13,14 +14,6 @@ export function b64RawEnc(buf: Uint8Array): string {
|
||||||
.replace(/\//g, "_");
|
.replace(/\//g, "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hexEncode(buf: Uint8Array): string {
|
|
||||||
return Array.from(buf)
|
|
||||||
.map(function (x) {
|
|
||||||
return ("0" + x.toString(16)).substr(-2);
|
|
||||||
})
|
|
||||||
.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms items in the credentialCreateOptions generated on the server
|
* Transforms items in the credentialCreateOptions generated on the server
|
||||||
* into byte arrays expected by the navigator.credentials.create() call
|
* into byte arrays expected by the navigator.credentials.create() call
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { until } from "lit-html/directives/until";
|
||||||
import { ifDefined } from "lit-html/directives/if-defined";
|
import { ifDefined } from "lit-html/directives/if-defined";
|
||||||
import "../../../elements/forms/HorizontalFormElement";
|
import "../../../elements/forms/HorizontalFormElement";
|
||||||
import "../../../elements/forms/FormGroup";
|
import "../../../elements/forms/FormGroup";
|
||||||
|
import { first, randomString } from "../../../utils";
|
||||||
|
|
||||||
@customElement("ak-provider-oauth2-form")
|
@customElement("ak-provider-oauth2-form")
|
||||||
export class OAuth2ProviderFormPage extends Form<OAuth2Provider> {
|
export class OAuth2ProviderFormPage extends Form<OAuth2Provider> {
|
||||||
|
@ -92,12 +93,12 @@ export class OAuth2ProviderFormPage extends Form<OAuth2Provider> {
|
||||||
label=${gettext("Client ID")}
|
label=${gettext("Client ID")}
|
||||||
?required=${true}
|
?required=${true}
|
||||||
name="clientId">
|
name="clientId">
|
||||||
<input type="text" value="${ifDefined(this.provider?.clientId)}" class="pf-c-form-control" required>
|
<input type="text" value="${first(this.provider?.clientId, randomString(40))}" class="pf-c-form-control" required>
|
||||||
</ak-form-element-horizontal>
|
</ak-form-element-horizontal>
|
||||||
<ak-form-element-horizontal
|
<ak-form-element-horizontal
|
||||||
label=${gettext("Client Secret")}
|
label=${gettext("Client Secret")}
|
||||||
name="clientSecret">
|
name="clientSecret">
|
||||||
<input type="text" value="${ifDefined(this.provider?.clientSecret /* TODO: Generate secret */)}" class="pf-c-form-control">
|
<input type="text" value="${first(this.provider?.clientSecret, randomString(128))}" class="pf-c-form-control">
|
||||||
</ak-form-element-horizontal>
|
</ak-form-element-horizontal>
|
||||||
<ak-form-element-horizontal
|
<ak-form-element-horizontal
|
||||||
label=${gettext("Redirect URIs")}
|
label=${gettext("Redirect URIs")}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { customElement, html, TemplateResult } from "lit-element";
|
||||||
import { DeleteForm } from "../../elements/forms/DeleteForm";
|
import { DeleteForm } from "../../elements/forms/DeleteForm";
|
||||||
import { MessageLevel } from "../../elements/messages/Message";
|
import { MessageLevel } from "../../elements/messages/Message";
|
||||||
import { showMessage } from "../../elements/messages/MessageContainer";
|
import { showMessage } from "../../elements/messages/MessageContainer";
|
||||||
|
import "../../elements/buttons/SpinnerButton";
|
||||||
|
|
||||||
@customElement("ak-user-active-form")
|
@customElement("ak-user-active-form")
|
||||||
export class UserActiveForm extends DeleteForm {
|
export class UserActiveForm extends DeleteForm {
|
||||||
|
|
|
@ -79,3 +79,17 @@ export function first<T>(...args: Array<T | undefined | null>): T {
|
||||||
}
|
}
|
||||||
throw new Error(`No compatible arg given: ${args}`);
|
throw new Error(`No compatible arg given: ${args}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hexEncode(buf: Uint8Array): string {
|
||||||
|
return Array.from(buf)
|
||||||
|
.map(function (x) {
|
||||||
|
return ("0" + x.toString(16)).substr(-2);
|
||||||
|
})
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function randomString(len: number): string {
|
||||||
|
const arr = new Uint8Array(len / 2);
|
||||||
|
window.crypto.getRandomValues(arr);
|
||||||
|
return hexEncode(arr);
|
||||||
|
}
|
||||||
|
|
Reference in New Issue