Code cleanup

This commit is contained in:
Steve Smith
2020-07-28 15:35:48 -04:00
parent f4bfc81fe8
commit 2c9c7dd3d1
4 changed files with 7 additions and 28 deletions

View File

@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using AutoMapper; using AutoMapper;
using MediatR; using MediatR;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
@@ -46,11 +43,9 @@ namespace Microsoft.eShopWeb.PublicApi
private void ConfigureInMemoryDatabases(IServiceCollection services) private void ConfigureInMemoryDatabases(IServiceCollection services)
{ {
// use in-memory database
services.AddDbContext<CatalogContext>(c => services.AddDbContext<CatalogContext>(c =>
c.UseInMemoryDatabase("Catalog")); c.UseInMemoryDatabase("Catalog"));
// Add Identity DbContext
services.AddDbContext<AppIdentityDbContext>(options => services.AddDbContext<AppIdentityDbContext>(options =>
options.UseInMemoryDatabase("Identity")); options.UseInMemoryDatabase("Identity"));
@@ -91,27 +86,18 @@ namespace Microsoft.eShopWeb.PublicApi
services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>)); services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
services.AddScoped<ITokenClaimsService, IdentityTokenClaimService>(); services.AddScoped<ITokenClaimsService, IdentityTokenClaimService>();
// Add memory cache services
services.AddMemoryCache(); 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); var key = Encoding.ASCII.GetBytes(AuthorizationConstants.JWT_SECRET_KEY);
services.AddAuthentication(config => 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; config.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
}) })
.AddJwtBearer(x => .AddJwtBearer(config =>
{ {
x.RequireHttpsMetadata = false; config.RequireHttpsMetadata = false;
x.SaveToken = true; config.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters config.TokenValidationParameters = new TokenValidationParameters
{ {
ValidateIssuerSigningKey = true, ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key), IssuerSigningKey = new SymmetricSecurityKey(key),

View File

@@ -1,8 +1,4 @@
using System; namespace Shared.Authorization
using System.Collections.Generic;
using System.Text;
namespace Shared.Authorization
{ {
public class ClaimValue public class ClaimValue
{ {

View File

@@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Security.Claims;
using System.Text;
namespace Shared.Authorization namespace Shared.Authorization
{ {

View File

@@ -20,7 +20,7 @@ namespace Microsoft.eShopWeb.Web.Controllers
_mediator = mediator; _mediator = mediator;
} }
[HttpGet()] [HttpGet]
public async Task<IActionResult> MyOrders() public async Task<IActionResult> MyOrders()
{ {
var viewModel = await _mediator.Send(new GetMyOrders(User.Identity.Name)); var viewModel = await _mediator.Send(new GetMyOrders(User.Identity.Name));