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
|
@ -1,27 +1,27 @@
|
|||
using Foxchat.Core.Federation;
|
||||
using Foxchat.Core.Models;
|
||||
using Foxchat.Core.Models.Http;
|
||||
using Foxchat.Identity.Database;
|
||||
using Foxchat.Identity.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Foxchat.Identity.Services;
|
||||
|
||||
public class ChatInstanceResolverService(ILogger logger, RequestSigningService requestSigningService, IdentityContext context, InstanceConfig config)
|
||||
public class ChatInstanceResolverService(ILogger logger, RequestSigningService requestSigningService, IdentityContext db, InstanceConfig config)
|
||||
{
|
||||
private readonly ILogger _logger = logger.ForContext<ChatInstanceResolverService>();
|
||||
|
||||
public async Task<ChatInstance> ResolveChatInstanceAsync(string domain)
|
||||
{
|
||||
var instance = await context.ChatInstances.Where(c => c.Domain == domain).FirstOrDefaultAsync();
|
||||
var instance = await db.ChatInstances.Where(c => c.Domain == domain).FirstOrDefaultAsync();
|
||||
if (instance != null) return instance;
|
||||
|
||||
_logger.Information("Unknown chat instance {Domain}, fetching its data", domain);
|
||||
|
||||
var resp = await requestSigningService.RequestAsync<HelloResponse>(
|
||||
var resp = await requestSigningService.RequestAsync<Hello.HelloResponse>(
|
||||
HttpMethod.Post,
|
||||
domain, "/_fox/chat/hello",
|
||||
userId: null,
|
||||
body: new HelloRequest(config.Domain)
|
||||
body: new Hello.HelloRequest(config.Domain)
|
||||
);
|
||||
|
||||
instance = new ChatInstance
|
||||
|
@ -31,8 +31,8 @@ public class ChatInstanceResolverService(ILogger logger, RequestSigningService r
|
|||
PublicKey = resp.PublicKey,
|
||||
Status = ChatInstance.InstanceStatus.Active,
|
||||
};
|
||||
await context.AddAsync(instance);
|
||||
await context.SaveChangesAsync();
|
||||
await db.AddAsync(instance);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue