Activities of "papusa"

Looks like the archivator didn’t include the src folder. Could you check again now?

I've send a link to the BankID test app.

  • National identity number: 04080599469
  • One-time code: otp
  • BankID password: qwer1234

It's always null when context.EndpointType == OpenIddictServerEndpointType.Authorization.

I’ve been trying to do that, but both IdentityTokenPrincipal and AccessTokenPrincipal are null. Maybe this needs to be handled in a different event? I’m not very familiar with OpenIddict, what do you think?

You can use a custom claim to check it. eg nationalidentitynumber then try to get this claim from CurrentUser.

Here is my claims contributor:

public class BankIdClaimsPrincipalContributor : IAbpClaimsPrincipalContributor, ITransientDependency
{
    private readonly AbpSignInManager _signInManager;

    public BankIdClaimsPrincipalContributor(AbpSignInManager signInManager)
    {
        _signInManager = signInManager;
    }

    public async Task ContributeAsync(AbpClaimsPrincipalContributorContext context)
    {
        var identity = context.ClaimsPrincipal.Identities.FirstOrDefault();
        
        var externalLogin = await _signInManager.GetExternalLoginInfoAsync();
        if (externalLogin == null)
        {
            // Contributor is executed 4 times. Last 2 times externalLogin is null.
            // It results in 2 "isbankidauthenticated" claims, one has value of false and another is true.
            identity?.AddClaim(new Claim("isbankidauthenticated", false.ToString().ToLower()));
            return;
        }
        
        var isBankIdAuthenticated = externalLogin.LoginProvider == "Criipto";
        var claim = new Claim("isbankidauthenticated", isBankIdAuthenticated.ToString().ToLower());
        identity?.AddClaim(claim);
    }
}

I noticed that it gets executed 4 times. Is this the expected behavior? This causes an issue because I cannot reliably set my claim value to false.

You can check the BankID platform to see if it supports adding custom claims for a user.

I don’t quite understand how BankID is related here. As far as I know, the claims are set within the ABP application itself. Am I missing something? Previously, you suggested implementing IOpenIddictServerHandler<OpenIddictServerEvents.ProcessSignInContext>. This works, but it only adds the claim to the access_token. How can I also include the claim in the id_token?

public class BankIdOpenIddictServerHandler :  IOpenIddictServerHandler<OpenIddictServerEvents.ProcessSignInContext>
{
    public static OpenIddictServerHandlerDescriptor Descriptor { get; }
        = OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.ProcessSignInContext>()
            .UseSingletonHandler<BankIdOpenIddictServerHandler>()
            .SetOrder(100_000)
            .SetType(OpenIddictServerHandlerType.Custom)
            .Build();

    public async ValueTask HandleAsync(OpenIddictServerEvents.ProcessSignInContext context)
    {
        if (context.EndpointType != OpenIddictServerEndpointType.Authorization ||
            context.AuthorizationCodePrincipal == null)
        {
            return;
        }

        var httpContext = context.Transaction.GetHttpRequest()?.HttpContext;
        if (httpContext == null)
        {
            return;
        }

        var identity = await httpContext.AuthenticateAsync(IdentityConstants.ApplicationScheme);
        if (identity.Principal == null)
        {
            return;
        }

        var bankIdClaim = identity.Principal.FindFirst("isbankidauthenticated");
        if (bankIdClaim != null)
        {
            context.AuthorizationCodePrincipal.AddClaim("isbankidauthenticated", bankIdClaim.Value);
        }
    }
}

To determine if a user logged in with a local account or via an external login (such as BankID), you can inspect the user's login providers. ABP's Identity system stores external login information in the user logins table.

As I understand it, this only shows which providers are associated with the user (from the user logins table), not which provider was actually used for the current login session. Is there a way to detect the login type of the current session?

To include a custom claim in both the access_token and id_token, you can use claims contributors in ABP. Implement IAbpClaimsPrincipalContributor and register it. In your contributor, add a custom claim (e.g., "login_type") based on the authentication context. This claim will be included in the generated tokens if added during the authentication process.

I have already implemented a claims contributor. But is this the recommended approach? I noticed it is executed four (4) times when a user logs in from Angular. Also, it does not add the claim to the id_token or access_token received on the client. This was partially solved by the suggested IOpenIddictServerHandler<OpenIddictServerEvents.ProcessSignInContext> implementation from my previous ticket, but that only adds the claim to the access_token, which is not very convenient on the client side.

The AI answer didn’t really address my third question either. Could you please clarify the recommended way to handle the scenario where a user adds a new external login?

Hi, I previously opened a ticket regarding external login with BankID, and I now have three additional questions:

Recognizing login type

  • Is it possible to determine whether the user logged in with a local account or via an external login (e.g., BankID)? I'd like to make certain decisions based on the login method used.

Adding login type claim

  • Is it possible to include a custom claim in both the access_token and the id_token?

Handling BankID-only actions There are some actions in my application that must only be allowed when a user is authenticated via BankID (external login).

  • If the user does not yet have an external login, they should be prompted to add it.
  • When a user adds an external login, it goes through the BankID login flow. However, when the request returns to the ABP application, the claims contributors are missing, so I cannot add any claim that marks the user as BankID-authenticated.
  • This results in the user having to authenticate with BankID twice, which is not ideal.

Is there a recommended way to handle this scenario to avoid requiring double BankID authentication?

It works. Thank you!

I've shared a link to the BankID demo project via OneDrive. You should receive e-mail with link.

While testing the demo, I noticed that the issue only occurs when an external login is added to an existing user. If the user is registered directly via BankID, the problem doesn't appear.

Here are the steps to reproduce the issue:

  1. Log in using any local user (e.g., admin).
  2. Navigate to External Logins.
  3. Add an external BankID account using the following test credentials:
    • National identity number: 04080599469
    • One-time code: otp
    • BankID password: qwer1234
  4. After linking the external login, log out.
  5. Log in using BankID.
  6. In the Angular app's Home page, click the "Test national identity claim" button.
  7. Expected: It should display the national identity number. Actual: It shows a message indicating the claim is not found.

Below is result for same user in angular and swagger:

I will test your case with GitHub login.

Sounds good. Thanks

Showing 1 to 10 of 33 entries
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 18, 2025, 07:10