Streamlined grpc auth

Added ShareX Destiation on client
This commit is contained in:
2025-05-21 22:07:57 -04:00
parent acd30750a9
commit 7061b4c313
14 changed files with 155 additions and 46 deletions

View File

@@ -1,14 +1,24 @@
using AobaCore;
using Aoba.RPC;
using Aoba.RPC;
using AobaCore;
using AobaServer.Models;
using AobaServer.Utils;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using Microsoft.AspNetCore.Mvc;
using MongoDB.Bson.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AobaServer.Services;
public class AobaRpcService(AobaService aobaService) : AobaRpc.AobaRpcBase
public class AobaRpcService(AobaService aobaService, AccountsService accountsService, AuthInfo authInfo) : AobaRpc.AobaRpcBase
{
public override async Task<MediaResponse> GetMedia(Id request, ServerCallContext context)
{
@@ -22,4 +32,29 @@ public class AobaRpcService(AobaService aobaService) : AobaRpc.AobaRpcBase
return result.ToResponse();
}
}
public override async Task<ShareXResponse> GetShareXDestination(Empty request, ServerCallContext context)
{
var userId = context.GetHttpContext().User.GetId();
var user = await accountsService.GetUserAsync(userId, context.CancellationToken);
if (user == null)
return new ShareXResponse { Error = "User does not exist" };
var token = user.GetToken(authInfo);
var dest = new ShareXDestination
{
DeletionURL = string.Empty,
ThumbnailURL = string.Empty,
Headers = new()
{
{ "Authorization", $"Bearer {token}" }
}
};
return new ShareXResponse
{
Destination = JsonSerializer.Serialize(dest, new JsonSerializerOptions
{
WriteIndented = true
})
};
}
}