Activities of "bhyatz"

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v3.0.4
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): yes / no
  • Exception message and stack trace: None
  • Steps to reproduce the issue:

I can't see the custom claim in the current user or pricipal

I have added a custom claim type "testClaimType" using the frontend

I have added the a claim value for this claim to the Admin user

During Login The AbpUserClaimsPrincipalFactory loads the custom claims correctly. As you can see there is claim of testClaimType with value 12.

However the claim type does not show in the current user claims or the ClaimsPrincipal .

How do you get the claims for the custom claim types for the current user?

Is it possible to add the custom claim types to the current users claims?

Answer

I am using identity server and the ui is angular.

I have currently implemented this by extending the Volo.Abp.Identity.IdentityUser and updating GetRolesAsync,IsInRoleAsync and GetActiveRoles to filter only the active roles. I am not sure if this is the best way or not.

Question

I have extended abpuserroles to include Active and Inactive dates so a user will only have a role between these dates.

However I found several places where the user roles are used in the code. However I can't find the place where the roles are assigned to the user when he logs in.

I need to change the login so that only roles that are active are assigned to a user when he logs in. Where do I modify this logic?

Answer

Hi

I am getting the following error, I have tried the above and it is still not working. I only develop on one computer.

Answer

According to https://github.com/abpframework/abp/issues/1082 this has been added to backlog with priority high, do you have an idea when this would be implemented?

Question

What is the best way to implement impersonation in the current framework?

Question

Hi

    I would like to add valid from and valid to dates for user roles. 
    I need the user to only have a role between these dates.
    How do I implemet this functionality so that the roles are only returned if the current dates are between these dates.
Answer

Hi Alper

We are using the angular ui , not mvc. How would you do this on the angular ui?

Answer

I am not sure if this is the correct way. I created my own IResourceOwnerPasswordValidator that extends AbpResourceOwnerPasswordValidator. I modified ValidateAsync to include my own rules and than called await base.ValidateAsync(context);

public override async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            await ReplaceEmailToUsernameOfInputIfNeeds(context).ConfigureAwait(false);

            var user = _abUserManager.GetUser(context.UserName);
            if (user != null)
            {
                var now = DateTime.Now;

                if (user.ValidFromDate.CompareTo(now) > 0 || user.ValidToInclDate.AddDays(1).CompareTo(now) < 0)
                {
                    _logger.LogInformation("User not in valid from and valid to dates : {username}", context.UserName);
                    await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "login not valid for dates", interactive: false)).ConfigureAwait(false);
                    context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant,"User Login not valid for current Date");
                }
                else if(!user.Active)
                {
                    _logger.LogInformation("User is deactivated : {username}", context.UserName);
                    await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "is deactivated", interactive: false)).ConfigureAwait(false);
                    context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "User is deactivated");
                }
                else
                {
                    await base.ValidateAsync(context);
                }
            }
            else
            {
                _logger.LogInformation("No user found matching username: {username}", context.UserName);
                await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid username", interactive: false)).ConfigureAwait(false);
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant);
            }
        }

I also createe my own service to add users with the extra properties. I first create the user using the injected IAbUserManager and then update the user using the custom user respository

public override async Task<AbUserDto> CreateAsync(AbUserCreateDto input)
        {
            var user = _abUserManager.GetUser(input.Username);

            if (user != null)
            {
                throw new BusinessException(AumErrorCodes.UserNameExists);
            }

            await ValidateInput(input.PhoneNumbers,input.PersonTypeId,input.CompanyId);
            var emailAddress = input.EmailAddresses.First().EmailAddress;

            var userId  = await _abUserManager.CreateUserAsync(input.Username, input.Password, emailAddress,
            input.ValidFromDate, input.ValidToInclDate, input.Active, input.DeactivationReason);

            input.AbpUserId = userId;

            return await base.CreateAsync(input);
        }
Question

I have added custom properties to Appuser /* Add your own properties here. Example: * * public virtual string MyProperty { get; set; } */ public virtual bool Active { get; set; } = false; public virtual DateTime ValidFromDate { get; set; } public virtual DateTime ValidToInclDate { get; set; } public virtual string DeactivationReason { get; set; }

What is the best way to extend the login validation to check if the user is active and if the current date is between the Valid From and Valid To dates when the user logs in. How do I customize the adduser to include the added fields when creating the user?

Showing 11 to 20 of 24 entries
Made with ❤️ on ABP v9.2.0-preview. Updated on January 14, 2025, 14:54