[backend/masto-client] Implement /oauth/revoke endpoint
This commit is contained in:
parent
3217831d22
commit
2736ce1b71
2 changed files with 31 additions and 10 deletions
|
@ -117,15 +117,22 @@ public class MastodonAuthController(DatabaseContext db) : Controller {
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: implement /oauth/revoke
|
|
||||||
/*
|
|
||||||
[HttpPost("/oauth/revoke")]
|
[HttpPost("/oauth/revoke")]
|
||||||
[ConsumesHybrid]
|
[ConsumesHybrid]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
//[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(MastodonAuth.RegisterAppResponse))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(object))]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))]
|
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))]
|
||||||
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]
|
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]
|
||||||
public async Task<IActionResult> RegisterApp([FromHybrid] ) { }
|
public async Task<IActionResult> 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());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -110,4 +110,18 @@ public abstract class AuthSchemas {
|
||||||
[J("scope")] public string Scope => string.Join(' ', Scopes);
|
[J("scope")] public string Scope => string.Join(' ', Scopes);
|
||||||
[J("created_at")] public long CreatedAtInternal => (long)(CreatedAt - DateTime.UnixEpoch).TotalSeconds;
|
[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!;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue