[英]How to pass the Client Id for google authetication in .Net Core 6
I am trying to use a google authentication in .Net Core 6. I have already generated the credentials in google developer console and added in the code.我正在尝试在 .Net Core 6 中使用谷歌身份验证。我已经在谷歌开发者控制台中生成了凭据并添加到代码中。
using LoginKud.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<AppDbContext>();
builder.Services.AddAuthentication().AddGoogle(options => {
options.ClientId = builder.Configuration["591241482908-66qgk38nbf1un6mxxxxxxxxxx.apps.googleusercontent.com"];
options.ClientSecret = builder.Configuration["GOCSPX-jHKaxxxxxxx"];
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/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.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
I have provided both client Id and Client Secret Id but I get The 'ClientId' option must be provided. (Parameter 'ClientId')
我已经提供了客户端 ID 和客户端密码 ID,但我得到
The 'ClientId' option must be provided. (Parameter 'ClientId')
The 'ClientId' option must be provided. (Parameter 'ClientId')
error every time I run the program. The 'ClientId' option must be provided. (Parameter 'ClientId')
每次运行程序时都会出错。 How can I solve this?我该如何解决这个问题?
I thing the problem is inside this 2 lines:我认为问题出在这两条线内:
options.ClientId = builder.Configuration["591241482908-66qgk38nbf1un6mxxxxxxxxxx.apps.googleusercontent.com"];
options.ClientSecret = builder.Configuration["GOCSPX-jHKaxxxxxxx"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.