diff --git a/Iceshrimp.Backend/Controllers/Mastodon/MastodonAuthController.cs b/Iceshrimp.Backend/Controllers/Mastodon/MastodonAuthController.cs index 098d4e9a..5759de4f 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/MastodonAuthController.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/MastodonAuthController.cs @@ -117,15 +117,22 @@ public class MastodonAuthController(DatabaseContext db) : Controller { return Ok(res); } - //TODO: implement /oauth/revoke - /* -[HttpPost("/oauth/revoke")] -[ConsumesHybrid] -[Produces("application/json")] -//[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(MastodonAuth.RegisterAppResponse))] -[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))] -[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))] -public async Task RegisterApp([FromHybrid] ) { } + [HttpPost("/oauth/revoke")] + [ConsumesHybrid] + [Produces("application/json")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(object))] + [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))] + [ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))] + public async Task RevokeOauthToken([FromHybrid] AuthSchemas.OauthTokenRevocationRequest request) { + var token = await db.OauthTokens.FirstOrDefaultAsync(p => p.Token == request.Token && + p.App.ClientId == request.ClientId && + p.App.ClientSecret == request.ClientSecret); + if (token == null) + throw GracefulException.Forbidden("You are not authorized to revoke this token"); -*/ + db.Remove(token); + await db.SaveChangesAsync(); + + return Ok(new object()); + } } \ No newline at end of file diff --git a/Iceshrimp.Backend/Controllers/Mastodon/Schemas/AuthSchemas.cs b/Iceshrimp.Backend/Controllers/Mastodon/Schemas/AuthSchemas.cs index eebdd816..6e485acf 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/Schemas/AuthSchemas.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/Schemas/AuthSchemas.cs @@ -110,4 +110,18 @@ public abstract class AuthSchemas { [J("scope")] public string Scope => string.Join(' ', Scopes); [J("created_at")] public long CreatedAtInternal => (long)(CreatedAt - DateTime.UnixEpoch).TotalSeconds; } + + public class OauthTokenRevocationRequest { + [B(Name = "client_id")] + [J("client_id")] + [JR] + public string ClientId { get; set; } = null!; + + [B(Name = "client_secret")] + [J("client_secret")] + [JR] + public string ClientSecret { get; set; } = null!; + + [B(Name = "code")] [J("token")] [JR] public string Token { get; set; } = null!; + } } \ No newline at end of file