This commit is contained in:
parent
b0a19fe668
commit
7b9e50bde2
5 changed files with 59 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
|||
using System.Net;
|
||||
using System.Net.Mime;
|
||||
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
|
||||
using Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
|
||||
using Iceshrimp.Backend.Controllers.Shared.Attributes;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
|
@ -8,6 +9,7 @@ using Iceshrimp.Backend.Core.Extensions;
|
|||
using Iceshrimp.Backend.Core.Helpers;
|
||||
using Iceshrimp.Backend.Core.Middleware;
|
||||
using Iceshrimp.Backend.Core.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
|
@ -157,4 +159,44 @@ public class AuthController(DatabaseContext db, MetaService meta) : ControllerBa
|
|||
|
||||
return new object();
|
||||
}
|
||||
|
||||
[Authenticate]
|
||||
[HttpGet("/api/oauth_tokens.json")]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
public async Task<List<PleromaOauthTokenEntity>> GetOauthTokens()
|
||||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
var oauthTokens = await db.OauthTokens
|
||||
.Where(p => p.User == user)
|
||||
.Include(oauthToken => oauthToken.App)
|
||||
.ToListAsync();
|
||||
|
||||
List<PleromaOauthTokenEntity> result = [];
|
||||
foreach (var token in oauthTokens)
|
||||
{
|
||||
result.Add(new PleromaOauthTokenEntity()
|
||||
{
|
||||
Id = token.Id,
|
||||
AppName = token.App.Name,
|
||||
ValidUntil = token.CreatedAt + TimeSpan.FromDays(365 * 100)
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[Authenticate]
|
||||
[HttpDelete("/api/oauth_tokens/{id}")]
|
||||
[ProducesResults(HttpStatusCode.Created)]
|
||||
[ProducesErrors(HttpStatusCode.BadRequest, HttpStatusCode.Forbidden)]
|
||||
public async Task RevokeOauthTokenPleroma(string id)
|
||||
{
|
||||
var token = await db.OauthTokens.FirstOrDefaultAsync(p => p.Id == id) ??
|
||||
throw GracefulException.Forbidden("You are not authorized to revoke this token");
|
||||
|
||||
db.Remove(token);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
Response.StatusCode = 201;
|
||||
}
|
||||
}
|
|
@ -65,7 +65,7 @@ public class UserRenderer(
|
|||
}
|
||||
else
|
||||
{
|
||||
favicon = "http://localhost:3000/_content/Iceshrimp.Assets.Branding/favicon.wy3b9djz5j.png";
|
||||
favicon = config.Value.WebDomain + "/_content/Iceshrimp.Assets.Branding/favicon.png";
|
||||
softwareName = "iceshrimp";
|
||||
softwareVersion = config.Value.Version;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
using System.Runtime.InteropServices.JavaScript;
|
||||
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
|
||||
|
||||
namespace Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
|
||||
|
||||
public class PleromaOauthTokenEntity
|
||||
{
|
||||
[J("id")] public required string Id { get; set; }
|
||||
[J("valid_until")] public required DateTime ValidUntil { get; set; }
|
||||
[J("app_name")] public required string? AppName { get; set; }
|
||||
}
|
|
@ -6,7 +6,7 @@ namespace Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
|
|||
[Keyless]
|
||||
public class PleromaUserExtensions
|
||||
{
|
||||
[J("is_admin")] public required bool IsAdmin { get; set; }
|
||||
[J("is_moderator")] public required bool IsModerator { get; set; }
|
||||
[J("favicon")] public required string Favicon { get; set; }
|
||||
[J("is_admin")] public required bool IsAdmin { get; set; }
|
||||
[J("is_moderator")] public required bool IsModerator { get; set; }
|
||||
[J("favicon")] public required string Favicon { get; set; }
|
||||
}
|
|
@ -7,8 +7,8 @@ ListenHost = localhost
|
|||
;;ListenSocketPerms = 660
|
||||
|
||||
;; Caution: changing these settings after initial setup *will* break federation
|
||||
WebDomain = shrimp.example.org
|
||||
AccountDomain = example.org
|
||||
WebDomain = localhost:3000
|
||||
AccountDomain = localhost:3000
|
||||
;; End of problematic settings block
|
||||
|
||||
;; Additional domains this instance allows API access from, separated by commas.
|
||||
|
|
Loading…
Add table
Reference in a new issue