我正在处理的项目实际上是一个asp.net react项目模板,包括立即出现的身份框架。
下面是它们rx的代码更改:
using CompraDeMi.ConsumerWeb.Areas.Identity;
using CompraDeMi.ConsumerWeb.Data;
using CompraDeMi.ConsumerWeb.Models;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.EntityFrameworkCore;
using System.Configuration;
namespace CompraDeMi.ConsumerWeb
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddScoped<IUserClaimsPrincipalFactory<ApplicationUser>, ApplicationUserClaimsPrincipalFactory>();
builder.Services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
builder.Services.AddAuthentication()
.AddIdentityServerJwt()
.AddGoogle(googleOptions => {
googleOptions.ClientId = builder.Configuration["Authentication:Google:ClientId"];
googleOptions.ClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
});
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
using (var svcScope = app.Services.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
var appContext = svcScope.ServiceProvider.GetService<ApplicationDbContext>();
if (appContext is not null)
appContext.Database.Migrate();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseIdentityServer();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.MapRazorPages();
app.MapFallbackToFile("index.html");
app.Run();
}
}
}我还在此基础上实现了谷歌身份验证:https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-6.0

我在Google注册了这个应用程序,除了我注册或使用Google身份验证时,一切看起来都很好。
除了控制台警告之外,我没有收到多少反馈:
router.ts:11 No routes matched location "/signin-google?state=CfDJ8FUFmpOzEnlEgxO5Hun5JDlqGr8BLuC31PgS_uHAK0U2KcsmY4YvZwK740bnV9SHpMaqx-wNdCJnq3_DlacPC-oNhKN6hAQezjJFdAjyBHUL-MwMMe27_b-4gZM7Jf6IYTAYxbDj2ij_OaNLEsSyAxB1jT40TQicPwX1dmEu6FT40xZn54EhmNKRe1jpOZ_jixO0-jNUC8j-jE6gtwJCKGzkYP_RnhEJMEx79_GCqVK5Atu0cIho2ew_BPfNL-Y4G3q_rQgSyIvpbVszW8YtcWyfX-4RK93blAogHW2iX7kRhje98SVwhHuAEt8gTNlF1Tvr0xFKUrW0RQd0j3z3tOQ&code=4%2F0ARtbsJoMtOs4W_GAG36XEMq9r999I_awQ3Tn7S8yf-aJbuZYjBaAat56sPCagDDACOgrfg&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=0&prompt=consent"
warning @ router.ts:11
useRoutes @ hooks.tsx:348
Routes @ components.tsx:256
renderWithHooks @ react-dom.development.js:16305
mountIndeterminateComponent @ react-dom.development.js:20074
beginWork @ react-dom.development.js:21587
beginWork$1 @ react-dom.development.js:27426
performUnitOfWork @ react-dom.development.js:26557
workLoopSync @ react-dom.development.js:26466
renderRootSync @ react-dom.development.js:26434
performConcurrentWorkOnRoot @ react-dom.development.js:25738
workLoop @ scheduler.development.js:266
flushWork @ scheduler.development.js:239
performWorkUntilDeadline @ scheduler.development.js:533我知道身份框架正在使用Razor页面。基于警告,它看起来像是react路由器正在尝试处理回调。
我想MS在提供React模板时会考虑到这一点。
我错过了什么吗?或者其他人能给我指点的文件?
我们非常感谢你的帮助。
发布于 2022-10-06 18:21:40
在搜索了几天的答案之后,没有找到答案,我记得在添加新的api端点时,我需要在这里设置代理:Out of box VS 2022 SPA React App won't route Web API。
我修改了setupProxy.js文件:

我添加了以下代码:

谷歌认证立刻就成功了!
https://stackoverflow.com/questions/73952211
复制相似问题