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

@ -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);
}