Save Access token with extra Claim “assertion_details” when using Duende AccessTokenManagement

I have a .net 8 webApi used for logging in to a secure site using OpenIdConnect.
We are using Duende nuget packages to handle DPoP. This works great, but we have a workflow where we enrich the acccess token with an extra claim (RAR.

We need to use the userId from the initial login and use this value as a parameter in our backend to build the “RAR” object used to populate the extra Claim. We update our login by calling RequestRefresTokenAsync() from a httpClient.

var refreshTokenResult = await httpClient.RequestRefreshTokenAsync(new RefreshTokenRequest
{
    ClientCredentialStyle = ClientCredentialStyle.PostBody,
    ClientAssertion = clientAssertion, //This ClientAssertion contains the Extra Claim
    Address = _appSettings.HelseId.TokenEndpoint,
    ClientId = _appSettings.HelseId.ClientId,
    RefreshToken = token.RefreshToken,
    Method = HttpMethod.Post,
    GrantType = OidcConstants.GrantTypes.RefreshToken,
    DPoPProofToken = ClientAssertionBuilder.CreateDPoPProof(_appSettings.HelseId.RsaKey, _appSettings.HelseId.TokenEndpoint, "POST", dPoPNonce: dPoPNonce, token.AccessToken)

});

My refreshTokenResult contains AccessToken with the extra claim and I can use this AccessToken to perform what needs to be done.

Unfortunately I am unable to use Duendes library that handles DPoP and automatically manages AccessTokens, handles Token expiry and refreshes etc by injecting a named HttpClient with “.AddUsesrAccessTokenHandler”
I would like to use this:

builder.Services.AddHttpClient("MyApi")
    .AddUserAccessTokenHandler();

But, unfortunately, if I use the “MyApi” httpClient my AccessToken which is refreshed and enriched with the extra Claim will get replaced by the initial AccessToken missing the extra Claim.

How can I either update the accesstokenManagement from Duende with my new token, but preferably extendt the service to add my extra Claim? The problem is, I do not have the extra Claim untill the user is authenticated and I have read a parameter to the controller/endpoint the client request.

I have tried to implement my own IClientAssertionService

// Use client assertion for automatic refresh of tokens
builder.Services.AddScoped<IClientAssertionService, ClientAssertionService>();

public Task<ClientAssertion?> GetClientAssertionAsync(string? clientName = null, TokenRequestParameters? parameters = null)
{
    var rarValue = FindCookie(_httpContextAccessor.HttpContext.Response.Headers, "rar");
            
    string assertionValue = string.Empty;
    if (!string.IsNullOrWhiteSpace(rarValue ))
    {
        _logger.LogDebug("GetClientAssertionAsync Create ClientAssertion with RAR");
        var hcpInfo = JsonSerializer.Deserialize<HcpInformation>(rarValue );
         assertionValue = ClientAssertionBuilder.GetClientAssertion(options.ClientId, options.RsaKey, options.Authority,hcpInfo);
    }
    else
    {
        _logger.LogDebug("GetClientAssertionAsync Create ClientAssertion without RAR. No Cookie found");
        
         assertionValue = ClientAssertionBuilder.GetClientAssertion(options.ClientId, options.RsaKey, options.Authority,null);
    }         
    return Task.FromResult<ClientAssertion?>(new ClientAssertion
    {
        Type = OidcConstants.ClientAssertionTypes.JwtBearer,
        Value = assertionValue
    });
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật