|
|
@ -18,11 +18,17 @@ namespace Jellyfin.Server.Filters
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var requiredScopes = new List<string>();
|
|
|
|
var requiredScopes = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var requiresAuth = false;
|
|
|
|
// Add all method scopes.
|
|
|
|
// Add all method scopes.
|
|
|
|
foreach (var attribute in context.MethodInfo.GetCustomAttributes(true))
|
|
|
|
foreach (var attribute in context.MethodInfo.GetCustomAttributes(true))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (attribute is AuthorizeAttribute authorizeAttribute
|
|
|
|
if (attribute is not AuthorizeAttribute authorizeAttribute)
|
|
|
|
&& authorizeAttribute.Policy is not null
|
|
|
|
{
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requiresAuth = true;
|
|
|
|
|
|
|
|
if (authorizeAttribute.Policy is not null
|
|
|
|
&& !requiredScopes.Contains(authorizeAttribute.Policy, StringComparer.Ordinal))
|
|
|
|
&& !requiredScopes.Contains(authorizeAttribute.Policy, StringComparer.Ordinal))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
requiredScopes.Add(authorizeAttribute.Policy);
|
|
|
|
requiredScopes.Add(authorizeAttribute.Policy);
|
|
|
@ -35,8 +41,13 @@ namespace Jellyfin.Server.Filters
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var attribute in controllerAttributes)
|
|
|
|
foreach (var attribute in controllerAttributes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (attribute is AuthorizeAttribute authorizeAttribute
|
|
|
|
if (attribute is not AuthorizeAttribute authorizeAttribute)
|
|
|
|
&& authorizeAttribute.Policy is not null
|
|
|
|
{
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requiresAuth = true;
|
|
|
|
|
|
|
|
if (authorizeAttribute.Policy is not null
|
|
|
|
&& !requiredScopes.Contains(authorizeAttribute.Policy, StringComparer.Ordinal))
|
|
|
|
&& !requiredScopes.Contains(authorizeAttribute.Policy, StringComparer.Ordinal))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
requiredScopes.Add(authorizeAttribute.Policy);
|
|
|
|
requiredScopes.Add(authorizeAttribute.Policy);
|
|
|
@ -44,8 +55,11 @@ namespace Jellyfin.Server.Filters
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (requiredScopes.Count != 0)
|
|
|
|
if (!requiresAuth)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!operation.Responses.ContainsKey("401"))
|
|
|
|
if (!operation.Responses.ContainsKey("401"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
operation.Responses.Add("401", new OpenApiResponse { Description = "Unauthorized" });
|
|
|
|
operation.Responses.Add("401", new OpenApiResponse { Description = "Unauthorized" });
|
|
|
@ -74,5 +88,4 @@ namespace Jellyfin.Server.Filters
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|