mirror of
https://github.com/bitwarden/android.git
synced 2024-12-18 23:31:52 +03:00
clear push token on unregister
This commit is contained in:
parent
38184e4893
commit
b1da05474a
4 changed files with 34 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue