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