HI
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;
namespace BookStore;
public class MyRoleValidator : IRoleValidator<IdentityRole>
{
public MyRoleValidator(IdentityErrorDescriber? errors = null)
{
Describer = errors ?? new IdentityErrorDescriber();
}
private IdentityErrorDescriber Describer { get; set; }
public virtual async Task<IdentityResult> ValidateAsync(RoleManager<IdentityRole> manager, IdentityRole role)
{
if (manager == null)
{
throw new ArgumentNullException(nameof(manager));
}
if (role == null)
{
throw new ArgumentNullException(nameof(role));
}
var errors = new List<IdentityError>();
await ValidateRoleName(manager, role, errors).ConfigureAwait(false);
if (errors.Count > 0)
{
return IdentityResult.Failed(errors.ToArray());
}
return IdentityResult.Success;
}
private async Task ValidateRoleName(RoleManager<IdentityRole> manager, IdentityRole role, ICollection<IdentityError> errors)
{
var roleName = await manager.GetRoleNameAsync(role).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(roleName))
{
errors.Add(Describer.InvalidRoleName(roleName));
}
else
{
// Add your custom validation here
// var owner = await manager.FindByNameAsync(roleName).ConfigureAwait(false);
// if (owner != null &&
// !string.Equals(await manager.GetRoleIdAsync(owner).ConfigureAwait(false), await manager.GetRoleIdAsync(role).ConfigureAwait(false)))
// {
// errors.Add(Describer.DuplicateRoleName(roleName));
// }
}
}
}
public class BookStoreDomainModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.RemoveAll(x => x.ServiceType == typeof(IRoleValidator<IdentityRole>));
context.Services.AddScoped<IRoleValidator<IdentityRole>, MyRoleValidator>();
//....
}
}
hi
Please share the code of yourlogout code, Thanks
Hi
Add your code into CurrentPrincipalAccessor' changescope.
var userPrincipal = await SignInManager.CreateUserPrincipalAsync(user);
using (CurrentPrincipalAccessor.Change(userPrincipal))
{
await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
Action = "Login" + result
});
}
var userPrincipal = await SignInManager.CreateUserPrincipalAsync(user);
using (CurrentPrincipalAccessor.Change(userPrincipal))
{
await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
Action = result.ToIdentitySecurityLogAction(),
UserName = user.Name
});
}
hi
var userPrincipal = await SignInManager.CreateUserPrincipalAsync(user);
using (CurrentPrincipalAccessor.Change(userPrincipal))
{
await IdentitySecurityLogManager.SaveAsync()
}
hi
I mean your code instead of IdentitySecurityLogManager source code.
we are using this to add UserName but here UserId is not present.
Where did you call the below code? Please share the code. Thanks
await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.Identity,
Action = Microsoft.AspNetCore.Identity.SignInResult.Success.ToIdentitySecurityLogAction(),
UserName = user.Name
});
hi
This is related to angular-oauth2-oidc, our angular team will check and reply to you.
hi
You can share the logs of authserver now without set level.
hi
It seems the logs don't contain authserver website.
Can you share the logs of all website? Thanks
Also set the level to Debug will be best.
public async static Task<int> Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Async(c => c.File("Logs/logs.txt"))
.WriteTo.Async(c => c.Console())
.CreateLogger();