From b90ce2a2afffadc37a4f05d3fba44864fa54f065 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 10 Feb 2017 19:16:23 -0500 Subject: [PATCH] token refresh bad requests are to be treated as unauthorized --- src/App/Repositories/AccountsApiRepository.cs | 1 - src/App/Repositories/BaseApiRepository.cs | 12 +++++++++++- src/App/Repositories/CipherApiRepository.cs | 2 -- src/App/Repositories/LoginApiRepository.cs | 4 ---- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/App/Repositories/AccountsApiRepository.cs b/src/App/Repositories/AccountsApiRepository.cs index 9817c0e1a..387be9081 100644 --- a/src/App/Repositories/AccountsApiRepository.cs +++ b/src/App/Repositories/AccountsApiRepository.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Bit.App.Abstractions; using Bit.App.Models.Api; using Plugin.Connectivity.Abstractions; -using System.Net; namespace Bit.App.Repositories { diff --git a/src/App/Repositories/BaseApiRepository.cs b/src/App/Repositories/BaseApiRepository.cs index d37751aa7..f6acdbdfb 100644 --- a/src/App/Repositories/BaseApiRepository.cs +++ b/src/App/Repositories/BaseApiRepository.cs @@ -75,6 +75,11 @@ namespace Bit.App.Repositories var response = await client.SendAsync(requestMessage).ConfigureAwait(false); if(!response.IsSuccessStatusCode) { + if(response.StatusCode == HttpStatusCode.BadRequest) + { + response.StatusCode = HttpStatusCode.Unauthorized; + } + return await error.Invoke(response).ConfigureAwait(false); } @@ -111,6 +116,11 @@ namespace Bit.App.Repositories var response = await client.SendAsync(requestMessage).ConfigureAwait(false); if(!response.IsSuccessStatusCode) { + if(response.StatusCode == HttpStatusCode.BadRequest) + { + response.StatusCode = HttpStatusCode.Unauthorized; + } + return await error.Invoke(response).ConfigureAwait(false); } @@ -119,7 +129,7 @@ namespace Bit.App.Repositories TokenService.Token = tokenResponse.AccessToken; TokenService.RefreshToken = tokenResponse.RefreshToken; } - catch(Exception ee) + catch { return webException.Invoke(); } diff --git a/src/App/Repositories/CipherApiRepository.cs b/src/App/Repositories/CipherApiRepository.cs index 85d72db04..61ea216d3 100644 --- a/src/App/Repositories/CipherApiRepository.cs +++ b/src/App/Repositories/CipherApiRepository.cs @@ -1,12 +1,10 @@ using System; -using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Bit.App.Abstractions; using Bit.App.Models.Api; using Newtonsoft.Json; using Plugin.Connectivity.Abstractions; -using System.Net; namespace Bit.App.Repositories { diff --git a/src/App/Repositories/LoginApiRepository.cs b/src/App/Repositories/LoginApiRepository.cs index 6515d4208..bc82f4a58 100644 --- a/src/App/Repositories/LoginApiRepository.cs +++ b/src/App/Repositories/LoginApiRepository.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; using Bit.App.Abstractions; using Bit.App.Models.Api; -using Newtonsoft.Json; using Plugin.Connectivity.Abstractions; namespace Bit.App.Repositories