jellyfin/Emby.Server.Implementations/HttpServer/Security/AuthService.cs

43 lines
1.2 KiB
C#
Raw Normal View History

2019-11-01 18:38:54 +01:00
#pragma warning disable CS1591
2020-05-13 04:10:35 +02:00
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Authentication;
2014-07-02 07:16:59 +02:00
using MediaBrowser.Controller.Net;
using Microsoft.AspNetCore.Http;
2016-11-04 02:18:51 +01:00
namespace Emby.Server.Implementations.HttpServer.Security
{
public class AuthService : IAuthService
{
private readonly IAuthorizationContext _authorizationContext;
2014-07-08 03:41:03 +02:00
public AuthService(
2020-09-02 12:22:14 +02:00
IAuthorizationContext authorizationContext)
2014-07-02 07:16:59 +02:00
{
_authorizationContext = authorizationContext;
}
public AuthorizationInfo Authenticate(HttpRequest request)
{
var auth = _authorizationContext.GetAuthorizationInfo(request);
if (!auth.HasToken)
{
throw new AuthenticationException("Request does not contain a token.");
}
if (!auth.IsAuthenticated)
2020-10-15 16:02:59 +02:00
{
throw new SecurityException("Invalid token.");
2020-10-15 16:02:59 +02:00
}
2020-10-15 01:58:33 +02:00
if (auth.User?.HasPermission(PermissionKind.IsDisabled) ?? false)
{
throw new SecurityException("User account has been disabled.");
}
return auth;
}
}
}