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:
Jens Langhammer 2021-04-03 14:47:34 +02:00
parent 66d7d598fb
commit aaa1f92945
7 changed files with 22 additions and 10 deletions

View File

@ -2,6 +2,7 @@ import { gettext } from "django";
import { customElement, html, property, TemplateResult } from "lit-element";
import { EVENT_REFRESH } from "../../constants";
import { ModalButton } from "../buttons/ModalButton";
import "../buttons/SpinnerButton";
import { MessageLevel } from "../messages/Message";
import { showMessage } from "../messages/MessageContainer";

View File

@ -4,6 +4,7 @@ import { EVENT_REFRESH } from "../../constants";
import { ModalButton } from "../buttons/ModalButton";
import { MessageLevel } from "../messages/Message";
import { showMessage } from "../messages/MessageContainer";
import "../buttons/SpinnerButton";
@customElement("ak-forms-delete")
export class DeleteForm extends ModalButton {

View File

@ -3,6 +3,7 @@ import { customElement, html, property, TemplateResult } from "lit-element";
import { EVENT_REFRESH } from "../../constants";
import { ModalButton } from "../buttons/ModalButton";
import { Form } from "./Form";
import "../buttons/SpinnerButton";
@customElement("ak-forms-modal")
export class ModalForm extends ModalButton {

View File

@ -1,4 +1,5 @@
import * as base64js from "base64-js";
import { hexEncode } from "../../../utils";
export function b64enc(buf: Uint8Array): string {
return base64js.fromByteArray(buf)
@ -13,14 +14,6 @@ export function b64RawEnc(buf: Uint8Array): string {
.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
* into byte arrays expected by the navigator.credentials.create() call

View File

@ -8,6 +8,7 @@ import { until } from "lit-html/directives/until";
import { ifDefined } from "lit-html/directives/if-defined";
import "../../../elements/forms/HorizontalFormElement";
import "../../../elements/forms/FormGroup";
import { first, randomString } from "../../../utils";
@customElement("ak-provider-oauth2-form")
export class OAuth2ProviderFormPage extends Form<OAuth2Provider> {
@ -92,12 +93,12 @@ export class OAuth2ProviderFormPage extends Form<OAuth2Provider> {
label=${gettext("Client ID")}
?required=${true}
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
label=${gettext("Client Secret")}
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
label=${gettext("Redirect URIs")}

View File

@ -3,6 +3,7 @@ import { customElement, html, TemplateResult } from "lit-element";
import { DeleteForm } from "../../elements/forms/DeleteForm";
import { MessageLevel } from "../../elements/messages/Message";
import { showMessage } from "../../elements/messages/MessageContainer";
import "../../elements/buttons/SpinnerButton";
@customElement("ak-user-active-form")
export class UserActiveForm extends DeleteForm {

View File

@ -79,3 +79,17 @@ export function first<T>(...args: Array<T | undefined | null>): T {
}
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);
}