Starts in:
0 DAY
5 HRS
49 MIN
9 SEC
Starts in:
0 D
5 H
49 M
9 S
Open Closed

How to override CreateExternalUserAsync with Blazor? #2619


User avatar
0
nalle.jacobsson@helaforsakring.se created
  • ABP Framework version: v5.1.3
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

I'd like to override CreateExternalUserAsync to add some custom logic when new users are created from Azure AD. How can I accomplish this with Blazor as UI?


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

    hi

    https://community.abp.io/posts/how-to-customize-the-login-page-for-mvc-razor-page-applications-9a40f3cd

  • User Avatar
    0

    Thanks. I hade made two mistakes:

    • I put my custom LoginModel in the wrong project, this pointed me in the right direction:

    https://community.abp.io/posts/how-to-customize-the-login-page-of-an-abp-blazor-application-by4o9yms

    • I didn't decorate my custom LoginModel with the correct attributes, I found instructions here:

    https://docs.abp.io/en/abp/latest/UI/AspNetCore/Customization-User-Interface#overriding-a-page-model-c

    Now it's working 👍

    My next question is how can I (in CreateExternalUserAsync()) access the claims I received via OpenIdConnect? My config looks like this:

    private void ConfigureExternalProviders(ServiceConfigurationContext context, IConfiguration configuration)
    {
        context.Services.AddAuthentication()
            .AddOpenIdConnect("AzureOpenId", "Azure AD OpenId", options =>
            {
                options.Authority = "https://login.microsoftonline.com/" + configuration["AzureAd:TenantId"] + "/v2.0/";
                options.ClientId = configuration["AzureAd:ClientId"];
                options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
                options.CallbackPath = configuration["AzureAd:CallbackPath"];
                options.ClientSecret = configuration["AzureAd:ClientSecret"];
                options.RequireHttpsMetadata = false;
                options.SaveTokens = true;
                options.GetClaimsFromUserInfoEndpoint = true;
                options.Scope.Add("email");
                options.Scope.Add("profile");
    
                options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "sub");
            })
    
  • User Avatar
    0

    I found them in ExternalLoginInfo.Principal.Claims

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06