mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
[PM-4360] Move auth owned code into auth (#6595)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { DeviceResponse } from "../../abstractions/devices/responses/device.response";
|
||||
import { EncString } from "../../platform/models/domain/enc-string";
|
||||
import { DeviceKey, UserKey } from "../../platform/models/domain/symmetric-crypto-key";
|
||||
import { DeviceResponse } from "../abstractions/devices/responses/device.response";
|
||||
|
||||
export abstract class DeviceTrustCryptoServiceAbstraction {
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DeviceResponse } from "../../abstractions/devices/responses/device.response";
|
||||
import { ListResponse } from "../../models/response/list.response";
|
||||
import { DeviceResponse } from "../abstractions/devices/responses/device.response";
|
||||
import { SecretVerificationRequest } from "../models/request/secret-verification.request";
|
||||
import { UpdateDevicesTrustRequest } from "../models/request/update-devices-trust.request";
|
||||
import { ProtectedDeviceResponse } from "../models/response/protected-device.response";
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { DeviceView } from "./views/device.view";
|
||||
|
||||
export abstract class DevicesServiceAbstraction {
|
||||
getDevices$: () => Observable<Array<DeviceView>>;
|
||||
getDeviceByIdentifier$: (deviceIdentifier: string) => Observable<DeviceView>;
|
||||
isDeviceKnownForUser$: (email: string, deviceIdentifier: string) => Observable<boolean>;
|
||||
updateTrustedDeviceKeys$: (
|
||||
deviceIdentifier: string,
|
||||
devicePublicKeyEncryptedUserKey: string,
|
||||
userKeyEncryptedDevicePublicKey: string,
|
||||
deviceKeyEncryptedDevicePrivateKey: string
|
||||
) => Observable<DeviceView>;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { DeviceType } from "../../../../enums";
|
||||
import { BaseResponse } from "../../../../models/response/base.response";
|
||||
|
||||
export class DeviceResponse extends BaseResponse {
|
||||
id: string;
|
||||
userId: string;
|
||||
name: string;
|
||||
identifier: string;
|
||||
type: DeviceType;
|
||||
creationDate: string;
|
||||
revisionDate: string;
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
this.id = this.getResponseProperty("Id");
|
||||
this.userId = this.getResponseProperty("UserId");
|
||||
this.name = this.getResponseProperty("Name");
|
||||
this.identifier = this.getResponseProperty("Identifier");
|
||||
this.type = this.getResponseProperty("Type");
|
||||
this.creationDate = this.getResponseProperty("CreationDate");
|
||||
this.revisionDate = this.getResponseProperty("RevisionDate");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { DeviceType } from "../../../../enums";
|
||||
import { View } from "../../../../models/view/view";
|
||||
import { DeviceResponse } from "../responses/device.response";
|
||||
|
||||
export class DeviceView implements View {
|
||||
id: string;
|
||||
userId: string;
|
||||
name: string;
|
||||
identifier: string;
|
||||
type: DeviceType;
|
||||
creationDate: string;
|
||||
revisionDate: string;
|
||||
|
||||
constructor(deviceResponse: DeviceResponse) {
|
||||
Object.assign(this, deviceResponse);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { DeviceResponse } from "../../abstractions/devices/responses/device.response";
|
||||
import { AppIdService } from "../../platform/abstractions/app-id.service";
|
||||
import { CryptoFunctionService } from "../../platform/abstractions/crypto-function.service";
|
||||
import { CryptoService } from "../../platform/abstractions/crypto.service";
|
||||
@@ -14,6 +13,7 @@ import {
|
||||
} from "../../platform/models/domain/symmetric-crypto-key";
|
||||
import { CsprngArray } from "../../types/csprng";
|
||||
import { DeviceTrustCryptoServiceAbstraction } from "../abstractions/device-trust-crypto.service.abstraction";
|
||||
import { DeviceResponse } from "../abstractions/devices/responses/device.response";
|
||||
import { DevicesApiServiceAbstraction } from "../abstractions/devices-api.service.abstraction";
|
||||
import { SecretVerificationRequest } from "../models/request/secret-verification.request";
|
||||
import {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { matches, mock } from "jest-mock-extended";
|
||||
|
||||
import { DeviceResponse } from "../../abstractions/devices/responses/device.response";
|
||||
import { DeviceType } from "../../enums";
|
||||
import { EncryptionType } from "../../enums/encryption-type.enum";
|
||||
import { AppIdService } from "../../platform/abstractions/app-id.service";
|
||||
@@ -17,6 +16,7 @@ import {
|
||||
UserKey,
|
||||
} from "../../platform/models/domain/symmetric-crypto-key";
|
||||
import { CsprngArray } from "../../types/csprng";
|
||||
import { DeviceResponse } from "../abstractions/devices/responses/device.response";
|
||||
import { DevicesApiServiceAbstraction } from "../abstractions/devices-api.service.abstraction";
|
||||
import { UpdateDevicesTrustRequest } from "../models/request/update-devices-trust.request";
|
||||
import { ProtectedDeviceResponse } from "../models/response/protected-device.response";
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { ApiService } from "../../abstractions/api.service";
|
||||
import { DeviceResponse } from "../../abstractions/devices/responses/device.response";
|
||||
import { ListResponse } from "../../models/response/list.response";
|
||||
import { Utils } from "../../platform/misc/utils";
|
||||
import { TrustedDeviceKeysRequest } from "../../services/devices/requests/trusted-device-keys.request";
|
||||
import { DeviceResponse } from "../abstractions/devices/responses/device.response";
|
||||
import { DevicesApiServiceAbstraction } from "../abstractions/devices-api.service.abstraction";
|
||||
import { SecretVerificationRequest } from "../models/request/secret-verification.request";
|
||||
import { UpdateDevicesTrustRequest } from "../models/request/update-devices-trust.request";
|
||||
import { ProtectedDeviceResponse } from "../models/response/protected-device.response";
|
||||
|
||||
import { TrustedDeviceKeysRequest } from "./devices/requests/trusted-device-keys.request";
|
||||
|
||||
export class DevicesApiServiceImplementation implements DevicesApiServiceAbstraction {
|
||||
constructor(private apiService: ApiService) {}
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Observable, defer, map } from "rxjs";
|
||||
|
||||
import { ListResponse } from "../../../models/response/list.response";
|
||||
import { DevicesServiceAbstraction } from "../../abstractions/devices/devices.service.abstraction";
|
||||
import { DeviceResponse } from "../../abstractions/devices/responses/device.response";
|
||||
import { DeviceView } from "../../abstractions/devices/views/device.view";
|
||||
import { DevicesApiServiceAbstraction } from "../../abstractions/devices-api.service.abstraction";
|
||||
|
||||
/**
|
||||
* @class DevicesServiceImplementation
|
||||
* @implements {DevicesServiceAbstraction}
|
||||
* @description Observable based data store service for Devices.
|
||||
* note: defer is used to convert the promises to observables and to ensure
|
||||
* that observables are created for each subscription
|
||||
* (i.e., promsise --> observables are cold until subscribed to)
|
||||
*/
|
||||
export class DevicesServiceImplementation implements DevicesServiceAbstraction {
|
||||
constructor(private devicesApiService: DevicesApiServiceAbstraction) {}
|
||||
|
||||
/**
|
||||
* @description Gets the list of all devices.
|
||||
*/
|
||||
getDevices$(): Observable<Array<DeviceView>> {
|
||||
return defer(() => this.devicesApiService.getDevices()).pipe(
|
||||
map((deviceResponses: ListResponse<DeviceResponse>) => {
|
||||
return deviceResponses.data.map((deviceResponse: DeviceResponse) => {
|
||||
return new DeviceView(deviceResponse);
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Gets the device with the specified identifier.
|
||||
*/
|
||||
getDeviceByIdentifier$(deviceIdentifier: string): Observable<DeviceView> {
|
||||
return defer(() => this.devicesApiService.getDeviceByIdentifier(deviceIdentifier)).pipe(
|
||||
map((deviceResponse: DeviceResponse) => new DeviceView(deviceResponse))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Checks if a device is known for a user by user's email and device's identifier.
|
||||
*/
|
||||
isDeviceKnownForUser$(email: string, deviceIdentifier: string): Observable<boolean> {
|
||||
return defer(() => this.devicesApiService.getKnownDevice(email, deviceIdentifier));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Updates the keys for the specified device.
|
||||
*/
|
||||
|
||||
updateTrustedDeviceKeys$(
|
||||
deviceIdentifier: string,
|
||||
devicePublicKeyEncryptedUserKey: string,
|
||||
userKeyEncryptedDevicePublicKey: string,
|
||||
deviceKeyEncryptedDevicePrivateKey: string
|
||||
): Observable<DeviceView> {
|
||||
return defer(() =>
|
||||
this.devicesApiService.updateTrustedDeviceKeys(
|
||||
deviceIdentifier,
|
||||
devicePublicKeyEncryptedUserKey,
|
||||
userKeyEncryptedDevicePublicKey,
|
||||
deviceKeyEncryptedDevicePrivateKey
|
||||
)
|
||||
).pipe(map((deviceResponse: DeviceResponse) => new DeviceView(deviceResponse)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export class TrustedDeviceKeysRequest {
|
||||
constructor(
|
||||
public encryptedUserKey: string,
|
||||
public encryptedPublicKey: string,
|
||||
public encryptedPrivateKey: string
|
||||
) {}
|
||||
}
|
||||
Reference in New Issue
Block a user