I’ve been struggling configuring and to combine an authentication using Google, and it to generate JWT token within my app and ship them to the client. Then the client would authorize themselves using these tokens.
I have implemented already the Google authentication correctly, I cannot seem to figure out how to get the User details from Google and generate these JWT’s.
I tried following this response from a kind user on an older thread, but I get that:
The authentication handler registered for scheme 'Bearer' is 'JwtBearerHandler' which cannot be used for SignInAsync
Since it’s source from an under-the-hood process I cannot debug this and I can’t seem to understand how to configure that correctly.
Any help or advice would be appreciated!
Edit:
These are my service registrations:
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(opt =>
{
opt.SaveToken = true;
opt.RequireHttpsMetadata = true;
opt.TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = false,
ValidateAudience = false,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidAudience = configuration["JWT:Audience"],
ValidIssuer = configuration["JWT:Issuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JWT:Secret"]))
};
})
.AddGoogle(googleOptions =>
{
googleOptions.ClientId = configuration["Google:ClientId"]!;
googleOptions.ClientSecret = configuration["Google:ClientSecret"]!;
});