Streamlined grpc auth
Added ShareX Destiation on client
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
public class ShareXDestination
|
||||
{
|
||||
public string Version { get; set; } = "13.1.0";
|
||||
public string Version { get; set; } = "14.0.1";
|
||||
public string Name { get; set; } = "Aoba";
|
||||
public string DestinationType { get; set; } = "ImageUploader, TextUploader, FileUploader";
|
||||
public string RequestMethod { get; set; } = "POST";
|
||||
@@ -13,6 +13,6 @@ public class ShareXDestination
|
||||
public string FileFormName { get; set; } = "file";
|
||||
public string[] RegexList { get; set; } = ["([^/]+)/?$"];
|
||||
public string URL { get; set; } = "https://aoba.app$json:url$";
|
||||
public required string ThumbnailURL { get; set; }
|
||||
public required string DeletionURL { get; set; }
|
||||
public string? ThumbnailURL { get; set; }
|
||||
public string? DeletionURL { get; set; }
|
||||
}
|
||||
@@ -109,7 +109,6 @@ if (!app.Environment.IsDevelopment())
|
||||
}
|
||||
|
||||
app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true });
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
|
||||
@@ -123,6 +122,7 @@ app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
app.MapObserability();
|
||||
app.MapGrpcService<AobaRpcService>()
|
||||
.RequireAuthorization()
|
||||
.RequireCors("RPC");
|
||||
app.MapGrpcService<AobaAuthService>()
|
||||
.AllowAnonymous()
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
syntax = "proto3";
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
option csharp_namespace = "Aoba.RPC";
|
||||
package aoba;
|
||||
|
||||
service AobaRpc {
|
||||
rpc GetMedia (Id) returns (MediaResponse);
|
||||
rpc DeleteMedia (Id) returns (Empty);
|
||||
rpc UpdateMedia (Empty) returns (Empty);
|
||||
rpc DeleteMedia (Id) returns (google.protobuf.Empty);
|
||||
rpc UpdateMedia (google.protobuf.Empty) returns (google.protobuf.Empty);
|
||||
rpc ListMedia(PageFilter) returns (ListResponse);
|
||||
rpc GetUser(Id) returns (UserResponse);
|
||||
rpc GetShareXDestination(google.protobuf.Empty) returns (ShareXResponse);
|
||||
}
|
||||
|
||||
message PageFilter {
|
||||
@@ -24,7 +26,7 @@ message Id {
|
||||
message MediaResponse {
|
||||
oneof result {
|
||||
MediaModel value = 1;
|
||||
Empty empty = 2;
|
||||
google.protobuf.Empty empty = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +46,7 @@ message Pagination {
|
||||
message UserResponse {
|
||||
oneof userResult {
|
||||
UserModel user = 1;
|
||||
Empty empty = 2;
|
||||
google.protobuf.Empty empty = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +57,6 @@ message UserModel {
|
||||
bool isAdmin = 4;
|
||||
}
|
||||
|
||||
message Empty {}
|
||||
|
||||
message MediaModel {
|
||||
Id id = 1;
|
||||
@@ -67,7 +68,7 @@ message MediaModel {
|
||||
Id owner = 7;
|
||||
}
|
||||
|
||||
enum MediaType{
|
||||
enum MediaType {
|
||||
Image = 0;
|
||||
Audio = 1;
|
||||
Video = 2;
|
||||
@@ -75,3 +76,10 @@ enum MediaType{
|
||||
Code = 4;
|
||||
Raw = 5;
|
||||
}
|
||||
|
||||
message ShareXResponse {
|
||||
oneof dstResult {
|
||||
string destination = 1;
|
||||
string error = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
using AobaServer.Models;
|
||||
|
||||
using Grpc.Core;
|
||||
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
using MongoDB.Bson;
|
||||
@@ -37,4 +39,9 @@ public static class Extensions
|
||||
{
|
||||
return user.FindFirstValue(ClaimTypes.NameIdentifier).ToObjectId();
|
||||
}
|
||||
|
||||
public static ObjectId GetUserId(this ServerCallContext context)
|
||||
{
|
||||
return context.GetHttpContext().User.GetId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Aoba.RPC;
|
||||
|
||||
using MongoDB.Bson;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace AobaServer.Utils;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user