add basic suppport for client_credentials oauth grant
This commit is contained in:
parent
049f4a56de
commit
8995213d26
20 changed files with 627 additions and 58 deletions
|
@ -5,16 +5,15 @@ using Foxchat.Core.Database;
|
|||
using Foxchat.Core.Utils;
|
||||
using NodaTime;
|
||||
using NodaTime.Text;
|
||||
using Serilog;
|
||||
|
||||
namespace Foxchat.Core.Federation;
|
||||
|
||||
public partial class RequestSigningService(ILogger logger, IClock clock, IDatabaseContext context, CoreConfig config)
|
||||
public partial class RequestSigningService(ILogger logger, IClock clock, IDatabaseContext db, CoreConfig config)
|
||||
{
|
||||
private readonly ILogger _logger = logger.ForContext<RequestSigningService>();
|
||||
private readonly IClock _clock = clock;
|
||||
private readonly CoreConfig _config = config;
|
||||
private readonly RSA _rsa = context.GetInstanceKeysAsync().GetAwaiter().GetResult();
|
||||
private readonly RSA _rsa = db.GetInstanceKeysAsync().GetAwaiter().GetResult();
|
||||
private readonly HttpClient _httpClient = new();
|
||||
|
||||
public string GenerateSignature(SignatureData data)
|
||||
|
@ -41,11 +40,11 @@ public partial class RequestSigningService(ILogger logger, IClock clock, IDataba
|
|||
var time = ParseTime(dateHeader);
|
||||
if ((now + Duration.FromMinutes(1)) < time)
|
||||
{
|
||||
throw new FoxchatError.IncomingFederationError("Request was made in the future");
|
||||
throw new ApiError.IncomingFederationError("Request was made in the future");
|
||||
}
|
||||
else if ((now - Duration.FromMinutes(1)) > time)
|
||||
{
|
||||
throw new FoxchatError.IncomingFederationError("Request was made too long ago");
|
||||
throw new ApiError.IncomingFederationError("Request was made too long ago");
|
||||
}
|
||||
|
||||
var plaintext = GeneratePlaintext(new SignatureData(time, host, requestPath, contentLength, userId));
|
||||
|
@ -54,7 +53,7 @@ public partial class RequestSigningService(ILogger logger, IClock clock, IDataba
|
|||
|
||||
if (!CryptoUtils.TryFromBase64String(encodedSignature, out var signature))
|
||||
{
|
||||
throw new FoxchatError.IncomingFederationError("Invalid base64 signature");
|
||||
throw new ApiError.IncomingFederationError("Invalid base64 signature");
|
||||
}
|
||||
|
||||
var deformatter = new RSAPKCS1SignatureDeformatter(rsa);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue