Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External Provider Login .NET

I had follow this tutorial for setup External Login https://code-maze.com/external-identity-provider-aspnet-core-identity/, after when I want to test login with google account, I write my email, my password. I get to fuunction ExternalLoginConfirmation where ModelState is not valid, always because Principal is null and if I do not specify returnUrl also because of that. Here are pictures of Debug: ExternalLogin Method

ExternalLoginCallback

Now I'm not sure why returnUrl must be mandatory field, this can easy manage if null is to have to return to Home/Index. enter image description here

Then when I submit I got ModelStata.IsValid as false ExternalLoginConfirmation

From Program.cs I have this configuration:

builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
{
    containerBuilder.RegisterModule(new DefaultDomainModule());
    containerBuilder.RegisterModule(new DefaultInfrastructureModule(false));
});
builder.Services.AddAuthentication()
    .AddGoogle(options =>
    {
        IConfigurationSection googleAuthSection = builder.Configuration.GetSection("Authentication:Google");
        options.ClientId = googleAuthSection["ClientId"];
        options.ClientSecret = googleAuthSection["ClientSecret"];
        options.SaveTokens = true;

    });

And Code from InfrastructureLayer:

public static void AddIdentityDbContext(this IServiceCollection services, string connectionString) =>
    services.AddDbContext<IdentityAppDbContext>(options =>
        {
            options.UseSqlServer(connectionString);
        })
        .AddIdentity<IdentityUser, IdentityRole>(options =>
        {
            options.Password.RequireDigit = false;
            options.Password.RequireLowercase = false;
            options.Password.RequireNonAlphanumeric = false;
            options.Password.RequiredLength = 4;
            options.SignIn.RequireConfirmedEmail = true;
            options.Lockout.MaxFailedAccessAttempts = 5;
            options.User.RequireUniqueEmail = true;
        })
        .AddEntityFrameworkStores<IdentityAppDbContext>()
        .AddDefaultTokenProviders();
like image 291
Danijel Boksan Avatar asked Nov 16 '25 09:11

Danijel Boksan


1 Answers

ExternalLoginCallBack returnUrl parameter set to nullable to solves this issue:

from

public async Task ExternalLoginCallBack(string returnUrl = null)

to

public async Task ExternalLoginCallBack(string? returnUrl = null)

https://github.com/dotnet/aspnetcore/issues/22656#issuecomment-640650945

like image 176
MD. RAKIB HASAN Avatar answered Nov 18 '25 00:11

MD. RAKIB HASAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!