Kavita/API/Extensions/ClaimsPrincipalExtensions.cs
Joseph Milazzo aaad82cb7a
Reduce Unauthenticated Errors in Sentry (#238)
* Updated README to be explicit that kavita.db needs to be writable.

* Implemented a new Exception type that is for throwing a message to UI without logging in Sentry.
2021-06-01 06:57:46 -05:00

15 lines
431 B
C#

using System.Security.Claims;
using Kavita.Common;
namespace API.Extensions
{
public static class ClaimsPrincipalExtensions
{
public static string GetUsername(this ClaimsPrincipal user)
{
var userClaim = user.FindFirst(ClaimTypes.NameIdentifier);
if (userClaim == null) throw new KavitaException("User is not authenticated");
return userClaim.Value;
}
}
}