Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/browser/src/background/main.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ import { ProviderService as ProviderServiceAbstraction } from "@bitwarden/common
import { ProviderService } from "@bitwarden/common/provider/services/provider.service";
import { ApiService } from "@bitwarden/common/services/api.service";
import { AuditService } from "@bitwarden/common/services/audit.service";
import { AgentConnectionStateProvider } from "@bitwarden/common/tools/agent-connection/services/agent-connection-state.provider";
import { AgentConnectionService } from "@bitwarden/common/tools/agent-connection/services/agent-connection.service";
import { KeyServiceLegacyEncryptorProvider } from "@bitwarden/common/tools/cryptography/key-service-legacy-encryptor-provider";
import { buildExtensionRegistry } from "@bitwarden/common/tools/extension/factory";
import {
Expand Down Expand Up @@ -1312,6 +1314,15 @@ export default class MainBackground {

this.providerService = new ProviderService(this.stateProvider);

// Agent connections are only populated on sync when the LoginWithBitwarden flag is on; the
// browser does not wire the broker UI (web-only v1) but must still satisfy the sync dependency.
const agentConnectionService = new AgentConnectionService(
this.keyService,
this.encryptService,
this.i18nService,
new AgentConnectionStateProvider(this.stateProvider),
);

this.syncService = new DefaultSyncService(
this.masterPasswordService,
this.accountService,
Expand Down Expand Up @@ -1339,6 +1350,7 @@ export default class MainBackground {
this.stateProvider,
this.configService,
this.sdkService,
agentConnectionService,
);

this.syncServiceListener = new SyncServiceListener(
Expand Down
12 changes: 12 additions & 0 deletions apps/cli/src/service-container/service-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ import { ProviderApiServiceAbstraction } from "@bitwarden/common/provider";
import { ProviderApiService } from "@bitwarden/common/provider/services/provider-api.service";
import { ProviderService } from "@bitwarden/common/provider/services/provider.service";
import { AuditService } from "@bitwarden/common/services/audit.service";
import { AgentConnectionStateProvider } from "@bitwarden/common/tools/agent-connection/services/agent-connection-state.provider";
import { AgentConnectionService } from "@bitwarden/common/tools/agent-connection/services/agent-connection.service";
import { KeyServiceLegacyEncryptorProvider } from "@bitwarden/common/tools/cryptography/key-service-legacy-encryptor-provider";
import { buildExtensionRegistry } from "@bitwarden/common/tools/extension/factory";
import {
Expand Down Expand Up @@ -1069,6 +1071,15 @@ export class ServiceContainer {

this.avatarService = new AvatarService(this.apiService, this.stateProvider);

// Agent connections are only populated on sync when the LoginWithBitwarden flag is on; the CLI
// does not wire the broker UI (web-only v1) but must still satisfy the sync dependency.
const agentConnectionService = new AgentConnectionService(
this.keyService,
this.encryptService,
this.i18nService,
new AgentConnectionStateProvider(this.stateProvider),
);

this.syncService = new DefaultSyncService(
this.masterPasswordService,
this.accountService,
Expand Down Expand Up @@ -1096,6 +1107,7 @@ export class ServiceContainer {
this.stateProvider,
this.configService,
this.sdkService,
agentConnectionService,
);

this.totpService = new TotpService(this.sdkService);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AgentConnectionWithIdRequest } from "@bitwarden/common/tools/agent-connection/models/request/agent-connection-with-id.request";
import { SendWithIdRequest } from "@bitwarden/common/tools/send/models/request/send-with-id.request";
import { CipherWithIdRequest } from "@bitwarden/common/vault/models/request/cipher-with-id.request";
import { FolderWithIdRequest } from "@bitwarden/common/vault/models/request/folder-with-id.request";
Expand All @@ -6,14 +7,17 @@ export class UserDataRequest {
ciphers: CipherWithIdRequest[];
folders: FolderWithIdRequest[];
sends: SendWithIdRequest[];
agentConnections: AgentConnectionWithIdRequest[];

constructor(
ciphers: CipherWithIdRequest[],
folders: FolderWithIdRequest[],
sends: SendWithIdRequest[],
agentConnections: AgentConnectionWithIdRequest[] = [],
) {
this.ciphers = ciphers;
this.folders = folders;
this.sends = sends;
this.agentConnections = agentConnections;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { AgentConnectionService } from "@bitwarden/common/tools/agent-connection/services/agent-connection.service.abstraction";
import { SendWithIdRequest } from "@bitwarden/common/tools/send/models/request/send-with-id.request";
import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction";
import { UserId } from "@bitwarden/common/types/guid";
Expand Down Expand Up @@ -244,6 +245,7 @@ describe("KeyRotationService", () => {
let mockCipherService: MockProxy<CipherService>;
let mockFolderService: MockProxy<FolderService>;
let mockSendService: MockProxy<SendService>;
let mockAgentConnectionService: MockProxy<AgentConnectionService>;
let mockEmergencyAccessService: MockProxy<EmergencyAccessService>;
let mockResetPasswordService: MockProxy<OrganizationUserResetPasswordService>;
let mockDeviceTrustService: MockProxy<DeviceTrustServiceAbstraction>;
Expand Down Expand Up @@ -280,6 +282,8 @@ describe("KeyRotationService", () => {
mockCipherService = mock<CipherService>();
mockFolderService = mock<FolderService>();
mockSendService = mock<SendService>();
mockAgentConnectionService = mock<AgentConnectionService>();
mockAgentConnectionService.getRotatedData.mockResolvedValue([]);
mockEmergencyAccessService = mock<EmergencyAccessService>();
mockEmergencyAccessService.getPublicKeys.mockResolvedValue(
mockTrustedPublicKeys.map((key) => {
Expand Down Expand Up @@ -329,6 +333,7 @@ describe("KeyRotationService", () => {
mockCipherService,
mockFolderService,
mockSendService,
mockAgentConnectionService,
mockEmergencyAccessService,
mockResetPasswordService,
mockDeviceTrustService,
Expand Down Expand Up @@ -945,6 +950,7 @@ describe("KeyRotationService", () => {
ciphers: mockCiphers,
folders: mockFolders,
sends: mockSends,
agentConnections: [],
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
import { asUuid } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { AgentConnectionService } from "@bitwarden/common/tools/agent-connection/services/agent-connection.service.abstraction";
import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction";
import { UserId } from "@bitwarden/common/types/guid";
import { UserKey } from "@bitwarden/common/types/key";
Expand Down Expand Up @@ -66,6 +67,7 @@ export class UserKeyRotationService {
private cipherService: CipherService,
private folderService: FolderService,
private sendService: SendService,
private agentConnectionService: AgentConnectionService,
private emergencyAccessService: EmergencyAccessService,
private resetPasswordService: OrganizationUserResetPasswordService,
private deviceTrustService: DeviceTrustServiceAbstraction,
Expand Down Expand Up @@ -462,7 +464,24 @@ export class UserKeyRotationService {
this.logService.info("[Userkey rotation] ciphers, folders, or sends are null. Aborting!");
throw new Error("ciphers, folders, or sends are null");
}
return new UserDataRequest(rotatedCiphers, rotatedFolders, rotatedSends);

// The agent-access PSK is wrapped with the user key, so each connection must be re-wrapped on
// rotation. Gated behind the feature flag; when off no connections are stored, so this is empty.
let rotatedAgentConnections: Awaited<ReturnType<AgentConnectionService["getRotatedData"]>> = [];
if (await this.configService.getFeatureFlag(FeatureFlag.LoginWithBitwarden)) {
rotatedAgentConnections = await this.agentConnectionService.getRotatedData(
originalUserKey,
newUnencryptedUserKey,
user.id,
);
}

return new UserDataRequest(
rotatedCiphers,
rotatedFolders,
rotatedSends,
rotatedAgentConnections,
);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions apps/web/src/app/layouts/user-layout.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
route="settings/emergency-access"
></bit-nav-item>
}
@if (loginWithBitwardenEnabled()) {
<bit-nav-item
[text]="'loginWithBitwardenConnections' | i18n"
route="settings/agent-connections"
></bit-nav-item>
}
<billing-free-families-nav-item></billing-free-families-nav-item>
<bit-nav-item [text]="'exportNoun' | i18n" route="tools/export"></bit-nav-item>
</bit-nav-group>
Expand Down Expand Up @@ -111,6 +117,12 @@
route="settings/emergency-access"
></bit-nav-item>
}
@if (loginWithBitwardenEnabled()) {
<bit-nav-item
[text]="'loginWithBitwardenConnections' | i18n"
route="settings/agent-connections"
></bit-nav-item>
}
<billing-free-families-nav-item></billing-free-families-nav-item>
</bit-nav-group>
}
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/app/layouts/user-layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export class UserLayoutComponent implements OnInit {
{ initialValue: false },
);

protected readonly loginWithBitwardenEnabled: Signal<boolean> = toSignal(
this.configService.getFeatureFlag$(FeatureFlag.LoginWithBitwarden),
{ initialValue: false },
);

protected readonly singleOrgPolicyApplies = toSignal(
this.accountService.activeAccount$.pipe(
getUserId,
Expand Down
26 changes: 26 additions & 0 deletions apps/web/src/app/oss-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,29 @@ const routes: Routes = [
canActivate: [unauthGuardFn()],
data: { titleId: "deleteOrganization" },
},
// Note: the OAuth completion/broker page is a static connector served at
// /oauth-complete-connector.html (see apps/web/src/connectors/oauth-complete.ts), not an Angular
// route, because it is the registered redirect_uri and must run outside the hash router.
],
},
{
path: "",
component: AnonLayoutWrapperComponent,
children: [
{
path: "oauth/authorize",
canActivate: [canAccessFeature(FeatureFlag.LoginWithBitwarden), deepLinkGuard(), authGuard],
loadComponent: () =>
import("./tools/agent-connection/oauth-authorize.component").then(
(m) => m.OAuthAuthorizeComponent,
),
data: {
pageIcon: UserLockIcon,
titleId: "loginWithBitwarden",
pageTitle: { key: "loginWithBitwarden" },
doNotSaveUrl: true,
} satisfies RouteDataProperties & AnonLayoutWrapperData,
},
{
path: AuthRoute.LoginWithPasskey,
canActivate: [unauthGuardFn()],
Expand Down Expand Up @@ -785,6 +802,15 @@ const routes: Routes = [
path: "security",
loadChildren: () => SecurityRoutingModule,
},
{
path: "agent-connections",
canActivate: [canAccessFeature(FeatureFlag.LoginWithBitwarden)],
loadComponent: () =>
import("./tools/agent-connection/agent-connections.component").then(
(m) => m.AgentConnectionsComponent,
),
data: { titleId: "loginWithBitwardenConnections" } satisfies RouteDataProperties,
},
{
path: "data-recovery",
component: DataRecoveryComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<app-header></app-header>

<bit-container>
<p bitTypography="body1">{{ "loginWithBitwardenConnectionsDescription" | i18n }}</p>

@if (connections$ | async; as connections) {
@if (connections.length === 0) {
<p class="tw-text-muted">{{ "loginWithBitwardenNoConnections" | i18n }}</p>
} @else {
<bit-table>
<ng-container header>
<tr>
<th bitCell>{{ "name" | i18n }}</th>
<th bitCell>{{ "dateCreated" | i18n }}</th>
<th bitCell class="tw-text-right">{{ "options" | i18n }}</th>
</tr>
</ng-container>
<ng-template body>
@for (connection of connections; track connection.id) {
<tr bitRow>
<td bitCell>{{ connection.name }}</td>
<td bitCell>{{ connection.creationDate | date: "medium" }}</td>
<td bitCell class="tw-text-right">
<button
type="button"
bitButton
buttonType="danger"
size="small"
(click)="revoke(connection)"
>
{{ "revoke" | i18n }}
</button>
</td>
</tr>
}
</ng-template>
</bit-table>
}
}
</bit-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Component } from "@angular/core";
import { Observable } from "rxjs";

import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { AgentConnectionView } from "@bitwarden/common/tools/agent-connection/models/view/agent-connection.view";
import { AgentConnectionApiService } from "@bitwarden/common/tools/agent-connection/services/agent-connection-api.service.abstraction";
import { InternalAgentConnectionService } from "@bitwarden/common/tools/agent-connection/services/agent-connection.service.abstraction";
import { DialogService, ToastService } from "@bitwarden/components";

import { HeaderModule } from "../../layouts/header/header.module";
import { SharedModule } from "../../shared";

/**
* Settings page listing the user's "Login with Bitwarden" agent connections with a revoke action.
* Revoking deletes the connection server-side (which pushes to the user's other clients) and from
* local state; the bot's short-lived token then expires on its own (no refresh).
*/
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AgentConnectionsComponent change-detection migration is marked FIXME; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment marks the component's change-detection migration as unfinished. A tracker link alone does not specify the remaining work or criteria for completion.

πŸ”§ How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
@Component({
imports: [SharedModule, HeaderModule],
templateUrl: "agent-connections.component.html",
})
export class AgentConnectionsComponent {
protected connections$: Observable<AgentConnectionView[]> =
this.agentConnectionService.agentConnectionViews$;

constructor(
private agentConnectionService: InternalAgentConnectionService,
private agentConnectionApiService: AgentConnectionApiService,
private dialogService: DialogService,
private i18nService: I18nService,
private toastService: ToastService,
) {}

async revoke(connection: AgentConnectionView): Promise<void> {
const confirmed = await this.dialogService.openSimpleDialog({
title: { key: "loginWithBitwardenRevokeTitle" },
content: { key: "loginWithBitwardenRevokeConfirm", placeholders: [connection.name] },
type: "warning",
acceptButtonText: { key: "revoke" },
});
if (!confirmed) {
return;
}

await this.agentConnectionApiService.delete(connection.id);
await this.agentConnectionService.delete(connection.id);
this.toastService.showToast({
variant: "success",
message: this.i18nService.t("loginWithBitwardenRevoked"),
});
}
}
Loading
Loading