我正在使用的项目实际上是一个 asp.net 反应项目模板,包括开箱即用的 Identity Framework。
这是他们 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 cl 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<IUserClaimsPrinlFactory<ApplicationUser>, ApplicationUserClaimsPrinlFactory>();
builder.Services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
builder.Services.AddAuthentication()
.AddIdentityServerJwt()
.AddGoogle(googleOptions => {
googleOptions.Id = builder.Configuration["Authentication:Google:Id"];
googleOptions.Secret = builder.Configuration["Authentication:Google:Secret"];
});
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();
}
}
}
我还基于此实现了 Google 身份验证:https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-6.0
我注册的应用程序与谷歌和一切似乎工作正常,除了当我注册或登录使用谷歌身份验证。
除了控制台警告之外,我没有得到太多反馈:
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.googlea.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googlea.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
我知道 Identity Framework 正在使用 Razor 页面。根据警告,它看起来像反应路由器正在尝试处理回调。
我想 MS 会在提供 React 项目模板时考虑到这一点。
有什么我错过了吗?或者一些文档任何人都可以指向我?
非常感谢你的帮助。
经过几天的搜索答案,没有找到一个我记得,我需要设置我的代理时,添加新的 API 端点描述这里:Out of box VS 2022 SPA React App won't route Web API
我修改了 setupProxy.js 文件:
I added the following line of code:
Google 身份验证开箱即用!
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(16条)