mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
* Add a button to delete all refresh tokens (#18680) Co-authored-by: Bram Kragten <mail@bramkragten.nl> * Don't delete LL tokens. Don't delete the current token * Update src/data/auth.ts Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com> * typing --------- Co-authored-by: Bram Kragten <mail@bramkragten.nl> Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
This commit is contained in:
parent
42a52f9a1c
commit
86bbff36ea
@ -1,5 +1,6 @@
|
|||||||
import { HaFormSchema } from "../components/ha-form/types";
|
import { HaFormSchema } from "../components/ha-form/types";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
import { RefreshTokenType } from "./refresh_token";
|
||||||
|
|
||||||
export interface AuthUrlSearchParams {
|
export interface AuthUrlSearchParams {
|
||||||
client_id?: string;
|
client_id?: string;
|
||||||
@ -137,7 +138,13 @@ export const adminChangePassword = (
|
|||||||
password,
|
password,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const deleteAllRefreshTokens = (hass: HomeAssistant) =>
|
export const deleteAllRefreshTokens = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
token_type?: RefreshTokenType,
|
||||||
|
delete_current_token?: boolean
|
||||||
|
) =>
|
||||||
hass.callWS({
|
hass.callWS({
|
||||||
type: "auth/delete_all_refresh_tokens",
|
type: "auth/delete_all_refresh_tokens",
|
||||||
|
token_type,
|
||||||
|
delete_current_token,
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,8 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type RefreshTokenType = "normal" | "long_lived_access_token";
|
||||||
|
|
||||||
export interface RefreshToken {
|
export interface RefreshToken {
|
||||||
client_icon?: string;
|
client_icon?: string;
|
||||||
client_id: string;
|
client_id: string;
|
||||||
@ -13,5 +15,5 @@ export interface RefreshToken {
|
|||||||
is_current: boolean;
|
is_current: boolean;
|
||||||
last_used_at?: string;
|
last_used_at?: string;
|
||||||
last_used_ip?: string;
|
last_used_ip?: string;
|
||||||
type: "normal" | "long_lived_access_token";
|
type: RefreshTokenType;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import "../../components/ha-card";
|
|||||||
import "../../components/ha-settings-row";
|
import "../../components/ha-settings-row";
|
||||||
import "../../components/ha-icon-button";
|
import "../../components/ha-icon-button";
|
||||||
import { RefreshToken } from "../../data/refresh_token";
|
import { RefreshToken } from "../../data/refresh_token";
|
||||||
|
import { deleteAllRefreshTokens } from "../../data/auth";
|
||||||
import {
|
import {
|
||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showConfirmationDialog,
|
showConfirmationDialog,
|
||||||
@ -108,6 +109,13 @@ class HaRefreshTokens extends LitElement {
|
|||||||
)
|
)
|
||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card-actions">
|
||||||
|
<mwc-button class="warning" @click=${this._deleteAllTokens}>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.profile.refresh_tokens.delete_all_tokens"
|
||||||
|
)}
|
||||||
|
</mwc-button>
|
||||||
|
</div>
|
||||||
</ha-card>`;
|
</ha-card>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +147,30 @@ class HaRefreshTokens extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _deleteAllTokens(): Promise<void> {
|
||||||
|
if (
|
||||||
|
!(await showConfirmationDialog(this, {
|
||||||
|
text: this.hass.localize(
|
||||||
|
"ui.panel.profile.refresh_tokens.confirm_delete_all"
|
||||||
|
),
|
||||||
|
destructive: true,
|
||||||
|
}))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await deleteAllRefreshTokens(this.hass, "normal", false);
|
||||||
|
fireEvent(this, "hass-refresh-tokens");
|
||||||
|
} catch (err: any) {
|
||||||
|
await showAlertDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.profile.refresh_tokens.delete_failed"
|
||||||
|
),
|
||||||
|
text: err.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
|
@ -5867,6 +5867,8 @@
|
|||||||
"last_used": "Last used {date} from {location}",
|
"last_used": "Last used {date} from {location}",
|
||||||
"not_used": "Has never been used",
|
"not_used": "Has never been used",
|
||||||
"confirm_delete": "Are you sure you want to delete the refresh token for {name}?",
|
"confirm_delete": "Are you sure you want to delete the refresh token for {name}?",
|
||||||
|
"delete_all_tokens": "Delete all tokens",
|
||||||
|
"confirm_delete_all": "Are you sure you want to delete all refresh tokens? Your current session token will not be removed. Your long-lived access tokens will not be removed.",
|
||||||
"delete_failed": "Failed to delete the refresh token.",
|
"delete_failed": "Failed to delete the refresh token.",
|
||||||
"current_token_tooltip": "Unable to delete current refresh token"
|
"current_token_tooltip": "Unable to delete current refresh token"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user