Use roles to sync Libraries and Age Rating for simplicty
This commit is contained in:
parent
9f94abe1be
commit
54fb4c7a8a
3 changed files with 11 additions and 9 deletions
|
@ -53,9 +53,9 @@ public static class StringExtensions
|
|||
return string.IsNullOrEmpty(value) ? defaultValue : double.Parse(value, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static string? TrimPrefix(this string? value, string prefix)
|
||||
public static string TrimPrefix(this string? value, string prefix)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) return value;
|
||||
if (string.IsNullOrEmpty(value)) return string.Empty;
|
||||
|
||||
if (!value.StartsWith(prefix)) return value;
|
||||
|
||||
|
|
|
@ -44,8 +44,8 @@ public interface IOidcService
|
|||
public class OidcService(ILogger<OidcService> logger, UserManager<AppUser> userManager,
|
||||
IUnitOfWork unitOfWork, IMapper mapper, IAccountService accountService): IOidcService
|
||||
{
|
||||
private const string LibraryAccessClaim = "library";
|
||||
private const string AgeRatingClaim = "AgeRating";
|
||||
private const string LibraryAccessPrefix = "library-";
|
||||
private const string AgeRatingPrefix = "age-rating-";
|
||||
|
||||
public async Task<AppUser?> LoginOrCreate(ClaimsPrincipal principal)
|
||||
{
|
||||
|
@ -175,8 +175,9 @@ public class OidcService(ILogger<OidcService> logger, UserManager<AppUser> userM
|
|||
private async Task SyncLibraries(ClaimsPrincipal claimsPrincipal, AppUser user)
|
||||
{
|
||||
var libraryAccess = claimsPrincipal
|
||||
.FindAll(LibraryAccessClaim)
|
||||
.Select(r => r.Value)
|
||||
.FindAll(ClaimTypes.Role)
|
||||
.Where(r => r.Value.StartsWith(LibraryAccessPrefix))
|
||||
.Select(r => r.Value.TrimPrefix(LibraryAccessPrefix))
|
||||
.ToList();
|
||||
if (libraryAccess.Count == 0) return;
|
||||
|
||||
|
@ -191,8 +192,9 @@ public class OidcService(ILogger<OidcService> logger, UserManager<AppUser> userM
|
|||
{
|
||||
|
||||
var ageRatings = claimsPrincipal
|
||||
.FindAll(AgeRatingClaim)
|
||||
.Select(r => r.Value)
|
||||
.FindAll(ClaimTypes.Role)
|
||||
.Where(r => r.Value.StartsWith(AgeRatingPrefix))
|
||||
.Select(r => r.Value.TrimPrefix(AgeRatingPrefix))
|
||||
.ToList();
|
||||
if (ageRatings.Count == 0) return;
|
||||
|
||||
|
|
|
@ -373,7 +373,7 @@ public class SettingsService : ISettingsService
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "OpenIdConfiguration failed: {Reason}", e.Message);
|
||||
_logger.LogTrace(e, "OpenIdConfiguration failed: {Reason}", e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue