Skip to content

Commit

Permalink
Merge pull request #6837 from crobibero/auth-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaboniface committed Nov 13, 2021
2 parents f0028c7 + 4a28f46 commit 761a4e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<AuthorizationInfo> Authenticate(HttpRequest request)

if (!auth.HasToken)
{
throw new AuthenticationException("Request does not contain a token.");
return auth;
}

if (!auth.IsAuthenticated)
Expand Down
7 changes: 6 additions & 1 deletion Emby.Server.Implementations/HttpServer/WebSocketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public class WebSocketManager : IWebSocketManager
/// <inheritdoc />
public async Task WebSocketRequestHandler(HttpContext context)
{
_ = await _authService.Authenticate(context.Request).ConfigureAwait(false);
var authorizationInfo = await _authService.Authenticate(context.Request).ConfigureAwait(false);
if (!authorizationInfo.IsAuthenticated)
{
throw new SecurityException("Token is required");
}

try
{
_logger.LogInformation("WS {IP} request", context.Connection.RemoteIpAddress);
Expand Down
5 changes: 5 additions & 0 deletions Jellyfin.Api/Auth/CustomAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
try
{
var authorizationInfo = await _authService.Authenticate(Request).ConfigureAwait(false);
if (!authorizationInfo.HasToken)
{
return AuthenticateResult.NoResult();
}

var role = UserRoles.User;
if (authorizationInfo.IsApiKey || authorizationInfo.User.HasPermission(PermissionKind.IsAdministrator))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ private AuthorizationInfo SetupUser(bool isAdmin = false)
authorizationInfo.User.AddDefaultPreferences();
authorizationInfo.User.SetPermission(PermissionKind.IsAdministrator, isAdmin);
authorizationInfo.IsApiKey = false;
authorizationInfo.HasToken = true;
authorizationInfo.Token = "fake-token";

_jellyfinAuthServiceMock.Setup(
a => a.Authenticate(
Expand Down

0 comments on commit 761a4e8

Please sign in to comment.