[2.4.3] - Added IDs for user roles and groups in authorization result
parent
74d68f2329
commit
eefa23b3b8
|
@ -1,7 +1,7 @@
|
|||
<Project>
|
||||
<Import Project="dependencies.props" />
|
||||
<PropertyGroup>
|
||||
<Version>2.4.2</Version>
|
||||
<Version>2.4.3</Version>
|
||||
<Authors>Tudor Stanciu</Authors>
|
||||
<Company>STA</Company>
|
||||
<PackageTags>Tuitio</PackageTags>
|
||||
|
|
|
@ -114,4 +114,13 @@
|
|||
◾ New versions of nuget packages have been released.
|
||||
</Content>
|
||||
</Note>
|
||||
<Note>
|
||||
<Version>2.4.3</Version>
|
||||
<Date>2023-04-12 20:37</Date>
|
||||
<Content>
|
||||
Added IDs for user roles and groups in authorization result
|
||||
◾ Based on the development from the previous version, the authorization result has been extended and will contain both IDs and codes for the groups and roles of the authenticated user.
|
||||
◾ New versions of nuget packages have been released.
|
||||
</Content>
|
||||
</Note>
|
||||
</ReleaseNotes>
|
|
@ -1,7 +1,10 @@
|
|||
// Copyright (c) 2020 Tudor Stanciu
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Tuitio.Domain.Entities;
|
||||
using Tuitio.Domain.Models;
|
||||
|
||||
namespace Tuitio.Application.Extensions
|
||||
{
|
||||
|
@ -18,5 +21,23 @@ namespace Tuitio.Application.Extensions
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IEnumerable<RecordIdentifier> AsRecordIdentifiers(this IEnumerable<UserGroup> userGroups)
|
||||
{
|
||||
if (userGroups == null)
|
||||
throw new ArgumentNullException(nameof(userGroups));
|
||||
|
||||
var result = userGroups.Select(z => new RecordIdentifier(z.UserGroupId, z.UserGroupCode));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IEnumerable<RecordIdentifier> AsRecordIdentifiers(this IEnumerable<UserRole> userRoles)
|
||||
{
|
||||
if (userRoles == null)
|
||||
throw new ArgumentNullException(nameof(userRoles));
|
||||
|
||||
var result = userRoles.Select(z => new RecordIdentifier(z.UserRoleId, z.UserRoleCode));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Tuitio.Application.Mappings
|
|||
{
|
||||
public MappingProfile()
|
||||
{
|
||||
CreateMap<models.RecordIdentifier, dto.RecordIdentifier>();
|
||||
CreateMap<models.Token, dto.AuthorizationResult>();
|
||||
CreateMap<models.Account.LogoutResult, dto.AccountLogoutResult>();
|
||||
}
|
||||
|
|
|
@ -22,8 +22,9 @@ namespace Tuitio.Application.Services
|
|||
{
|
||||
var token = new Token(_configProvider.Token.ValidityInMinutes);
|
||||
var claims = user.Claims?.ToDictionary();
|
||||
var userRoles = user.GetUserRoles().Select(z => z.UserRoleCode);
|
||||
var userGroups = user.UserGroups?.Select(z => z.UserGroup.UserGroupCode);
|
||||
var userRoles = user.GetUserRoles().AsRecordIdentifiers();
|
||||
var userGroups = user.UserGroups?.Select(z => z.UserGroup).AsRecordIdentifiers();
|
||||
|
||||
token.SetUserData(user.UserId, user.UserName, user.FirstName, user.LastName, user.Email, user.SecurityStamp, claims, userRoles, userGroups);
|
||||
return token;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
// Copyright (c) 2020 Tudor Stanciu
|
||||
|
||||
namespace Tuitio.Domain.Models
|
||||
{
|
||||
public record RecordIdentifier(int Id, string Code);
|
||||
}
|
|
@ -24,10 +24,10 @@ namespace Tuitio.Domain.Models
|
|||
public Dictionary<string, string> Claims { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public IEnumerable<string> UserRoles { get; set; }
|
||||
public IEnumerable<RecordIdentifier> UserRoles { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public IEnumerable<string> UserGroups { get; set; }
|
||||
public IEnumerable<RecordIdentifier> UserGroups { get; set; }
|
||||
|
||||
[Obsolete("This constructor is only used for deserialization and should not be used for any other purpose.")]
|
||||
public Token() { }
|
||||
|
@ -40,7 +40,7 @@ namespace Tuitio.Domain.Models
|
|||
ExpiresIn = validityInMinutes * 60; // seconds
|
||||
}
|
||||
|
||||
public void SetUserData(int userId, string userName, string firstName, string lastName, string email, string securityStamp, Dictionary<string, string> claims, IEnumerable<string> userRoles, IEnumerable<string> userGroups)
|
||||
public void SetUserData(int userId, string userName, string firstName, string lastName, string email, string securityStamp, Dictionary<string, string> claims, IEnumerable<RecordIdentifier> userRoles, IEnumerable<RecordIdentifier> userGroups)
|
||||
{
|
||||
UserId = userId;
|
||||
UserName = userName;
|
||||
|
|
|
@ -20,7 +20,8 @@ namespace Tuitio.PublishedLanguage.Dto
|
|||
public DateTime CreatedAt { get; init; }
|
||||
public long ExpiresIn { get; init; }
|
||||
public Dictionary<string, string> Claims { get; init; }
|
||||
public string[] UserRoles { get; init; }
|
||||
public string[] UserGroups { get; init; }
|
||||
public RecordIdentifier[] UserRoles { get; init; }
|
||||
public RecordIdentifier[] UserGroups { get; init; }
|
||||
}
|
||||
public record RecordIdentifier(int Id, string Code);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
2.2.1 release [2023-04-08 01:48]
|
||||
2.2.2 release [2023-04-12 20:37]
|
||||
◾ Added IDs for user roles and groups in authorization result
|
||||
|
||||
2.2.1 release [2023-04-08 01:48]
|
||||
◾ Added user roles and groups in authorization result
|
||||
|
||||
2.2.0 release [2023-03-27 19:20]
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</RepositoryUrl>
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/ReleaseNotes.txt"))</PackageReleaseNotes>
|
||||
<Version>2.2.1</Version>
|
||||
<Version>2.2.2</Version>
|
||||
<PackageIcon>logo.png</PackageIcon>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<Company>Toodle HomeLab</Company>
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
2.2.1 release [2023-04-08 01:48]
|
||||
2.2.2 release [2023-04-12 20:37]
|
||||
◾ Added IDs for user roles and groups in authorization result
|
||||
|
||||
2.2.1 release [2023-04-08 01:48]
|
||||
◾ Added user roles and groups in authorization result
|
||||
|
||||
2.2.0 release [2023-03-27 19:20]
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</RepositoryUrl>
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/ReleaseNotes.txt"))</PackageReleaseNotes>
|
||||
<Version>2.2.1</Version>
|
||||
<Version>2.2.2</Version>
|
||||
<PackageIcon>logo.png</PackageIcon>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<Company>Toodle HomeLab</Company>
|
||||
|
|
Loading…
Reference in New Issue