I'm trying to add google authentication and have installed the nuget oacjage Microsoft.AspNetCore.Authentication.Google v. 7.0.14
But when I try to add it to services, the site stop with message
The program '[20972] LT.LoveMatch.Natural.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'.
Code:
GoogleConfigSection config = new GoogleConfigSection();
builder.Configuration.GetSection("Google").Bind(config);
builder.Services.AddAuthentication().AddGoogle(opt =>
{
opt.ClientId = config.ClientId;
opt.ClientSecret = config.ClientSecret;
});
Just created a new website project and did nothing but install nuget package Microsoft.AspNetCore.Authentication.Google 8.0.3 and added the service. It worked before I added the service, then it failed with code Access violation.
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddAuthentication().AddGoogle(opt => {
opt.ClientId = "clientId";
opt.ClientSecret = "secret";
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
Any ideas? Thanks!
Bit late but may be useful for others looking for an answer. What fixed similar issue for me was adding Authentication defaults. Not sure why it's not mentioned in Microsoft documentation or if I missed it. Anyways, editing code to the following should fix the error:
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = BearerTokenDefaults.AuthenticationScheme;
options.DefaultSignInScheme = BearerTokenDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
})
.AddBearerToken()
.AddGoogle(options =>
{
options.ClientId = googleClientId;
options.ClientSecret = googleClientSecret;
});
This should work if you choose cookie authentication as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With