mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
Migrate auth abstract services to strict ts (#15732)
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
|
||||||
// @ts-strict-ignore
|
|
||||||
import { UserId } from "@bitwarden/common/types/guid";
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
import { MasterKey } from "@bitwarden/common/types/key";
|
import { MasterKey } from "@bitwarden/common/types/key";
|
||||||
import { KdfConfig } from "@bitwarden/key-management";
|
import { KdfConfig } from "@bitwarden/key-management";
|
||||||
@@ -31,5 +29,5 @@ export abstract class SetPasswordJitService {
|
|||||||
* @throws If any property on the `credentials` object is null or undefined, or if a protectedUserKey
|
* @throws If any property on the `credentials` object is null or undefined, or if a protectedUserKey
|
||||||
* or newKeyPair could not be created.
|
* or newKeyPair could not be created.
|
||||||
*/
|
*/
|
||||||
setPassword: (credentials: SetPasswordCredentials) => Promise<void>;
|
abstract setPassword(credentials: SetPasswordCredentials): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
|
||||||
// @ts-strict-ignore
|
|
||||||
import { Observable } from "rxjs";
|
import { Observable } from "rxjs";
|
||||||
|
|
||||||
import { AdminAuthRequestStorable } from "@bitwarden/common/auth/models/domain/admin-auth-req-storable";
|
import { AdminAuthRequestStorable } from "@bitwarden/common/auth/models/domain/admin-auth-req-storable";
|
||||||
@@ -10,20 +8,20 @@ import { UserKey, MasterKey } from "@bitwarden/common/types/key";
|
|||||||
|
|
||||||
export abstract class AuthRequestServiceAbstraction {
|
export abstract class AuthRequestServiceAbstraction {
|
||||||
/** Emits an auth request id when an auth request has been approved. */
|
/** Emits an auth request id when an auth request has been approved. */
|
||||||
authRequestPushNotification$: Observable<string>;
|
abstract authRequestPushNotification$: Observable<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emits when a login has been approved by an admin. This emission is specifically for the
|
* Emits when a login has been approved by an admin. This emission is specifically for the
|
||||||
* purpose of notifying the consuming component to display a toast informing the user.
|
* purpose of notifying the consuming component to display a toast informing the user.
|
||||||
*/
|
*/
|
||||||
adminLoginApproved$: Observable<void>;
|
abstract adminLoginApproved$: Observable<void>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an admin auth request for the given user if it exists.
|
* Returns an admin auth request for the given user if it exists.
|
||||||
* @param userId The user id.
|
* @param userId The user id.
|
||||||
* @throws If `userId` is not provided.
|
* @throws If `userId` is not provided.
|
||||||
*/
|
*/
|
||||||
abstract getAdminAuthRequest: (userId: UserId) => Promise<AdminAuthRequestStorable | null>;
|
abstract getAdminAuthRequest(userId: UserId): Promise<AdminAuthRequestStorable | null>;
|
||||||
/**
|
/**
|
||||||
* Sets an admin auth request for the given user.
|
* Sets an admin auth request for the given user.
|
||||||
* Note: use {@link clearAdminAuthRequest} to clear the request.
|
* Note: use {@link clearAdminAuthRequest} to clear the request.
|
||||||
@@ -31,16 +29,16 @@ export abstract class AuthRequestServiceAbstraction {
|
|||||||
* @param userId The user id.
|
* @param userId The user id.
|
||||||
* @throws If `authRequest` or `userId` is not provided.
|
* @throws If `authRequest` or `userId` is not provided.
|
||||||
*/
|
*/
|
||||||
abstract setAdminAuthRequest: (
|
abstract setAdminAuthRequest(
|
||||||
authRequest: AdminAuthRequestStorable,
|
authRequest: AdminAuthRequestStorable,
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
) => Promise<void>;
|
): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Clears an admin auth request for the given user.
|
* Clears an admin auth request for the given user.
|
||||||
* @param userId The user id.
|
* @param userId The user id.
|
||||||
* @throws If `userId` is not provided.
|
* @throws If `userId` is not provided.
|
||||||
*/
|
*/
|
||||||
abstract clearAdminAuthRequest: (userId: UserId) => Promise<void>;
|
abstract clearAdminAuthRequest(userId: UserId): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Gets a list of standard pending auth requests for the user.
|
* Gets a list of standard pending auth requests for the user.
|
||||||
* @returns An observable of an array of auth request.
|
* @returns An observable of an array of auth request.
|
||||||
@@ -61,42 +59,42 @@ export abstract class AuthRequestServiceAbstraction {
|
|||||||
* approval was successful.
|
* approval was successful.
|
||||||
* @throws If the auth request is missing an id or key.
|
* @throws If the auth request is missing an id or key.
|
||||||
*/
|
*/
|
||||||
abstract approveOrDenyAuthRequest: (
|
abstract approveOrDenyAuthRequest(
|
||||||
approve: boolean,
|
approve: boolean,
|
||||||
authRequest: AuthRequestResponse,
|
authRequest: AuthRequestResponse,
|
||||||
) => Promise<AuthRequestResponse>;
|
): Promise<AuthRequestResponse>;
|
||||||
/**
|
/**
|
||||||
* Sets the `UserKey` from an auth request. Auth request must have a `UserKey`.
|
* Sets the `UserKey` from an auth request. Auth request must have a `UserKey`.
|
||||||
* @param authReqResponse The auth request.
|
* @param authReqResponse The auth request.
|
||||||
* @param authReqPrivateKey The private key corresponding to the public key sent in the auth request.
|
* @param authReqPrivateKey The private key corresponding to the public key sent in the auth request.
|
||||||
* @param userId The ID of the user for whose account we will set the key.
|
* @param userId The ID of the user for whose account we will set the key.
|
||||||
*/
|
*/
|
||||||
abstract setUserKeyAfterDecryptingSharedUserKey: (
|
abstract setUserKeyAfterDecryptingSharedUserKey(
|
||||||
authReqResponse: AuthRequestResponse,
|
authReqResponse: AuthRequestResponse,
|
||||||
authReqPrivateKey: ArrayBuffer,
|
authReqPrivateKey: ArrayBuffer,
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
) => Promise<void>;
|
): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Sets the `MasterKey` and `MasterKeyHash` from an auth request. Auth request must have a `MasterKey` and `MasterKeyHash`.
|
* Sets the `MasterKey` and `MasterKeyHash` from an auth request. Auth request must have a `MasterKey` and `MasterKeyHash`.
|
||||||
* @param authReqResponse The auth request.
|
* @param authReqResponse The auth request.
|
||||||
* @param authReqPrivateKey The private key corresponding to the public key sent in the auth request.
|
* @param authReqPrivateKey The private key corresponding to the public key sent in the auth request.
|
||||||
* @param userId The ID of the user for whose account we will set the keys.
|
* @param userId The ID of the user for whose account we will set the keys.
|
||||||
*/
|
*/
|
||||||
abstract setKeysAfterDecryptingSharedMasterKeyAndHash: (
|
abstract setKeysAfterDecryptingSharedMasterKeyAndHash(
|
||||||
authReqResponse: AuthRequestResponse,
|
authReqResponse: AuthRequestResponse,
|
||||||
authReqPrivateKey: ArrayBuffer,
|
authReqPrivateKey: ArrayBuffer,
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
) => Promise<void>;
|
): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Decrypts a `UserKey` from a public key encrypted `UserKey`.
|
* Decrypts a `UserKey` from a public key encrypted `UserKey`.
|
||||||
* @param pubKeyEncryptedUserKey The public key encrypted `UserKey`.
|
* @param pubKeyEncryptedUserKey The public key encrypted `UserKey`.
|
||||||
* @param privateKey The private key corresponding to the public key used to encrypt the `UserKey`.
|
* @param privateKey The private key corresponding to the public key used to encrypt the `UserKey`.
|
||||||
* @returns The decrypted `UserKey`.
|
* @returns The decrypted `UserKey`.
|
||||||
*/
|
*/
|
||||||
abstract decryptPubKeyEncryptedUserKey: (
|
abstract decryptPubKeyEncryptedUserKey(
|
||||||
pubKeyEncryptedUserKey: string,
|
pubKeyEncryptedUserKey: string,
|
||||||
privateKey: ArrayBuffer,
|
privateKey: ArrayBuffer,
|
||||||
) => Promise<UserKey>;
|
): Promise<UserKey>;
|
||||||
/**
|
/**
|
||||||
* Decrypts a `MasterKey` and `MasterKeyHash` from a public key encrypted `MasterKey` and `MasterKeyHash`.
|
* Decrypts a `MasterKey` and `MasterKeyHash` from a public key encrypted `MasterKey` and `MasterKeyHash`.
|
||||||
* @param pubKeyEncryptedMasterKey The public key encrypted `MasterKey`.
|
* @param pubKeyEncryptedMasterKey The public key encrypted `MasterKey`.
|
||||||
@@ -104,18 +102,18 @@ export abstract class AuthRequestServiceAbstraction {
|
|||||||
* @param privateKey The private key corresponding to the public key used to encrypt the `MasterKey` and `MasterKeyHash`.
|
* @param privateKey The private key corresponding to the public key used to encrypt the `MasterKey` and `MasterKeyHash`.
|
||||||
* @returns The decrypted `MasterKey` and `MasterKeyHash`.
|
* @returns The decrypted `MasterKey` and `MasterKeyHash`.
|
||||||
*/
|
*/
|
||||||
abstract decryptPubKeyEncryptedMasterKeyAndHash: (
|
abstract decryptPubKeyEncryptedMasterKeyAndHash(
|
||||||
pubKeyEncryptedMasterKey: string,
|
pubKeyEncryptedMasterKey: string,
|
||||||
pubKeyEncryptedMasterKeyHash: string,
|
pubKeyEncryptedMasterKeyHash: string,
|
||||||
privateKey: ArrayBuffer,
|
privateKey: ArrayBuffer,
|
||||||
) => Promise<{ masterKey: MasterKey; masterKeyHash: string }>;
|
): Promise<{ masterKey: MasterKey; masterKeyHash: string }>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles incoming auth request push notifications.
|
* Handles incoming auth request push notifications.
|
||||||
* @param notification push notification.
|
* @param notification push notification.
|
||||||
* @remark We should only be receiving approved push notifications to prevent enumeration.
|
* @remark We should only be receiving approved push notifications to prevent enumeration.
|
||||||
*/
|
*/
|
||||||
abstract sendAuthRequestPushNotification: (notification: AuthRequestPushNotification) => void;
|
abstract sendAuthRequestPushNotification(notification: AuthRequestPushNotification): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a dash-delimited fingerprint for use in confirming the `AuthRequest` between the requesting and approving device.
|
* Creates a dash-delimited fingerprint for use in confirming the `AuthRequest` between the requesting and approving device.
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
|
||||||
// @ts-strict-ignore
|
|
||||||
import { Observable } from "rxjs";
|
import { Observable } from "rxjs";
|
||||||
|
|
||||||
import { AuthenticationType } from "@bitwarden/common/auth/enums/authentication-type";
|
import { AuthenticationType } from "@bitwarden/common/auth/enums/authentication-type";
|
||||||
@@ -20,60 +18,60 @@ export abstract class LoginStrategyServiceAbstraction {
|
|||||||
* The current strategy being used to authenticate.
|
* The current strategy being used to authenticate.
|
||||||
* Emits null if the session has timed out.
|
* Emits null if the session has timed out.
|
||||||
*/
|
*/
|
||||||
currentAuthType$: Observable<AuthenticationType | null>;
|
abstract currentAuthType$: Observable<AuthenticationType | null>;
|
||||||
/**
|
/**
|
||||||
* If the login strategy uses the email address of the user, this
|
* If the login strategy uses the email address of the user, this
|
||||||
* will return it. Otherwise, it will return null.
|
* will return it. Otherwise, it will return null.
|
||||||
*/
|
*/
|
||||||
getEmail: () => Promise<string | null>;
|
abstract getEmail(): Promise<string | null>;
|
||||||
/**
|
/**
|
||||||
* If the user is logging in with a master password, this will return
|
* If the user is logging in with a master password, this will return
|
||||||
* the master password hash. Otherwise, it will return null.
|
* the master password hash. Otherwise, it will return null.
|
||||||
*/
|
*/
|
||||||
getMasterPasswordHash: () => Promise<string | null>;
|
abstract getMasterPasswordHash(): Promise<string | null>;
|
||||||
/**
|
/**
|
||||||
* If the user is logging in with SSO, this will return
|
* If the user is logging in with SSO, this will return
|
||||||
* the email auth token. Otherwise, it will return null.
|
* the email auth token. Otherwise, it will return null.
|
||||||
* @see {@link SsoLoginStrategyData.ssoEmail2FaSessionToken}
|
* @see {@link SsoLoginStrategyData.ssoEmail2FaSessionToken}
|
||||||
*/
|
*/
|
||||||
getSsoEmail2FaSessionToken: () => Promise<string | null>;
|
abstract getSsoEmail2FaSessionToken(): Promise<string | null>;
|
||||||
/**
|
/**
|
||||||
* Returns the access code if the user is logging in with an
|
* Returns the access code if the user is logging in with an
|
||||||
* Auth Request. Otherwise, it will return null.
|
* Auth Request. Otherwise, it will return null.
|
||||||
*/
|
*/
|
||||||
getAccessCode: () => Promise<string | null>;
|
abstract getAccessCode(): Promise<string | null>;
|
||||||
/**
|
/**
|
||||||
* Returns the auth request ID if the user is logging in with an
|
* Returns the auth request ID if the user is logging in with an
|
||||||
* Auth Request. Otherwise, it will return null.
|
* Auth Request. Otherwise, it will return null.
|
||||||
*/
|
*/
|
||||||
getAuthRequestId: () => Promise<string | null>;
|
abstract getAuthRequestId(): Promise<string | null>;
|
||||||
/**
|
/**
|
||||||
* Sends a token request to the server using the provided credentials.
|
* Sends a token request to the server using the provided credentials.
|
||||||
*/
|
*/
|
||||||
logIn: (
|
abstract logIn(
|
||||||
credentials:
|
credentials:
|
||||||
| UserApiLoginCredentials
|
| UserApiLoginCredentials
|
||||||
| PasswordLoginCredentials
|
| PasswordLoginCredentials
|
||||||
| SsoLoginCredentials
|
| SsoLoginCredentials
|
||||||
| AuthRequestLoginCredentials
|
| AuthRequestLoginCredentials
|
||||||
| WebAuthnLoginCredentials,
|
| WebAuthnLoginCredentials,
|
||||||
) => Promise<AuthResult>;
|
): Promise<AuthResult>;
|
||||||
/**
|
/**
|
||||||
* Sends a token request to the server with the provided two factor token.
|
* Sends a token request to the server with the provided two factor token.
|
||||||
* This uses data stored from {@link LoginStrategyServiceAbstraction.logIn}, so that must be called first.
|
* This uses data stored from {@link LoginStrategyServiceAbstraction.logIn}, so that must be called first.
|
||||||
* Returns an error if no session data is found.
|
* Returns an error if no session data is found.
|
||||||
*/
|
*/
|
||||||
logInTwoFactor: (twoFactor: TokenTwoFactorRequest) => Promise<AuthResult>;
|
abstract logInTwoFactor(twoFactor: TokenTwoFactorRequest): Promise<AuthResult>;
|
||||||
/**
|
/**
|
||||||
* Creates a master key from the provided master password and email.
|
* Creates a master key from the provided master password and email.
|
||||||
*/
|
*/
|
||||||
makePreloginKey: (masterPassword: string, email: string) => Promise<MasterKey>;
|
abstract makePreloginKey(masterPassword: string, email: string): Promise<MasterKey>;
|
||||||
/**
|
/**
|
||||||
* Emits true if the authentication session has expired.
|
* Emits true if the authentication session has expired.
|
||||||
*/
|
*/
|
||||||
authenticationSessionTimeout$: Observable<boolean>;
|
abstract get authenticationSessionTimeout$(): Observable<boolean>;
|
||||||
/**
|
/**
|
||||||
* Sends a token request to the server with the provided device verification OTP.
|
* Sends a token request to the server with the provided device verification OTP.
|
||||||
*/
|
*/
|
||||||
logInNewDeviceVerification: (deviceVerificationOtp: string) => Promise<AuthResult>;
|
abstract logInNewDeviceVerification(deviceVerificationOtp: string): Promise<AuthResult>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user