简体   繁体   English

如何在 .Net Core 6 中传递客户端 ID 以进行谷歌身份验证

[英]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.

相关问题 使用 asp.net core mvc 中的身份验证保护 wwwroot 中的某些文件夹 - Protect certain folders in wwwroot with authetication in asp.net core mvc 使用 .NET Core 进行 Google API 客户端库身份验证 - Google API Client library authentication with .NET Core 如何使用 Angular 将 Windows 身份验证从客户端转发/传递到 ASP.NET Core 应用程序中的另一个 REST API? - How to forward/pass windows authentication from client to another REST API in an ASP.NET Core app with Angular? 如何在 .net core web 应用程序和 web api 之间传递/验证 Open ID 令牌? - How to pass/verify Open ID token between .net core web app and web api? 如何在不通过 controller asp.net 核心的情况下获取任何 Class 中的当前用户 ID 和用户声明 - How to get current user Id and user claim in any Class without pass by controller asp.net core 如何获取用户的当前 ID 以传递给 _Layout ASP.NET 核心? - How to get the current Id of a user to pass to _Layout ASP.NET Core? Microsoft Graph API 安全性 .net Core 客户端 ID - Microsoft Graph API Security .net Core Client ID 客户端不刷新新对象的ID | ASP.NET 核心 5 - Client does not refresh ID of new object | ASP.NET core 5 在 2 个控制器 ASP.NET Core 3.1 MVC 之间传递 ID - Pass ID between 2 controllers ASP.NET Core 3.1 MVC 如何在.Net Core中使用客户端SSL证书 - How to use Client SSL Certificates with .Net Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM