mirror of
https://github.com/bitwarden/browser
synced 2024-12-26 18:04:07 +01:00
Add headers for client type and client version (#651)
This commit is contained in:
parent
6b8508579f
commit
8130fce404
@ -1,3 +1,4 @@
|
||||
import { ClientType } from "../enums/clientType";
|
||||
import { DeviceType } from "../enums/deviceType";
|
||||
import { ThemeType } from "../enums/themeType";
|
||||
|
||||
@ -6,9 +7,9 @@ interface ToastOptions {
|
||||
}
|
||||
|
||||
export abstract class PlatformUtilsService {
|
||||
identityClientId: string;
|
||||
getDevice: () => DeviceType;
|
||||
getDeviceString: () => string;
|
||||
getClientType: () => ClientType;
|
||||
isFirefox: () => boolean;
|
||||
isChrome: () => boolean;
|
||||
isEdge: () => boolean;
|
||||
|
8
common/src/enums/clientType.ts
Normal file
8
common/src/enums/clientType.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export enum ClientType {
|
||||
Web = "web",
|
||||
Browser = "browser",
|
||||
Desktop = "desktop",
|
||||
Mobile = "mobile",
|
||||
Cli = "cli",
|
||||
DirectoryConnector = "connector",
|
||||
}
|
@ -3,6 +3,7 @@ import { TokenRequest, TokenRequestTwoFactor } from "./tokenRequest";
|
||||
import { CaptchaProtectedRequest } from "../captchaProtectedRequest";
|
||||
import { DeviceRequest } from "../deviceRequest";
|
||||
|
||||
import { ClientType } from "../../../enums/clientType";
|
||||
import { Utils } from "../../../misc/utils";
|
||||
|
||||
export class PasswordTokenRequest extends TokenRequest implements CaptchaProtectedRequest {
|
||||
@ -16,7 +17,7 @@ export class PasswordTokenRequest extends TokenRequest implements CaptchaProtect
|
||||
super(twoFactor, device);
|
||||
}
|
||||
|
||||
toIdentityToken(clientId: string) {
|
||||
toIdentityToken(clientId: ClientType) {
|
||||
const obj = super.toIdentityToken(clientId);
|
||||
|
||||
obj.grant_type = "password";
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { ClientType } from "../enums/clientType";
|
||||
import { DeviceType } from "../enums/deviceType";
|
||||
import { PolicyType } from "../enums/policyType";
|
||||
|
||||
@ -225,7 +226,7 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
const identityToken =
|
||||
request instanceof ApiTokenRequest
|
||||
? request.toIdentityToken()
|
||||
: request.toIdentityToken(this.platformUtilsService.identityClientId);
|
||||
: request.toIdentityToken(this.platformUtilsService.getClientType());
|
||||
|
||||
const response = await this.fetch(
|
||||
new Request(this.environmentService.getIdentityUrl() + "/connect/token", {
|
||||
@ -2205,11 +2206,16 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
fetch(request: Request): Promise<Response> {
|
||||
async fetch(request: Request): Promise<Response> {
|
||||
if (request.method === "GET") {
|
||||
request.headers.set("Cache-Control", "no-store");
|
||||
request.headers.set("Pragma", "no-cache");
|
||||
}
|
||||
request.headers.set("Bitwarden-Client-Name", this.platformUtilsService.getClientType());
|
||||
request.headers.set(
|
||||
"Bitwarden-Client-Version",
|
||||
await this.platformUtilsService.getApplicationVersion()
|
||||
);
|
||||
return this.nativeFetch(request);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ import { clipboard, ipcRenderer, shell } from "electron";
|
||||
|
||||
import { isDev, isMacAppStore } from "../utils";
|
||||
|
||||
import { ClientType } from "jslib-common/enums/clientType";
|
||||
import { DeviceType } from "jslib-common/enums/deviceType";
|
||||
import { ThemeType } from "jslib-common/enums/themeType";
|
||||
|
||||
@ -11,8 +12,7 @@ import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.se
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
|
||||
export class ElectronPlatformUtilsService implements PlatformUtilsService {
|
||||
identityClientId: string;
|
||||
|
||||
private clientType: ClientType;
|
||||
private deviceCache: DeviceType = null;
|
||||
|
||||
constructor(
|
||||
@ -21,7 +21,7 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
|
||||
private isDesktopApp: boolean,
|
||||
private stateService: StateService
|
||||
) {
|
||||
this.identityClientId = isDesktopApp ? "desktop" : "connector";
|
||||
this.clientType = isDesktopApp ? ClientType.Desktop : ClientType.DirectoryConnector;
|
||||
}
|
||||
|
||||
getDevice(): DeviceType {
|
||||
@ -48,6 +48,10 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
|
||||
return device.replace("desktop", "");
|
||||
}
|
||||
|
||||
getClientType() {
|
||||
return this.clientType;
|
||||
}
|
||||
|
||||
isFirefox(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as child_process from "child_process";
|
||||
|
||||
import { ClientType } from "jslib-common/enums/clientType";
|
||||
import { DeviceType } from "jslib-common/enums/deviceType";
|
||||
import { ThemeType } from "jslib-common/enums/themeType";
|
||||
|
||||
@ -9,12 +10,12 @@ import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.se
|
||||
const open = require("open");
|
||||
|
||||
export class CliPlatformUtilsService implements PlatformUtilsService {
|
||||
identityClientId: string;
|
||||
clientType: ClientType;
|
||||
|
||||
private deviceCache: DeviceType = null;
|
||||
|
||||
constructor(identityClientId: string, private packageJson: any) {
|
||||
this.identityClientId = identityClientId;
|
||||
constructor(clientType: ClientType, private packageJson: any) {
|
||||
this.clientType = clientType;
|
||||
}
|
||||
|
||||
getDevice(): DeviceType {
|
||||
@ -41,6 +42,10 @@ export class CliPlatformUtilsService implements PlatformUtilsService {
|
||||
return device.replace("desktop", "");
|
||||
}
|
||||
|
||||
getClientType() {
|
||||
return this.clientType;
|
||||
}
|
||||
|
||||
isFirefox() {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user