Skip to content

Commit

Permalink
Fix 500 in DELETE apikey
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Jan 17, 2024
1 parent 9997340 commit 45394e0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Shoko.Server/API/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ public ActionResult ChangePassword([FromBody] string newPassword)
///</summary>
///<param name="apikey">The Apikey or device to delete.</param>
[HttpDelete]
public ActionResult Delete(string apikey)
public ActionResult Delete([FromBody]string apikey)
{
var token = RepoFactory.AuthTokens.GetAll().FirstOrDefault(a => a.UserID == User?.JMMUserID && a.DeviceName.EqualsInvariantIgnoreCase(apikey));
if (apikey == null) return BadRequest("Must provide an apikey or device name to delete");
var token = RepoFactory.AuthTokens.GetAll().FirstOrDefault(a => a.UserID == User?.JMMUserID && apikey.EqualsInvariantIgnoreCase(a.DeviceName));
token ??= RepoFactory.AuthTokens.GetByToken(apikey);
if (User?.JMMUserID != token.UserID && User?.IsAdmin != 1) return Unauthorized("Cannot delete a token for another user");
if (token == null) return BadRequest("Could not find apikey or device name to delete");
RepoFactory.AuthTokens.Delete(token);
return Ok();
}
Expand Down

0 comments on commit 45394e0

Please sign in to comment.