NDB.Security.Authentication.Identity - guest user claim

messaging
Tudor Stanciu 2021-06-29 10:01:18 +03:00
parent 685be06f80
commit 67a9b643d8
5 changed files with 14 additions and 4 deletions

View File

@ -6,6 +6,7 @@
<PackageProjectUrl>https://dev.azure.com/tstanciu94/NDB</PackageProjectUrl> <PackageProjectUrl>https://dev.azure.com/tstanciu94/NDB</PackageProjectUrl>
<RepositoryUrl>https://dev.azure.com/tstanciu94/NDB</RepositoryUrl> <RepositoryUrl>https://dev.azure.com/tstanciu94/NDB</RepositoryUrl>
<RepositoryType>Git</RepositoryType> <RepositoryType>Git</RepositoryType>
<PackageTags>NDB Cache</PackageTags>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,8 @@
namespace NDB.Security.Authentication.Identity.Constants
{
public struct ClaimTypes
{
public const string
IsGuestUser = "IsGuestUser";
}
}

View File

@ -30,7 +30,7 @@ namespace NDB.Security.Authentication.Identity
var authenticateAsGuest = _authenticationOptions.AuthenticateAsGuest?.Invoke(Request) ?? false; var authenticateAsGuest = _authenticationOptions.AuthenticateAsGuest?.Invoke(Request) ?? false;
if (authenticateAsGuest) if (authenticateAsGuest)
{ {
var guestTicket = GetAuthenticationTicket(new User() { UserId = _authenticationOptions.GuestUserId, UserName = _authenticationOptions.GuestUserName }); var guestTicket = GetAuthenticationTicket(new User() { UserId = _authenticationOptions.GuestUserId, UserName = _authenticationOptions.GuestUserName }, true);
return AuthenticateResult.Success(guestTicket); return AuthenticateResult.Success(guestTicket);
} }
@ -56,11 +56,12 @@ namespace NDB.Security.Authentication.Identity
return AuthenticateResult.Success(ticket); return AuthenticateResult.Success(ticket);
} }
private AuthenticationTicket GetAuthenticationTicket(User user) private AuthenticationTicket GetAuthenticationTicket(User user, bool isGuest = false)
{ {
var claims = new[] { var claims = new[] {
new Claim(ClaimTypes.NameIdentifier, user.UserId.ToString()), new Claim(ClaimTypes.NameIdentifier, user.UserId.ToString()),
new Claim(ClaimTypes.Name, user.UserName), new Claim(ClaimTypes.Name, user.UserName),
new Claim(Constants.ClaimTypes.IsGuestUser, isGuest.ToString())
}; };
var identity = new ClaimsIdentity(claims, Scheme.Name); var identity = new ClaimsIdentity(claims, Scheme.Name);

View File

@ -7,7 +7,7 @@
<RepositoryUrl>https://dev.azure.com/tstanciu94/NDB</RepositoryUrl> <RepositoryUrl>https://dev.azure.com/tstanciu94/NDB</RepositoryUrl>
<RepositoryType>Git</RepositoryType> <RepositoryType>Git</RepositoryType>
<PackageTags>NDB Authentication Identity</PackageTags> <PackageTags>NDB Authentication Identity</PackageTags>
<Version>1.0.2</Version> <Version>1.0.3</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -22,7 +22,7 @@ dotnet nuget push NDB.Extensions.Swagger.1.0.2.nupkg -k ***REMOVED*** -s http://
dotnet nuget push NDB.Extensions.Http.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget dotnet nuget push NDB.Extensions.Http.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget
dotnet nuget push NDB.Security.Authentication.Identity.1.0.2.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget dotnet nuget push NDB.Security.Authentication.Identity.1.0.3.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget
dotnet nuget push NDB.Extensions.Caching.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget dotnet nuget push NDB.Extensions.Caching.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget
####################################################################################################################################################### #######################################################################################################################################################