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);
|
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;
|
if (!value.StartsWith(prefix)) return value;
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@ public interface IOidcService
|
||||||
public class OidcService(ILogger<OidcService> logger, UserManager<AppUser> userManager,
|
public class OidcService(ILogger<OidcService> logger, UserManager<AppUser> userManager,
|
||||||
IUnitOfWork unitOfWork, IMapper mapper, IAccountService accountService): IOidcService
|
IUnitOfWork unitOfWork, IMapper mapper, IAccountService accountService): IOidcService
|
||||||
{
|
{
|
||||||
private const string LibraryAccessClaim = "library";
|
private const string LibraryAccessPrefix = "library-";
|
||||||
private const string AgeRatingClaim = "AgeRating";
|
private const string AgeRatingPrefix = "age-rating-";
|
||||||
|
|
||||||
public async Task<AppUser?> LoginOrCreate(ClaimsPrincipal principal)
|
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)
|
private async Task SyncLibraries(ClaimsPrincipal claimsPrincipal, AppUser user)
|
||||||
{
|
{
|
||||||
var libraryAccess = claimsPrincipal
|
var libraryAccess = claimsPrincipal
|
||||||
.FindAll(LibraryAccessClaim)
|
.FindAll(ClaimTypes.Role)
|
||||||
.Select(r => r.Value)
|
.Where(r => r.Value.StartsWith(LibraryAccessPrefix))
|
||||||
|
.Select(r => r.Value.TrimPrefix(LibraryAccessPrefix))
|
||||||
.ToList();
|
.ToList();
|
||||||
if (libraryAccess.Count == 0) return;
|
if (libraryAccess.Count == 0) return;
|
||||||
|
|
||||||
|
@ -191,8 +192,9 @@ public class OidcService(ILogger<OidcService> logger, UserManager<AppUser> userM
|
||||||
{
|
{
|
||||||
|
|
||||||
var ageRatings = claimsPrincipal
|
var ageRatings = claimsPrincipal
|
||||||
.FindAll(AgeRatingClaim)
|
.FindAll(ClaimTypes.Role)
|
||||||
.Select(r => r.Value)
|
.Where(r => r.Value.StartsWith(AgeRatingPrefix))
|
||||||
|
.Select(r => r.Value.TrimPrefix(AgeRatingPrefix))
|
||||||
.ToList();
|
.ToList();
|
||||||
if (ageRatings.Count == 0) return;
|
if (ageRatings.Count == 0) return;
|
||||||
|
|
||||||
|
|
|
@ -373,7 +373,7 @@ public class SettingsService : ISettingsService
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.LogError(e, "OpenIdConfiguration failed: {Reason}", e.Message);
|
_logger.LogTrace(e, "OpenIdConfiguration failed: {Reason}", e.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue