mirror of
https://github.com/bitwarden/browser
synced 2026-02-10 21:50:15 +00:00
Add device identifier to config request
This commit is contained in:
@@ -5,5 +5,5 @@ export abstract class ConfigApiServiceAbstraction {
|
||||
/**
|
||||
* Fetches the server configuration for the given user. If no user is provided, the configuration will not contain user-specific context.
|
||||
*/
|
||||
abstract get(userId: UserId | undefined): Promise<ServerConfigResponse>;
|
||||
abstract get(userId: UserId | undefined, appId: string): Promise<ServerConfigResponse>;
|
||||
}
|
||||
|
||||
@@ -10,13 +10,15 @@ export class ConfigApiService implements ConfigApiServiceAbstraction {
|
||||
private tokenService: TokenService,
|
||||
) {}
|
||||
|
||||
async get(userId: UserId | undefined): Promise<ServerConfigResponse> {
|
||||
async get(userId: UserId | undefined, appId: string): Promise<ServerConfigResponse> {
|
||||
// Authentication adds extra context to config responses, if the user has an access token, we want to use it
|
||||
// We don't particularly care about ensuring the token is valid and not expired, just that it exists
|
||||
const authed: boolean =
|
||||
userId == null ? false : (await this.tokenService.getAccessToken(userId)) != null;
|
||||
|
||||
const r = await this.apiService.send("GET", "/config", null, authed, true);
|
||||
const r = await this.apiService.send("GET", "/config", null, authed, true, null, (headers) => {
|
||||
headers.set("Device-Identifier", appId);
|
||||
});
|
||||
return new ServerConfigResponse(r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { AuthService } from "../../../auth/abstractions/auth.service";
|
||||
import { AuthenticationStatus } from "../../../auth/enums/authentication-status";
|
||||
import { FeatureFlag } from "../../../enums/feature-flag.enum";
|
||||
import { UserId } from "../../../types/guid";
|
||||
import { AppIdService } from "../../abstractions/app-id.service";
|
||||
import { ConfigApiServiceAbstraction } from "../../abstractions/config/config-api.service.abstraction";
|
||||
import { ServerConfig } from "../../abstractions/config/server-config";
|
||||
import { Environment, EnvironmentService } from "../../abstractions/environment.service";
|
||||
@@ -46,6 +47,7 @@ describe("ConfigService", () => {
|
||||
const authService = mock<AuthService>({
|
||||
authStatusFor$: (userId) => of(AuthenticationStatus.Unlocked),
|
||||
});
|
||||
const appIdService = mock<AppIdService>();
|
||||
let stateProvider: FakeStateProvider;
|
||||
let globalState: FakeGlobalState<Record<ApiUrl, ServerConfig>>;
|
||||
let userState: FakeSingleUserState<ServerConfig>;
|
||||
@@ -81,6 +83,7 @@ describe("ConfigService", () => {
|
||||
logService,
|
||||
stateProvider,
|
||||
authService,
|
||||
appIdService,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -218,6 +221,7 @@ describe("ConfigService", () => {
|
||||
mock<AuthService>({
|
||||
authStatusFor$: () => of(AuthenticationStatus.Locked),
|
||||
}),
|
||||
appIdService,
|
||||
);
|
||||
|
||||
const config = await firstValueFrom(sut.serverConfig$);
|
||||
@@ -243,6 +247,7 @@ describe("ConfigService", () => {
|
||||
logService,
|
||||
stateProvider,
|
||||
authService,
|
||||
appIdService,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -296,6 +301,7 @@ describe("ConfigService", () => {
|
||||
logService,
|
||||
stateProvider,
|
||||
authService,
|
||||
appIdService,
|
||||
);
|
||||
|
||||
userState.nextState(null);
|
||||
@@ -349,6 +355,7 @@ describe("ConfigService", () => {
|
||||
logService,
|
||||
stateProvider,
|
||||
authService,
|
||||
appIdService,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
FeatureFlagValueType,
|
||||
} from "../../../enums/feature-flag.enum";
|
||||
import { UserId } from "../../../types/guid";
|
||||
import { AppIdService } from "../../abstractions/app-id.service";
|
||||
import { ConfigApiServiceAbstraction } from "../../abstractions/config/config-api.service.abstraction";
|
||||
import { ConfigService } from "../../abstractions/config/config.service";
|
||||
import { ServerConfig } from "../../abstractions/config/server-config";
|
||||
@@ -70,6 +71,7 @@ export class DefaultConfigService implements ConfigService {
|
||||
private logService: LogService,
|
||||
private stateProvider: StateProvider,
|
||||
private authService: AuthService,
|
||||
private appIdService: AppIdService,
|
||||
) {
|
||||
const userId$ = this.stateProvider.activeUserId$;
|
||||
const authStatus$ = userId$.pipe(
|
||||
@@ -186,7 +188,8 @@ export class DefaultConfigService implements ConfigService {
|
||||
);
|
||||
this.failedFetchFallbackSubject.next(existingConfig);
|
||||
}, SLOW_EMISSION_GUARD);
|
||||
const response = await this.configApiService.get(userId);
|
||||
const appId = await this.appIdService.getAppId();
|
||||
const response = await this.configApiService.get(userId, appId);
|
||||
clearTimeout(handle);
|
||||
const newConfig = new ServerConfig(new ServerConfigData(response));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user