Google 身份验证在本地主机上有效,但在域上无效

Google 身份验证在本地主机上有效,但在域上无效

Google 身份验证在本地主机上运行,​​但在域上运行不成功(请参阅附加的 gif)。

为什么身份验证对 localhost 有效,但对域 cpspmo.com 无效?我已添加https://www.cpspmo作为授权的 JavaScript 来源 URI。

还添加了以下授权重定向 URI:https://www.cpspmo.com/signin-google https://www.cpspmo.com/Account/GoogleResponse

这是我的Startup.cs:

使用 CPSPMOWEB.Data;使用 CPSPMOWEB.Models.EF;使用 Microsoft.AspNetCore.Builder;使用 Microsoft.AspNetCore.Hosting;使用 Microsoft.AspNetCore.HttpsPolicy;使用 Microsoft.AspNetCore.Identity;使用 Microsoft.AspNetCore.Identity.UI;使用 Microsoft.EntityFrameworkCore;使用 Microsoft.Extensions.Configuration;使用 Microsoft.Extensions.DependencyInjection;使用 Microsoft.Extensions.Hosting;使用 Microsoft.AspNetCore.Server.IISIntegration;使用 Microsoft.Net.Http.Headers;

命名空间 CPSPMOWEB { 公共类 Startup { 公共 Startup(IConfiguration 配置) { 配置 = 配置; }

    public IConfiguration Configuration { get; }
    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        //services.AddCors();
        services.AddControllers();
        services.AddAuthentication(IISDefaults.AuthenticationScheme);

        var connStr = Configuration.GetConnectionString("PMOUpdatesClouodConnection");
        services.AddDbContext<PMOUpdatesCloudContext>(options => options.UseSqlServer(connStr));

        services.AddRazorPages().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);

        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection")));
        services.AddDatabaseDeveloperPageExceptionFilter();

        services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores<ApplicationDbContext>();
        services.AddControllersWithViews();

        services.AddAuthentication()
         .AddGoogle(options =>
         {
             IConfigurationSection googleAuthNSection =
                 Configuration.GetSection("Authentication:Google");

             options.ClientId = googleAuthNSection["ClientId"];
             options.ClientSecret = googleAuthNSection["ClientSecret"];
         })

        .AddCookie(options =>
        {
            options.LoginPath = "/account/google-login";
        })
        ;
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseAuthentication();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseMigrationsEndPoint();
        }
        else
        {
            app.UseExceptionHandler("/Home/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.UseCors(x => x
        //   .AllowAnyMethod()
        //   .AllowAnyHeader()
        //   .SetIsOriginAllowed(origin => true) // allow any origin
        //   .AllowCredentials()); // allow credentials

        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapRazorPages();
        });
    }
}

}

本地主机身份验证

域身份验证

相关内容