Attività di "danieljudge10@gmail.com"

Hi,

For now you can try:

public static class RefreshEditionIdMiddlewareExtension 
{ 
    public static IApplicationBuilder UseRefreshEditionIdMiddleware(this IApplicationBuilder app) 
    { 
        return app.Use(async (ctx, next) => 
        { 
            var currentTenant = ctx.RequestServices.GetRequiredService<ICurrentTenant>(); 
            var currentUser = ctx.RequestServices.GetRequiredService<ICurrentUser>(); 
 
            if (!currentUser.IsAuthenticated || !currentUser.TenantId.HasValue) 
            { 
                await next(); 
                return; 
            } 
 
            var tenantStore = ctx.RequestServices.GetRequiredService<ITenantRepository>(); 
            var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService<ICurrentPrincipalAccessor>(); 
            var tenant = await tenantStore.FindAsync(currentTenant.GetId()); 
            var claims = currentPrincipalAccessor.Principal.Claims.ToList(); 
 
            claims.ReplaceOne(x => x.Type == AbpClaimTypes.EditionId, 
                new Claim(AbpClaimTypes.EditionId, tenant.EditionId?.ToString() ?? string.Empty)); 
 
            using (currentPrincipalAccessor.Change(claims)) 
            { 
                await next(); 
            } 
        }); 
    } 
} 
 
.... 
app.UseAuthorization(); 
 
app.UseRefreshEditionIdMiddleware(); // add behind to `UseAuthorization` 
 

Perfect, worked a treat. Thankyou

So it gets the edition from the jwt and then uses it to get the features? And then the new changes would only use the tenant?

Are there any workarounds? How is this typically handled? I'm happy to reauthenticate the user in the backend but, but I can't really log them out and make them log in again just for changing plans.

Any help is appreciated

Thanks for that.

Looks like that is the issue, I created a copy with the JToken and got the same error, then removed it and it worked. Any further information on why this causes it or hope for a more permanent solution? It's used in a lot of the models for Chargebee and I would rather avoid the headaches of maintaining a copy of them all, especially when it comes to billing.

Item is from Chargebee, below is what I get from the package, the souce can be found at https://github.com/chargebee/chargebee-dotnet/blob/master/ChargeBee/Models/Item.cs

#region Assembly ChargeBee, Version=2.9.1.0, Culture=neutral, PublicKeyToken=2efc9456dd1bdb9d
// C:\Users\xxxxxx\.nuget\packages\chargebee\2.10.0\lib\netstandard2.0\ChargeBee.dll
#endregion

using ChargeBee.Api;
using ChargeBee.Filters.Enums;
using ChargeBee.Internal;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;

namespace ChargeBee.Models
{
    public class Item : Resource
    {
        public Item();
        public Item(Stream stream);
        public Item(TextReader reader);
        public Item(string jsonString);

        public bool EnabledForCheckout { get; }
        public bool EnabledInPortal { get; }
        public bool? IncludedInMrr { get; }
        public ItemApplicabilityEnum ItemApplicability { get; }
        public string GiftClaimRedirectUrl { get; }
        public bool Metered { get; }
        public bool IsGiftable { get; }
        public UsageCalculationEnum? UsageCalculation { get; }
        public DateTime? ArchivedAt { get; }
        public List<ItemApplicableItem> ApplicableItems { get; }
        public JToken Metadata { get; }
        public string Unit { get; }
        public bool? IsShippable { get; }
        public string RedirectUrl { get; }
        public string ItemFamilyId { get; }
        public DateTime? UpdatedAt { get; }
        public long? ResourceVersion { get; }
        public StatusEnum? Status { get; }
        public string Description { get; }
        public string Name { get; }
        public string Id { get; }
        public TypeEnum ItemType { get; }

        public static CreateRequest Create();
        public static EntityRequest<Type> Delete(string id);
        public static ItemListRequest List();
        public static EntityRequest<Type> Retrieve(string id);
        public static UpdateRequest Update(string id);

        public enum StatusEnum
        {
            UnKnown = 0,
            Active = 1,
            Archived = 2,
            Deleted = 3
        }
        public enum TypeEnum
        {
            UnKnown = 0,
            Plan = 1,
            Addon = 2,
            Charge = 3
        }
        public enum ItemApplicabilityEnum
        {
            UnKnown = 0,
            All = 1,
            Restricted = 2
        }
        public enum UsageCalculationEnum
        {
            UnKnown = 0,
            SumOfUsages = 1,
            LastUsage = 2,
            MaxUsage = 3
        }

        public class CreateRequest : EntityRequest<CreateRequest>
        {
            public CreateRequest(string url, HttpMethod method);

            public CreateRequest ApplicableItems(List<string> applicableItems);
            public CreateRequest Description(string description);
            public CreateRequest EnabledForCheckout(bool enabledForCheckout);
            public CreateRequest EnabledInPortal(bool enabledInPortal);
            public CreateRequest GiftClaimRedirectUrl(string giftClaimRedirectUrl);
            public CreateRequest Id(string id);
            public CreateRequest IncludedInMrr(bool includedInMrr);
            public CreateRequest IsGiftable(bool isGiftable);
            public CreateRequest IsShippable(bool isShippable);
            public CreateRequest ItemApplicability(ItemApplicabilityEnum itemApplicability);
            public CreateRequest ItemFamilyId(string itemFamilyId);
            public CreateRequest Metadata(JToken metadata);
            public CreateRequest Metered(bool metered);
            public CreateRequest Name(string name);
            public CreateRequest RedirectUrl(string redirectUrl);
            public CreateRequest Type(TypeEnum type);
            public CreateRequest Unit(string unit);
            public CreateRequest UsageCalculation(UsageCalculationEnum usageCalculation);
        }
        public class UpdateRequest : EntityRequest<UpdateRequest>
        {
            public UpdateRequest(string url, HttpMethod method);

            public UpdateRequest ApplicableItems(List<string> applicableItems);
            [Obsolete]
            public UpdateRequest ClearApplicableItems(bool clearApplicableItems);
            public UpdateRequest Description(string description);
            public UpdateRequest EnabledForCheckout(bool enabledForCheckout);
            public UpdateRequest EnabledInPortal(bool enabledInPortal);
            public UpdateRequest GiftClaimRedirectUrl(string giftClaimRedirectUrl);
            public UpdateRequest IncludedInMrr(bool includedInMrr);
            public UpdateRequest IsShippable(bool isShippable);
            public UpdateRequest ItemApplicability(ItemApplicabilityEnum itemApplicability);
            public UpdateRequest ItemFamilyId(string itemFamilyId);
            public UpdateRequest Metadata(JToken metadata);
            public UpdateRequest Name(string name);
            public UpdateRequest RedirectUrl(string redirectUrl);
            public UpdateRequest Status(StatusEnum status);
            public UpdateRequest Unit(string unit);
        }
        public class ItemListRequest : ListRequestBase<ItemListRequest>
        {
            public ItemListRequest(string url);

            public BooleanFilter<ItemListRequest> EnabledForCheckout();
            public BooleanFilter<ItemListRequest> EnabledInPortal();
            public StringFilter<ItemListRequest> Id();
            public BooleanFilter<ItemListRequest> IsGiftable();
            public EnumFilter<ItemApplicabilityEnum, ItemListRequest> ItemApplicability();
            public StringFilter<ItemListRequest> ItemFamilyId();
            public BooleanFilter<ItemListRequest> Metered();
            public StringFilter<ItemListRequest> Name();
            public ItemListRequest SortById(SortOrderEnum order);
            public ItemListRequest SortByName(SortOrderEnum order);
            public ItemListRequest SortByUpdatedAt(SortOrderEnum order);
            public EnumFilter<StatusEnum, ItemListRequest> Status();
            public EnumFilter<TypeEnum, ItemListRequest> Type();
            public TimestampFilter<ItemListRequest> UpdatedAt();
            public EnumFilter<UsageCalculationEnum, ItemListRequest> UsageCalculation();
        }
        public class ItemApplicableItem : Resource
        {
            public ItemApplicableItem();

            public string Id();
        }
    }
}
1 - 4 di 4
Made with ❤️ on ABP v8.2.0-preview Updated on marzo 25, 2024, 15:11