From 58481633eb8a4d54466873ee326a7855619540b2 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 15 Dec 2017 09:58:26 -0500 Subject: [PATCH] added device type header to requests --- src/background/main.background.ts | 3 ++- src/services/api.service.ts | 36 ++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/background/main.background.ts b/src/background/main.background.ts index ded74ce1f5..65605050f7 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -75,7 +75,8 @@ export default class MainBackground { this.cryptoService = new CryptoService(); this.tokenService = new TokenService(); this.appIdService = new AppIdService(); - this.apiService = new ApiService(this.tokenService, (expired: boolean) => this.logout(expired)); + this.apiService = new ApiService(this.tokenService, this.utilsService, + (expired: boolean) => this.logout(expired)); this.environmentService = new EnvironmentService(this.apiService); this.userService = new UserService(this.tokenService); this.settingsService = new SettingsService(this.userService); diff --git a/src/services/api.service.ts b/src/services/api.service.ts index 3f66b51c4b..3df53fb454 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -34,7 +34,8 @@ export default class ApiService { identityBaseUrl: string; logoutCallback: Function; - constructor(private tokenService: TokenService, logoutCallback: Function) { + constructor(private tokenService: TokenService, private utilsService: UtilsService, + logoutCallback: Function) { this.logoutCallback = logoutCallback; } @@ -85,6 +86,7 @@ export default class ApiService { headers: new Headers({ 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'Accept': 'application/json', + 'Device-Type': this.utilsService.getBrowser(), }), method: 'POST', })); @@ -124,6 +126,7 @@ export default class ApiService { cache: 'no-cache', headers: new Headers({ 'Content-Type': 'application/json; charset=utf-8', + 'Device-Type': this.utilsService.getBrowser(), }), method: 'POST', })); @@ -141,8 +144,9 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/accounts/revision-date', { cache: 'no-cache', headers: new Headers({ - Accept: 'application/json', - Authorization: authHeader, + 'Accept': 'application/json', + 'Authorization': authHeader, + 'Device-Type': this.utilsService.getBrowser(), }), })); @@ -160,6 +164,7 @@ export default class ApiService { cache: 'no-cache', headers: new Headers({ 'Content-Type': 'application/json; charset=utf-8', + 'Device-Type': this.utilsService.getBrowser(), }), method: 'POST', })); @@ -176,6 +181,7 @@ export default class ApiService { cache: 'no-cache', headers: new Headers({ 'Content-Type': 'application/json; charset=utf-8', + 'Device-Type': this.utilsService.getBrowser(), }), method: 'POST', })); @@ -197,6 +203,7 @@ export default class ApiService { 'Accept': 'application/json', 'Authorization': authHeader, 'Content-Type': 'application/json; charset=utf-8', + 'Device-Type': this.utilsService.getBrowser(), }), method: 'POST', })); @@ -219,6 +226,7 @@ export default class ApiService { 'Accept': 'application/json', 'Authorization': authHeader, 'Content-Type': 'application/json; charset=utf-8', + 'Device-Type': this.utilsService.getBrowser(), }), method: 'PUT', })); @@ -237,7 +245,8 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/folders/' + id, { cache: 'no-cache', headers: new Headers({ - Authorization: authHeader, + 'Authorization': authHeader, + 'Device-Type': this.utilsService.getBrowser(), }), method: 'DELETE', })); @@ -259,6 +268,7 @@ export default class ApiService { 'Accept': 'application/json', 'Authorization': authHeader, 'Content-Type': 'application/json; charset=utf-8', + 'Device-Type': this.utilsService.getBrowser(), }), method: 'POST', })); @@ -281,6 +291,7 @@ export default class ApiService { 'Accept': 'application/json', 'Authorization': authHeader, 'Content-Type': 'application/json; charset=utf-8', + 'Device-Type': this.utilsService.getBrowser(), }), method: 'PUT', })); @@ -299,7 +310,8 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, { cache: 'no-cache', headers: new Headers({ - Authorization: authHeader, + 'Authorization': authHeader, + 'Device-Type': this.utilsService.getBrowser(), }), method: 'DELETE', })); @@ -318,8 +330,9 @@ export default class ApiService { body: data, cache: 'no-cache', headers: new Headers({ - Accept: 'application/json', - Authorization: authHeader, + 'Accept': 'application/json', + 'Authorization': authHeader, + 'Device-Type': this.utilsService.getBrowser(), }), method: 'POST', })); @@ -338,7 +351,8 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment/' + attachmentId, { cache: 'no-cache', headers: new Headers({ - Authorization: authHeader, + 'Authorization': authHeader, + 'Device-Type': this.utilsService.getBrowser(), }), method: 'DELETE', })); @@ -356,8 +370,9 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/sync', { cache: 'no-cache', headers: new Headers({ - Accept: 'application/json', - Authorization: authHeader, + 'Accept': 'application/json', + 'Authorization': authHeader, + 'Device-Type': this.utilsService.getBrowser(), }), })); @@ -415,6 +430,7 @@ export default class ApiService { headers: new Headers({ 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'Accept': 'application/json', + 'Device-Type': this.utilsService.getBrowser(), }), method: 'POST', }));