2016-05-04 02:49:49 +03:00
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using XLabs.Ioc;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App
|
|
|
|
|
{
|
|
|
|
|
public class TokenHttpRequestMessage : HttpRequestMessage
|
|
|
|
|
{
|
|
|
|
|
public TokenHttpRequestMessage()
|
|
|
|
|
{
|
|
|
|
|
var authService = Resolver.Resolve<IAuthService>();
|
2016-07-01 04:40:44 +03:00
|
|
|
|
var appIdService = Resolver.Resolve<IAppIdService>();
|
2016-05-04 02:49:49 +03:00
|
|
|
|
Headers.Add("Authorization", $"Bearer {authService.Token}");
|
2016-07-01 04:40:44 +03:00
|
|
|
|
if(!string.IsNullOrWhiteSpace(appIdService.AppId))
|
|
|
|
|
{
|
|
|
|
|
Headers.Add("DeviceIdentifier", appIdService.AppId);
|
|
|
|
|
}
|
2016-05-04 02:49:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TokenHttpRequestMessage(object requestObject)
|
|
|
|
|
: this()
|
|
|
|
|
{
|
|
|
|
|
var stringContent = JsonConvert.SerializeObject(requestObject);
|
|
|
|
|
Content = new StringContent(stringContent, Encoding.UTF8, "application/json");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|