mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
Add headers for client type and client version (#651)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user