|
|
|
@ -1,10 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Text; |
|
|
|
using AutoMapper; |
|
|
|
using MediatR; |
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies; |
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
@ -46,11 +43,9 @@ namespace Microsoft.eShopWeb.PublicApi |
|
|
|
|
|
|
|
private void ConfigureInMemoryDatabases(IServiceCollection services) |
|
|
|
{ |
|
|
|
// use in-memory database
|
|
|
|
services.AddDbContext<CatalogContext>(c => |
|
|
|
c.UseInMemoryDatabase("Catalog")); |
|
|
|
|
|
|
|
// Add Identity DbContext
|
|
|
|
services.AddDbContext<AppIdentityDbContext>(options => |
|
|
|
options.UseInMemoryDatabase("Identity")); |
|
|
|
|
|
|
|
@ -91,27 +86,18 @@ namespace Microsoft.eShopWeb.PublicApi |
|
|
|
services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>)); |
|
|
|
services.AddScoped<ITokenClaimsService, IdentityTokenClaimService>(); |
|
|
|
|
|
|
|
// Add memory cache services
|
|
|
|
services.AddMemoryCache(); |
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/46938248/asp-net-core-2-0-combining-cookies-and-bearer-authorization-for-the-same-endpoin
|
|
|
|
var key = Encoding.ASCII.GetBytes(AuthorizationConstants.JWT_SECRET_KEY); |
|
|
|
services.AddAuthentication(config => |
|
|
|
{ |
|
|
|
//config.DefaultScheme = "smart";
|
|
|
|
//config.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
//config.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
|
|
|
config.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
|
config.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
|
config.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
|
config.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
|
}) |
|
|
|
.AddJwtBearer(x => |
|
|
|
.AddJwtBearer(config => |
|
|
|
{ |
|
|
|
x.RequireHttpsMetadata = false; |
|
|
|
x.SaveToken = true; |
|
|
|
x.TokenValidationParameters = new TokenValidationParameters |
|
|
|
config.RequireHttpsMetadata = false; |
|
|
|
config.SaveToken = true; |
|
|
|
config.TokenValidationParameters = new TokenValidationParameters |
|
|
|
{ |
|
|
|
ValidateIssuerSigningKey = true, |
|
|
|
IssuerSigningKey = new SymmetricSecurityKey(key), |
|
|
|
|