mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
feat(web): [PM-1214] add device management screen
Adds a device management tab under settings -> security that allows users to: - View and manage their account's connected devices - Remove/deactivate devices - See device details like platform, last login, and trust status - Sort and filter device list with virtual scrolling Resolves PM-1214
This commit is contained in:
@@ -769,7 +769,10 @@ export default class MainBackground {
|
||||
this.configService,
|
||||
);
|
||||
|
||||
this.devicesService = new DevicesServiceImplementation(this.devicesApiService);
|
||||
this.devicesService = new DevicesServiceImplementation(
|
||||
this.devicesApiService,
|
||||
this.appIdService,
|
||||
);
|
||||
|
||||
this.authRequestService = new AuthRequestService(
|
||||
this.appIdService,
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<bit-container>
|
||||
<div class="tabbed-header">
|
||||
<div class="tw-flex tw-items-center tw-gap-2">
|
||||
<h1>{{ "devices" | i18n }}</h1>
|
||||
<button
|
||||
[bitPopoverTriggerFor]="infoPopover"
|
||||
type="button"
|
||||
class="tw-border-none tw-bg-transparent tw-text-primary-600 tw-flex tw-items-center tw-h-4 tw-w-4"
|
||||
[position]="'right-start'"
|
||||
>
|
||||
<i class="bwi bwi-question-circle" aria-hidden="true"></i>
|
||||
</button>
|
||||
<bit-popover [title]="'whatIsADevice' | i18n" #infoPopover>
|
||||
<p>{{ "aDeviceIs" | i18n }}</p>
|
||||
</bit-popover>
|
||||
<i
|
||||
*ngIf="asyncActionLoading"
|
||||
class="bwi bwi-spinner bwi-spin tw-flex tw-items-center tw-h-4 tw-w-4"
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>{{ "deviceListDescription" | i18n }}</p>
|
||||
|
||||
<div *ngIf="loading" class="tw-flex tw-justify-center tw-items-center tw-p-4">
|
||||
<i class="bwi bwi-spinner bwi-spin tw-text-2xl" aria-hidden="true"></i>
|
||||
</div>
|
||||
|
||||
<bit-table-scroll *ngIf="!loading" [dataSource]="dataSource" [rowSize]="50">
|
||||
<ng-container header>
|
||||
<th
|
||||
*ngFor="let col of columnConfig"
|
||||
[class]="col.headerClass"
|
||||
bitCell
|
||||
[bitSortable]="col.sortable ? col.name : null"
|
||||
[default]="col.name === 'loginStatus' ? 'desc' : null"
|
||||
scope="col"
|
||||
role="columnheader"
|
||||
>
|
||||
{{ col.title }}
|
||||
</th>
|
||||
<th bitCell scope="col" role="columnheader"></th>
|
||||
</ng-container>
|
||||
<ng-template bitRowDef let-row>
|
||||
<td bitCell class="tw-flex tw-gap-2">
|
||||
<div class="tw-flex tw-items-center tw-justify-center tw-w-10">
|
||||
<i [class]="getDeviceIcon(row.type)" class="bwi-lg" aria-hidden="true"></i>
|
||||
</div>
|
||||
<div>
|
||||
{{ row.displayName }}
|
||||
<span *ngIf="row.trusted" class="tw-text-sm tw-text-muted tw-block">
|
||||
{{ "trusted" | i18n }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td bitCell>
|
||||
<span *ngIf="isCurrentDevice(row)" bitBadge variant="primary">{{
|
||||
"currentSession" | i18n
|
||||
}}</span>
|
||||
<span *ngIf="hasPendingAuthRequest(row)" bitBadge variant="warning">{{
|
||||
"requestPending" | i18n
|
||||
}}</span>
|
||||
</td>
|
||||
<td bitCell>{{ row.firstLogin | date: "medium" }}</td>
|
||||
<td bitCell>
|
||||
<button
|
||||
type="button"
|
||||
bitIconButton="bwi-ellipsis-v"
|
||||
[bitMenuTriggerFor]="optionsMenu"
|
||||
></button>
|
||||
<bit-menu #optionsMenu>
|
||||
<button
|
||||
type="button"
|
||||
bitMenuItem
|
||||
(click)="removeDevice(row)"
|
||||
[disabled]="isCurrentDevice(row)"
|
||||
>
|
||||
<span [class]="isCurrentDevice(row) ? 'tw-text-muted' : 'tw-text-danger'">
|
||||
<i class="bwi bwi-trash" aria-hidden="true"></i>
|
||||
{{ "removeDevice" | i18n }}
|
||||
</span>
|
||||
</button>
|
||||
</bit-menu>
|
||||
</td>
|
||||
</ng-template>
|
||||
</bit-table-scroll>
|
||||
</bit-container>
|
||||
@@ -0,0 +1,220 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component } from "@angular/core";
|
||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
import { switchMap } from "rxjs/operators";
|
||||
|
||||
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
|
||||
import { DeviceView } from "@bitwarden/common/auth/abstractions/devices/views/device.view";
|
||||
import { DeviceType, DeviceTypeMetadata } from "@bitwarden/common/enums";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
|
||||
import {
|
||||
DialogService,
|
||||
ToastService,
|
||||
TableDataSource,
|
||||
TableModule,
|
||||
PopoverModule,
|
||||
} from "@bitwarden/components";
|
||||
|
||||
import { SharedModule } from "../../../shared";
|
||||
|
||||
interface DeviceTableData {
|
||||
id: string;
|
||||
type: DeviceType;
|
||||
displayName: string;
|
||||
loginStatus: string;
|
||||
firstLogin: Date;
|
||||
trusted: boolean;
|
||||
devicePendingAuthRequest: object | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a table of devices and allows the user to log out, approve or remove a device
|
||||
*/
|
||||
@Component({
|
||||
selector: "app-device-management",
|
||||
templateUrl: "./device-management.component.html",
|
||||
standalone: true,
|
||||
imports: [CommonModule, SharedModule, TableModule, PopoverModule],
|
||||
})
|
||||
export class DeviceManagementComponent {
|
||||
protected readonly tableId = "device-management-table";
|
||||
protected dataSource = new TableDataSource<DeviceTableData>();
|
||||
protected currentDevice: DeviceView | undefined;
|
||||
protected loading = true;
|
||||
protected asyncActionLoading = false;
|
||||
|
||||
constructor(
|
||||
private i18nService: I18nService,
|
||||
private devicesService: DevicesServiceAbstraction,
|
||||
private dialogService: DialogService,
|
||||
private toastService: ToastService,
|
||||
private validationService: ValidationService,
|
||||
) {
|
||||
this.devicesService
|
||||
.getCurrentDevice$()
|
||||
.pipe(
|
||||
takeUntilDestroyed(),
|
||||
switchMap((currentDevice) => {
|
||||
this.currentDevice = new DeviceView(currentDevice);
|
||||
return this.devicesService.getDevices$();
|
||||
}),
|
||||
)
|
||||
.subscribe({
|
||||
next: (devices) => {
|
||||
this.dataSource.data = devices.map((device) => {
|
||||
return {
|
||||
id: device.id,
|
||||
type: device.type,
|
||||
displayName: this.getHumanReadableDeviceType(device.type),
|
||||
loginStatus: this.getLoginStatus(device),
|
||||
devicePendingAuthRequest: device.response.devicePendingAuthRequest,
|
||||
firstLogin: new Date(device.creationDate),
|
||||
trusted: device.response.isTrusted,
|
||||
};
|
||||
});
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Column configuration for the table
|
||||
*/
|
||||
protected readonly columnConfig = [
|
||||
{
|
||||
name: "displayName",
|
||||
title: this.i18nService.t("device"),
|
||||
headerClass: "tw-w-1/3",
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: "loginStatus",
|
||||
title: this.i18nService.t("loginStatus"),
|
||||
headerClass: "tw-w-1/3",
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: "firstLogin",
|
||||
title: this.i18nService.t("firstLogin"),
|
||||
headerClass: "tw-w-1/3",
|
||||
sortable: true,
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the icon for a device type
|
||||
* @param type - The device type
|
||||
* @returns The icon for the device type
|
||||
*/
|
||||
getDeviceIcon(type: DeviceType): string {
|
||||
const defaultIcon = "bwi bwi-desktop";
|
||||
const categoryIconMap: Record<string, string> = {
|
||||
webVault: "bwi bwi-browser",
|
||||
desktop: "bwi bwi-desktop",
|
||||
mobile: "bwi bwi-mobile",
|
||||
cli: "bwi bwi-cli",
|
||||
extension: "bwi bwi-puzzle",
|
||||
sdk: "bwi bwi-desktop",
|
||||
};
|
||||
|
||||
const metadata = DeviceTypeMetadata[type];
|
||||
return metadata ? (categoryIconMap[metadata.category] ?? defaultIcon) : defaultIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the login status of a device
|
||||
* It will return the current session if the device is the current device
|
||||
* It will return the date of the pending auth request when available
|
||||
* @param device - The device
|
||||
* @returns The login status
|
||||
*/
|
||||
private getLoginStatus(device: DeviceView): string {
|
||||
if (this.isCurrentDevice(device)) {
|
||||
return this.i18nService.t("currentSession");
|
||||
}
|
||||
|
||||
if (device.response.devicePendingAuthRequest?.creationDate) {
|
||||
return this.i18nService.t("requestPending");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a human readable device type from the DeviceType enum
|
||||
* @param type - The device type
|
||||
* @returns The human readable device type
|
||||
*/
|
||||
private getHumanReadableDeviceType(type: DeviceType): string {
|
||||
const metadata = DeviceTypeMetadata[type];
|
||||
if (!metadata) {
|
||||
return this.i18nService.t("unknownDevice");
|
||||
}
|
||||
|
||||
// If the platform is "Unknown" translate it since it is not a proper noun
|
||||
const platform =
|
||||
metadata.platform === "Unknown" ? this.i18nService.t("unknown") : metadata.platform;
|
||||
const category = this.i18nService.t(metadata.category);
|
||||
return platform ? `${category} - ${platform}` : category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a device is the current device
|
||||
* @param device - The device or device table data
|
||||
* @returns True if the device is the current device, false otherwise
|
||||
*/
|
||||
protected isCurrentDevice(device: DeviceView | DeviceTableData): boolean {
|
||||
return "response" in device
|
||||
? device.id === this.currentDevice?.id
|
||||
: device.id === this.currentDevice?.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a device has a pending auth request
|
||||
* @param device - The device
|
||||
* @returns True if the device has a pending auth request, false otherwise
|
||||
*/
|
||||
protected hasPendingAuthRequest(device: DeviceTableData): boolean {
|
||||
return (
|
||||
device.devicePendingAuthRequest !== undefined && device.devicePendingAuthRequest !== null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a device
|
||||
* @param device - The device
|
||||
*/
|
||||
protected async removeDevice(device: DeviceTableData) {
|
||||
const confirmed = await this.dialogService.openSimpleDialog({
|
||||
title: { key: "removeDevice" },
|
||||
content: { key: "removeDeviceConfirmation" },
|
||||
type: "warning",
|
||||
});
|
||||
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.asyncActionLoading = true;
|
||||
await firstValueFrom(this.devicesService.deactivateDevice$(device.id));
|
||||
this.asyncActionLoading = false;
|
||||
|
||||
// Remove the device from the data source
|
||||
this.dataSource.data = this.dataSource.data.filter((d) => d.id !== device.id);
|
||||
|
||||
this.toastService.showToast({
|
||||
title: "",
|
||||
message: this.i18nService.t("deviceRemoved"),
|
||||
variant: "success",
|
||||
});
|
||||
} catch (error) {
|
||||
this.validationService.showError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { RouterModule, Routes } from "@angular/router";
|
||||
import { ChangePasswordComponent } from "../change-password.component";
|
||||
import { TwoFactorSetupComponent } from "../two-factor/two-factor-setup.component";
|
||||
|
||||
import { DeviceManagementComponent } from "./device-management.component";
|
||||
import { SecurityKeysComponent } from "./security-keys.component";
|
||||
import { SecurityComponent } from "./security.component";
|
||||
|
||||
@@ -29,6 +30,11 @@ const routes: Routes = [
|
||||
component: SecurityKeysComponent,
|
||||
data: { titleId: "keys" },
|
||||
},
|
||||
{
|
||||
path: "device-management",
|
||||
component: DeviceManagementComponent,
|
||||
data: { titleId: "devices" },
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<bit-tab-link route="change-password">{{ "masterPassword" | i18n }}</bit-tab-link>
|
||||
</ng-container>
|
||||
<bit-tab-link route="two-factor">{{ "twoStepLogin" | i18n }}</bit-tab-link>
|
||||
<bit-tab-link route="device-management">{{ "devices" | i18n }}</bit-tab-link>
|
||||
<bit-tab-link route="security-keys">{{ "keys" | i18n }}</bit-tab-link>
|
||||
</bit-tab-nav-bar>
|
||||
</app-header>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
|
||||
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-security",
|
||||
@@ -9,7 +10,10 @@ import { UserVerificationService } from "@bitwarden/common/auth/abstractions/use
|
||||
export class SecurityComponent implements OnInit {
|
||||
showChangePassword = true;
|
||||
|
||||
constructor(private userVerificationService: UserVerificationService) {}
|
||||
constructor(
|
||||
private userVerificationService: UserVerificationService,
|
||||
private configService: ConfigService,
|
||||
) {}
|
||||
|
||||
async ngOnInit() {
|
||||
this.showChangePassword = await this.userVerificationService.hasMasterPassword();
|
||||
|
||||
@@ -1128,6 +1128,12 @@
|
||||
"verifyIdentity": {
|
||||
"message": "Verify your Identity"
|
||||
},
|
||||
"whatIsADevice": {
|
||||
"message": "What is a device?"
|
||||
},
|
||||
"aDeviceIs": {
|
||||
"message": "A device is a unique installation of the Bitwarden app where you have logged in. Reinstalling, clearing app data, or clearing your cookies could result in a device appearing multiple times."
|
||||
},
|
||||
"logInInitiated": {
|
||||
"message": "Log in initiated"
|
||||
},
|
||||
@@ -1715,6 +1721,12 @@
|
||||
"logBackIn": {
|
||||
"message": "Please log back in."
|
||||
},
|
||||
"currentSession": {
|
||||
"message": "Current session"
|
||||
},
|
||||
"requestPending": {
|
||||
"message": "Request pending"
|
||||
},
|
||||
"logBackInOthersToo": {
|
||||
"message": "Please log back in. If you are using other Bitwarden applications log out and back in to those as well."
|
||||
},
|
||||
@@ -3765,6 +3777,15 @@
|
||||
"device": {
|
||||
"message": "Device"
|
||||
},
|
||||
"loginStatus": {
|
||||
"message": "Login status"
|
||||
},
|
||||
"firstLogin": {
|
||||
"message": "First login"
|
||||
},
|
||||
"trusted": {
|
||||
"message": "Trusted"
|
||||
},
|
||||
"creatingAccountOn": {
|
||||
"message": "Creating account on"
|
||||
},
|
||||
@@ -8236,6 +8257,18 @@
|
||||
"approveRequest": {
|
||||
"message": "Approve request"
|
||||
},
|
||||
"deviceApproved": {
|
||||
"message": "Device approved"
|
||||
},
|
||||
"deviceRemoved": {
|
||||
"message": "Device removed"
|
||||
},
|
||||
"removeDevice": {
|
||||
"message": "Remove device"
|
||||
},
|
||||
"removeDeviceConfirmation": {
|
||||
"message": "Are you sure you want to remove this device?"
|
||||
},
|
||||
"noDeviceRequests": {
|
||||
"message": "No device requests"
|
||||
},
|
||||
@@ -9939,6 +9972,12 @@
|
||||
"removeMembers": {
|
||||
"message": "Remove members"
|
||||
},
|
||||
"devices": {
|
||||
"message": "Devices"
|
||||
},
|
||||
"deviceListDescription": {
|
||||
"message": "Your account was logged in to each of the devices below. If you do not recognize a device, remove it now."
|
||||
},
|
||||
"claimedDomains": {
|
||||
"message": "Claimed domains"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user