Open Closed

Volo.Authorization:010001 Exception, On Creating Tenant Using ITenantAppService #3041


User avatar
0
hmahmood created
  • ABP Framework version: v4.4.4

  • UI type: MVC

  • DB provider: EF Core

  • Tiered (MVC) or Identity Server Separated (Angular): yes

In our application, we are creating the registration for tenants. When a user register in the application, we need to create a tenant and the admin user for that particular tenant. We are creating the tenant using ITenantAppService and user using IUserAppService. On creating tenant and user we are getting the volo.abp.authorixation exception. Which is occurring correctly because no user is logged in the application. As per our scenario we need to create the users and tenants without user logged in.

Please provide a way forward, how to achieve this in current scenario. Any suggestions would be much appreciated. Exception detail is provided below.

error.png


7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer
  • User Avatar
    0
    hmahmood created

    hi

    You can check this https://support.abp.io/QA/Questions/1761/ProfileAppServiceGetAsync--problem#answer-4b2e5dbb-9db6-371e-a6c2-39fe8d1865bc

    Hello,

    Thanks for the suggestion. We are not able to use the SignInManager in the way described in the above answer. Can you please provide detail how to use it in the current version.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    In our application, we are creating the registration for tenants. When a user register in the application, we need to create a tenant and the admin user for that particular tenant. We are creating the tenant using ITenantAppService and user using IUserAppService. On creating tenant and user we are getting the volo.abp.authorixation exception.

    Please share your code.

  • User Avatar
    0
    hmahmood created

    In our application, we are creating the registration for tenants. When a user register in the application, we need to create a tenant and the admin user for that particular tenant. We are creating the tenant using ITenantAppService and user using IUserAppService. On creating tenant and user we are getting the volo.abp.authorixation exception.

    Please share your code.

    We are using the SignInManager in the following way, as per the answer.
    WhatsApp Image 2022-05-10 at 3.14.13 PM.jpeg

    Getting this error
    WhatsApp Image 2022-05-10 at 2.59.08 PM.jpeg

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    What's your original code? (full class code)

  • User Avatar
    0
    hmahmood created

    What's your original code? (full class code)

    using TaxDep.Shared;
    using System.Collections.Generic;
    using Microsoft.AspNetCore.Mvc.Rendering;
    using Volo.Abp.Application.Dtos;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using TaxDep.Account;
    using Volo.Saas.Host;
    using Volo.Saas.Host.Dtos;
    using System;
    using Volo.Abp.Security.Claims;
    using Microsoft.AspNetCore.Identity;
    
    namespace TaxDep.Web.Pages.Account
    {
        public class RegistrationConfModel : TaxDepPageModel
        {
            [BindProperty]
            public RegistrationDto AccountSub { get; set; }
    
            public List<SelectListItem> Edition { get; set; } = new List<SelectListItem>{ };
    
            private readonly IRegistrationAppService _registrationSubAppService;
    
            private readonly TenantAppService _tenantAppService; 
    
            public SaasTenantCreateDto TenantDto { get; set; }
    
            public IdentityUser _identityUser;
    
            private readonly ICurrentPrincipalAccessor _CurrentPrincipalAccessor;
    
            public RegistrationConfModel(IRegistrationAppService registrationSubAppService, TenantAppService tenantAppService,ICurrentPrincipalAccessor currentPrincipalAccessor)
            {
                _registrationSubAppService = registrationSubAppService;
                _tenantAppService = tenantAppService;
                _CurrentPrincipalAccessor = currentPrincipalAccessor;
            }
    
            public async Task OnGetAsync(string UserName, string EmailAddress, string EditionId)
            {
                AccountSub = new RegistrationDto();
                AccountSub.Name = UserName;
                AccountSub.Email = EmailAddress;
                AccountSub.Edition = EditionId;
    
                Edition.AddRange((
                    await _registrationSubAppService.GetEditionListAsync(new LookupRequestDto
                                        {
                                            MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount
                                        })).Items.Where(o=>o.Id == AccountSub.Edition).Select(t => new SelectListItem(t.DisplayName, t.Id)).ToList()
                            );
                await Task.CompletedTask;
            }
    
            public async Task<IActionResult> OnPostAsync()
            {
                try
                {
                    _identityUser = new IdentityUser();
                    _identityUser.Email = "admin@abp.io";
                    _identityUser.PasswordHash = "AQAAAAEAACcQAAAAEGDujMi6IXJ6FdQ1OCM+v480S0dkjiaomSpNVq8gs22iPWOP1dmP1uYa8kxQn+RG4w==";
                    _identityUser.UserName = "admin";
                    await SignInManager.SignInAsync(_identityUser, isPersistent: false);
                    using (_CurrentPrincipalAccessor.Change(await SignInManager.CreateUserPrincipalAsync(_identityUser)))
                    {
                        //need to add tenant.
                        await _tenantAppService.CreateAsync(TenantDto);
                    }
                }
                catch(Exception ex)
                {
    
                }
    			
                return NoContent();
            }
        }
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Please inject the SignInManager in your TaxDepPageModel

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 13, 2025, 04:08