У меня проблемы с настройкой аутентификации в моем проекте Asp. net Core API. Я хочу использовать конфигурацию JWT, а также экран входа в Google - PullRequest
1 голос
/ 02 мая 2020

Если я настраиваю без JWT, он отображает страницу входа в Google, но когда я настраиваю добавление конфигурации JWT, он не отображает страницу входа в Google. Ниже приведен код

Ниже кода не отображается страница входа в Google.

protected override void RegisterAppInitialServicesToCollection(IServiceCollection services, IConfiguration configuration)
    {
        var jwtConfig = GetJwtBearerConfig(configuration);
        services.AddDbContext<TContext>();
        services.AddScoped<SysEntitiesBasic>(sp => sp.GetRequiredService<TContext>());
        services.AddIdentity<AppUser, Role>()
        .AddEntityFrameworkStores<TContext>()
        .AddDefaultTokenProviders();
        var googleSettings = configuration.GetSection("GoogleSettings");
        services.AddControllersWithViews().AddNewtonsoftJson(); ;
        services.AddRazorPages();
        services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
        })
        .AddJwtBearer(options =>
        {
            options.TokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer = jwtConfig.ValidateIssuer,
                ValidateAudience = jwtConfig.ValidateAudience,
                ValidateLifetime = jwtConfig.ValidateLifetime,
                ValidateIssuerSigningKey = jwtConfig.ValidateIssuerSigningKey,
                ValidIssuer = jwtConfig.Issuer,
                ValidAudience = jwtConfig.Audience,
                IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtConfig.SecurityKey))

            };
        })
        .AddGoogle(options =>
        {
            options.ClientId = googleSettings.GetValue<string>("ClientId");
            options.ClientSecret = googleSettings.GetValue<string>("ClientSecret");
        });

        services.AddMvc();
    }

Ниже приведена страница входа в Google.

 protected override void RegisterAppInitialServicesToCollection(IServiceCollection services, IConfiguration configuration)
    {
        services.AddDbContext<TContext>();
        services.AddScoped<SysEntitiesBasic>(sp => sp.GetRequiredService<TContext>());
        services.AddIdentity<AppUser, Role>()
        .AddEntityFrameworkStores<TContext>()
        .AddDefaultTokenProviders();
        var googleSettings = configuration.GetSection("GoogleSettings");
        services.AddControllersWithViews().AddNewtonsoftJson(); ;
        services.AddRazorPages();
        services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = GoogleDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
        })
        .AddGoogle(options =>
        {
            options.ClientId = googleSettings.GetValue<string>("ClientId");
            options.ClientSecret = googleSettings.GetValue<string>("ClientSecret");
        });

        services.AddMvc();
    }

I Мне нужна первая опция, так как я хочу использовать JWT для аутентификации и страницу Google для входа в систему. Когда не удается отобразить страницу входа, появляется страница ниже enter image description here

...