1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-09-29 04:07:37 +02:00

clear push token on unregister

This commit is contained in:
Kyle Spearrin 2016-08-06 00:41:00 -04:00
parent 38184e4893
commit b1da05474a
4 changed files with 34 additions and 2 deletions

View File

@ -9,5 +9,6 @@ namespace Bit.App.Abstractions
public interface IDeviceApiRepository : IApiRepository<DeviceRequest, DeviceResponse, string>
{
Task<ApiResult<DeviceResponse>> PutTokenAsync(string identifier, DeviceTokenRequest request);
Task<ApiResult<DeviceResponse>> PutClearTokenAsync(string identifier);
}
}

View File

@ -42,5 +42,32 @@ namespace Bit.App.Repositories
return ApiResult<DeviceResponse>.Success(responseObj, response.StatusCode);
}
}
public virtual async Task<ApiResult<DeviceResponse>> PutClearTokenAsync(string identifier)
{
if(!Connectivity.IsConnected)
{
return HandledNotConnected<DeviceResponse>();
}
using(var client = new ApiHttpClient())
{
var requestMessage = new TokenHttpRequestMessage
{
Method = HttpMethod.Put,
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/identifier/", identifier, "/clear-token")),
};
var response = await client.SendAsync(requestMessage);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<DeviceResponse>(response);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseObj = JsonConvert.DeserializeObject<DeviceResponse>(responseContent);
return ApiResult<DeviceResponse>.Success(responseObj, response.StatusCode);
}
}
}
}

View File

@ -95,10 +95,11 @@ namespace Bit.App.Services
}
}
public void OnUnregistered(DeviceType deviceType)
public async void OnUnregistered(DeviceType deviceType)
{
Debug.WriteLine("Push Notification - Device Unnregistered");
_settings.Remove(Constants.PushLastRegistrationDate);
await _deviceApiRepository.PutClearTokenAsync(_appIdService.AppId);
}
public void OnError(string message, DeviceType deviceType)

View File

@ -12,7 +12,10 @@ namespace Bit.App
{
var authService = Resolver.Resolve<IAuthService>();
var appIdService = Resolver.Resolve<IAppIdService>();
Headers.Add("Authorization", $"Bearer {authService.Token}");
if(authService.IsAuthenticated)
{
Headers.Add("Authorization", $"Bearer {authService.Token}");
}
if(!string.IsNullOrWhiteSpace(appIdService.AppId))
{
Headers.Add("DeviceIdentifier", appIdService.AppId);