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