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