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

43 lines
1.1 KiB
C#
Raw Normal View History

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