[2.4.3] - Added IDs for user roles and groups in authorization result

master
Tudor Stanciu 2023-04-12 18:13:37 +03:00
parent 74d68f2329
commit eefa23b3b8
12 changed files with 57 additions and 12 deletions

View File

@ -1,7 +1,7 @@
<Project> <Project>
<Import Project="dependencies.props" /> <Import Project="dependencies.props" />
<PropertyGroup> <PropertyGroup>
<Version>2.4.2</Version> <Version>2.4.3</Version>
<Authors>Tudor Stanciu</Authors> <Authors>Tudor Stanciu</Authors>
<Company>STA</Company> <Company>STA</Company>
<PackageTags>Tuitio</PackageTags> <PackageTags>Tuitio</PackageTags>

View File

@ -114,4 +114,13 @@
◾ New versions of nuget packages have been released. ◾ New versions of nuget packages have been released.
</Content> </Content>
</Note> </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> </ReleaseNotes>

View File

@ -1,7 +1,10 @@
// Copyright (c) 2020 Tudor Stanciu // Copyright (c) 2020 Tudor Stanciu
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Tuitio.Domain.Entities; using Tuitio.Domain.Entities;
using Tuitio.Domain.Models;
namespace Tuitio.Application.Extensions namespace Tuitio.Application.Extensions
{ {
@ -18,5 +21,23 @@ namespace Tuitio.Application.Extensions
return result; 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;
}
} }
} }

View File

@ -10,6 +10,7 @@ namespace Tuitio.Application.Mappings
{ {
public MappingProfile() public MappingProfile()
{ {
CreateMap<models.RecordIdentifier, dto.RecordIdentifier>();
CreateMap<models.Token, dto.AuthorizationResult>(); CreateMap<models.Token, dto.AuthorizationResult>();
CreateMap<models.Account.LogoutResult, dto.AccountLogoutResult>(); CreateMap<models.Account.LogoutResult, dto.AccountLogoutResult>();
} }

View File

@ -22,8 +22,9 @@ namespace Tuitio.Application.Services
{ {
var token = new Token(_configProvider.Token.ValidityInMinutes); var token = new Token(_configProvider.Token.ValidityInMinutes);
var claims = user.Claims?.ToDictionary(); var claims = user.Claims?.ToDictionary();
var userRoles = user.GetUserRoles().Select(z => z.UserRoleCode); var userRoles = user.GetUserRoles().AsRecordIdentifiers();
var userGroups = user.UserGroups?.Select(z => z.UserGroup.UserGroupCode); 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); token.SetUserData(user.UserId, user.UserName, user.FirstName, user.LastName, user.Email, user.SecurityStamp, claims, userRoles, userGroups);
return token; return token;
} }

View File

@ -0,0 +1,6 @@
// Copyright (c) 2020 Tudor Stanciu
namespace Tuitio.Domain.Models
{
public record RecordIdentifier(int Id, string Code);
}

View File

@ -24,10 +24,10 @@ namespace Tuitio.Domain.Models
public Dictionary<string, string> Claims { get; set; } public Dictionary<string, string> Claims { get; set; }
[JsonIgnore] [JsonIgnore]
public IEnumerable<string> UserRoles { get; set; } public IEnumerable<RecordIdentifier> UserRoles { get; set; }
[JsonIgnore] [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.")] [Obsolete("This constructor is only used for deserialization and should not be used for any other purpose.")]
public Token() { } public Token() { }
@ -40,7 +40,7 @@ namespace Tuitio.Domain.Models
ExpiresIn = validityInMinutes * 60; // seconds 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; UserId = userId;
UserName = userName; UserName = userName;

View File

@ -20,7 +20,8 @@ namespace Tuitio.PublishedLanguage.Dto
public DateTime CreatedAt { get; init; } public DateTime CreatedAt { get; init; }
public long ExpiresIn { get; init; } public long ExpiresIn { get; init; }
public Dictionary<string, string> Claims { get; init; } public Dictionary<string, string> Claims { get; init; }
public string[] UserRoles { get; init; } public RecordIdentifier[] UserRoles { get; init; }
public string[] UserGroups { get; init; } public RecordIdentifier[] UserGroups { get; init; }
} }
public record RecordIdentifier(int Id, string Code);
} }

View File

@ -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 ◾ Added user roles and groups in authorization result
2.2.0 release [2023-03-27 19:20] 2.2.0 release [2023-03-27 19:20]

View File

@ -7,7 +7,7 @@
<RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</RepositoryUrl> <RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</RepositoryUrl>
<RepositoryType>Git</RepositoryType> <RepositoryType>Git</RepositoryType>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/ReleaseNotes.txt"))</PackageReleaseNotes> <PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/ReleaseNotes.txt"))</PackageReleaseNotes>
<Version>2.2.1</Version> <Version>2.2.2</Version>
<PackageIcon>logo.png</PackageIcon> <PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>
<Company>Toodle HomeLab</Company> <Company>Toodle HomeLab</Company>

View File

@ -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 ◾ Added user roles and groups in authorization result
2.2.0 release [2023-03-27 19:20] 2.2.0 release [2023-03-27 19:20]

View File

@ -7,7 +7,7 @@
<RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</RepositoryUrl> <RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</RepositoryUrl>
<RepositoryType>Git</RepositoryType> <RepositoryType>Git</RepositoryType>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/ReleaseNotes.txt"))</PackageReleaseNotes> <PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/ReleaseNotes.txt"))</PackageReleaseNotes>
<Version>2.2.1</Version> <Version>2.2.2</Version>
<PackageIcon>logo.png</PackageIcon> <PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>
<Company>Toodle HomeLab</Company> <Company>Toodle HomeLab</Company>