mirror of
https://github.com/goauthentik/authentik.git
synced 2026-06-18 03:19:51 +03:00
9a44088d2b
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { customElement, property } from "lit-element";
|
|
import { CoreApi } from "authentik-api";
|
|
import { PRIMARY_CLASS, SUCCESS_CLASS } from "../../constants";
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
|
import { ActionButton } from "./ActionButton";
|
|
|
|
@customElement("ak-token-copy-button")
|
|
export class TokenCopyButton extends ActionButton {
|
|
@property()
|
|
identifier?: string;
|
|
|
|
@property()
|
|
buttonClass: string = PRIMARY_CLASS;
|
|
|
|
apiRequest: () => Promise<unknown> = () => {
|
|
this.setLoading();
|
|
if (!this.identifier) {
|
|
return Promise.reject();
|
|
}
|
|
return new CoreApi(DEFAULT_CONFIG).coreTokensViewKeyRetrieve({
|
|
identifier: this.identifier
|
|
}).then((token) => {
|
|
if (!token.key) {
|
|
return Promise.reject();
|
|
}
|
|
return navigator.clipboard.writeText(token.key).then(() => {
|
|
this.buttonClass = SUCCESS_CLASS;
|
|
setTimeout(() => {
|
|
this.buttonClass = PRIMARY_CLASS;
|
|
}, 1500);
|
|
});
|
|
}).catch((err: Response | undefined) => {
|
|
return err?.json().then(errResp => {
|
|
throw new Error(errResp["detail"]);
|
|
});
|
|
});
|
|
}
|
|
|
|
}
|