oauth stuff
Some checks are pending
/ test-build-and-push (push) Waiting to run

This commit is contained in:
notfire 2025-04-11 18:22:56 -04:00
parent b0a19fe668
commit 7b9e50bde2
Signed by: notfire
GPG key ID: 3AFDACAAB4E56B16
5 changed files with 59 additions and 6 deletions

View file

@ -1,6 +1,7 @@
using System.Net; using System.Net;
using System.Net.Mime; using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Mastodon.Attributes; using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
using Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
using Iceshrimp.Backend.Controllers.Shared.Attributes; using Iceshrimp.Backend.Controllers.Shared.Attributes;
using Iceshrimp.Backend.Core.Database; using Iceshrimp.Backend.Core.Database;
using Iceshrimp.Backend.Core.Database.Tables; using Iceshrimp.Backend.Core.Database.Tables;
@ -8,6 +9,7 @@ using Iceshrimp.Backend.Core.Extensions;
using Iceshrimp.Backend.Core.Helpers; using Iceshrimp.Backend.Core.Helpers;
using Iceshrimp.Backend.Core.Middleware; using Iceshrimp.Backend.Core.Middleware;
using Iceshrimp.Backend.Core.Services; using Iceshrimp.Backend.Core.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting; using Microsoft.AspNetCore.RateLimiting;
@ -157,4 +159,44 @@ public class AuthController(DatabaseContext db, MetaService meta) : ControllerBa
return new object(); 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;
}
} }

View file

@ -65,7 +65,7 @@ public class UserRenderer(
} }
else else
{ {
favicon = "http://localhost:3000/_content/Iceshrimp.Assets.Branding/favicon.wy3b9djz5j.png"; favicon = config.Value.WebDomain + "/_content/Iceshrimp.Assets.Branding/favicon.png";
softwareName = "iceshrimp"; softwareName = "iceshrimp";
softwareVersion = config.Value.Version; softwareVersion = config.Value.Version;
} }

View file

@ -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; }
}

View file

@ -6,7 +6,7 @@ namespace Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
[Keyless] [Keyless]
public class PleromaUserExtensions public class PleromaUserExtensions
{ {
[J("is_admin")] public required bool IsAdmin { get; set; } [J("is_admin")] public required bool IsAdmin { get; set; }
[J("is_moderator")] public required bool IsModerator { get; set; } [J("is_moderator")] public required bool IsModerator { get; set; }
[J("favicon")] public required string Favicon { get; set; } [J("favicon")] public required string Favicon { get; set; }
} }

View file

@ -7,8 +7,8 @@ ListenHost = localhost
;;ListenSocketPerms = 660 ;;ListenSocketPerms = 660
;; Caution: changing these settings after initial setup *will* break federation ;; Caution: changing these settings after initial setup *will* break federation
WebDomain = shrimp.example.org WebDomain = localhost:3000
AccountDomain = example.org AccountDomain = localhost:3000
;; End of problematic settings block ;; End of problematic settings block
;; Additional domains this instance allows API access from, separated by commas. ;; Additional domains this instance allows API access from, separated by commas.