1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 00:52:49 -05:00

hub api notifications

This commit is contained in:
Kyle Spearrin
2018-08-16 12:05:01 -04:00
parent ff01ce5ca7
commit 28e6783a00
22 changed files with 320 additions and 179 deletions

View File

@ -52,6 +52,30 @@ namespace Bit.Core.Services
protected HttpClient IdentityClient { get; private set; }
protected string AccessToken { get; private set; }
protected async Task SendAsync(HttpMethod method, string path, object requestModel = null)
{
var tokenStateResponse = await HandleTokenStateAsync();
if(!tokenStateResponse)
{
return;
}
var message = new TokenHttpRequestMessage(requestModel, AccessToken)
{
Method = method,
RequestUri = new Uri(string.Concat(Client.BaseAddress, path))
};
try
{
await Client.SendAsync(message);
}
catch(Exception e)
{
_logger.LogError(12334, e, "Failed to send to {0}.", message.RequestUri.ToString());
}
}
protected async Task<bool> HandleTokenStateAsync()
{
if(_nextAuthAttempt.HasValue && DateTime.UtcNow > _nextAuthAttempt.Value)
@ -119,8 +143,11 @@ namespace Bit.Core.Services
public TokenHttpRequestMessage(object requestObject, string token)
: this(token)
{
var stringContent = JsonConvert.SerializeObject(requestObject);
Content = new StringContent(stringContent, Encoding.UTF8, "application/json");
if(requestObject != null)
{
var stringContent = JsonConvert.SerializeObject(requestObject);
Content = new StringContent(stringContent, Encoding.UTF8, "application/json");
}
}
}