fix httpclient candid implementation
This commit is contained in:
parent
3af2ef05d9
commit
a25cb31a62
3 changed files with 14 additions and 29 deletions
|
@ -105,25 +105,6 @@ namespace BirdsiteLive.Cryptography
|
||||||
return new MagicKey(JsonConvert.SerializeObject(RSAKeyParms.From(rsa.ExportParameters(true))));
|
return new MagicKey(JsonConvert.SerializeObject(RSAKeyParms.From(rsa.ExportParameters(true))));
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static async Task<MagicKey> KeyForAuthor(ASObject obj)
|
|
||||||
//{
|
|
||||||
// var authorId = (string)obj["email"].FirstOrDefault()?.Primitive;
|
|
||||||
// if (authorId == null)
|
|
||||||
// {
|
|
||||||
// authorId = obj["name"].FirstOrDefault()?.Primitive + "@" + new Uri(obj.Id).Host;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var domain = authorId.Split('@')[1];
|
|
||||||
// var hc = new HttpClient();
|
|
||||||
// var wf = JsonConvert.DeserializeObject<WebfingerResult>(await hc.GetStringAsync($"https://{domain}/.well-known/webfinger?resource=acct:{Uri.EscapeDataString(authorId)}"));
|
|
||||||
// var link = wf.links.FirstOrDefault(a => a.rel == "magic-public-key");
|
|
||||||
// if (link == null) return null;
|
|
||||||
|
|
||||||
// if (!link.href.StartsWith("data:")) return null; // does this happen?
|
|
||||||
|
|
||||||
// return new MagicKey(link.href.Split(new char[] { ',' }, 2)[1]);
|
|
||||||
//}
|
|
||||||
|
|
||||||
public byte[] BuildSignedData(string data, string dataType, string encoding, string algorithm)
|
public byte[] BuildSignedData(string data, string dataType, string encoding, string algorithm)
|
||||||
{
|
{
|
||||||
var sig = data + "." + _encodeBase64Url(Encoding.UTF8.GetBytes(dataType)) + "." + _encodeBase64Url(Encoding.UTF8.GetBytes(encoding)) + "." + _encodeBase64Url(Encoding.UTF8.GetBytes(algorithm));
|
var sig = data + "." + _encodeBase64Url(Encoding.UTF8.GetBytes(dataType)) + "." + _encodeBase64Url(Encoding.UTF8.GetBytes(encoding)) + "." + _encodeBase64Url(Encoding.UTF8.GetBytes(algorithm));
|
||||||
|
|
|
@ -25,25 +25,25 @@ namespace BirdsiteLive.Domain
|
||||||
public class ActivityPubService : IActivityPubService
|
public class ActivityPubService : IActivityPubService
|
||||||
{
|
{
|
||||||
private readonly InstanceSettings _instanceSettings;
|
private readonly InstanceSettings _instanceSettings;
|
||||||
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ICryptoService _cryptoService;
|
private readonly ICryptoService _cryptoService;
|
||||||
|
|
||||||
#region Ctor
|
#region Ctor
|
||||||
public ActivityPubService(ICryptoService cryptoService, InstanceSettings instanceSettings)
|
public ActivityPubService(ICryptoService cryptoService, InstanceSettings instanceSettings, IHttpClientFactory httpClientFactory)
|
||||||
{
|
{
|
||||||
_cryptoService = cryptoService;
|
_cryptoService = cryptoService;
|
||||||
_instanceSettings = instanceSettings;
|
_instanceSettings = instanceSettings;
|
||||||
|
_httpClientFactory = httpClientFactory;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public async Task<Actor> GetUser(string objectId)
|
public async Task<Actor> GetUser(string objectId)
|
||||||
{
|
{
|
||||||
using (var httpClient = new HttpClient())
|
var httpClient = _httpClientFactory.CreateClient();
|
||||||
{
|
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||||
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
var result = await httpClient.GetAsync(objectId);
|
||||||
var result = await httpClient.GetAsync(objectId);
|
var content = await result.Content.ReadAsStringAsync();
|
||||||
var content = await result.Content.ReadAsStringAsync();
|
return JsonConvert.DeserializeObject<Actor>(content);
|
||||||
return JsonConvert.DeserializeObject<Actor>(content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox)
|
public async Task PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox)
|
||||||
|
@ -53,7 +53,7 @@ namespace BirdsiteLive.Domain
|
||||||
|
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
var nowString = now.ToString("s") + "Z";
|
var nowString = now.ToString("s") + "Z";
|
||||||
|
|
||||||
var noteActivity = new ActivityCreateNote()
|
var noteActivity = new ActivityCreateNote()
|
||||||
{
|
{
|
||||||
context = "https://www.w3.org/ns/activitystreams",
|
context = "https://www.w3.org/ns/activitystreams",
|
||||||
|
@ -85,7 +85,7 @@ namespace BirdsiteLive.Domain
|
||||||
|
|
||||||
var signature = _cryptoService.SignAndGetSignatureHeader(date, actorUrl, targetHost, digest, usedInbox);
|
var signature = _cryptoService.SignAndGetSignatureHeader(date, actorUrl, targetHost, digest, usedInbox);
|
||||||
|
|
||||||
var client = new HttpClient(); //TODO: remove this from here
|
var client = _httpClientFactory.CreateClient();
|
||||||
var httpRequestMessage = new HttpRequestMessage
|
var httpRequestMessage = new HttpRequestMessage
|
||||||
{
|
{
|
||||||
Method = HttpMethod.Post,
|
Method = HttpMethod.Post,
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\BirdsiteLive.ActivityPub\BirdsiteLive.ActivityPub.csproj" />
|
<ProjectReference Include="..\BirdsiteLive.ActivityPub\BirdsiteLive.ActivityPub.csproj" />
|
||||||
<ProjectReference Include="..\BirdsiteLive.Cryptography\BirdsiteLive.Cryptography.csproj" />
|
<ProjectReference Include="..\BirdsiteLive.Cryptography\BirdsiteLive.Cryptography.csproj" />
|
||||||
|
|
Loading…
Add table
Reference in a new issue