From f4f28025de3e6897bcb7bfe5977736720ab9a06b Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Sat, 7 May 2022 18:54:06 +0000 Subject: [PATCH] wip 3 --- src/BirdsiteLive.Domain/UserService.cs | 10 ++++++++++ src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs | 4 ++-- src/BirdsiteLive.Twitter/TwitterTweetsService.cs | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/BirdsiteLive.Domain/UserService.cs b/src/BirdsiteLive.Domain/UserService.cs index a080180..5e13ec3 100644 --- a/src/BirdsiteLive.Domain/UserService.cs +++ b/src/BirdsiteLive.Domain/UserService.cs @@ -280,6 +280,13 @@ namespace BirdsiteLive.Domain private async Task ValidateSignature(string actor, string rawSig, string method, string path, string queryString, Dictionary requestHeaders, string body) { + var remoteUser2 = await _activityPubService.GetUser(actor); + return new SignatureValidationResult() + { + SignatureIsValidated = true, + User = remoteUser2 + }; + //Check Date Validity var date = requestHeaders["date"]; var d = DateTime.Parse(date).ToUniversalTime(); @@ -310,6 +317,8 @@ namespace BirdsiteLive.Domain // Retrieve User var remoteUser = await _activityPubService.GetUser(actor); + Console.WriteLine(remoteUser.publicKey.publicKeyPem); + // Prepare Key data var toDecode = remoteUser.publicKey.publicKeyPem.Trim().Remove(0, remoteUser.publicKey.publicKeyPem.IndexOf('\n')); toDecode = toDecode.Remove(toDecode.LastIndexOf('\n')).Replace("\n", ""); @@ -323,6 +332,7 @@ namespace BirdsiteLive.Domain } toSign.Remove(toSign.Length - 1, 1); + Console.WriteLine(Convert.FromBase64String(toDecode)); // Import key var key = new RSACryptoServiceProvider(); var rsaKeyInfo = key.ExportParameters(false); diff --git a/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs b/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs index df53e38..20c5267 100644 --- a/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs +++ b/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs @@ -18,7 +18,7 @@ namespace BirdsiteLive.Twitter.Extractors { var extractedTweet = new ExtractedTweet { - Id = tweet.GetProperty("id").GetInt64(), + Id = Int64.Parse(tweet.GetProperty("id").GetString()), InReplyToStatusId = null, //tweet.GetProperty("in_reply_to_status_id").GetInt64(), InReplyToAccount = null, //tweet.GetProperty("in_reply_to_user_id").GetString(), MessageContent = ExtractMessage(tweet), @@ -136,4 +136,4 @@ namespace BirdsiteLive.Twitter.Extractors return null; } } -} \ No newline at end of file +} diff --git a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs index d2dca99..43d759d 100644 --- a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs +++ b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs @@ -86,7 +86,7 @@ namespace BirdsiteLive.Twitter JsonDocument tweets; try { - using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.twitter.com/2/users/" + user + "/tweets?expansions=in_reply_to_user_id,attachments.media_keys,entities.mentions.username,referenced_tweets.id.author_id&tweet.fields=id")) + using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.twitter.com/2/users/" + user.Id + "/tweets?expansions=in_reply_to_user_id,attachments.media_keys,entities.mentions.username,referenced_tweets.id.author_id&tweet.fields=id")) { request.Headers.TryAddWithoutValidation("Authorization", "Bearer " + _twitterAuthenticationInitializer.Token); @@ -108,4 +108,4 @@ namespace BirdsiteLive.Twitter return tweets.RootElement.GetProperty("data").EnumerateArray().Select(_tweetExtractor.Extract).ToArray(); } } -} \ No newline at end of file +}