From 699ec0001dc47221b095c70e5ce66703ad465a02 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Mon, 26 Jun 2017 18:31:04 +0200 Subject: [PATCH] Create IdentityService in marketing API --- .../Services/IIdentityService.cs | 12 ++++++++++ .../Services/IdentityService.cs | 23 +++++++++++++++++++ .../Marketing/Marketing.API/Startup.cs | 7 +++++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/Services/Marketing/Marketing.API/Infrastructure/Services/IIdentityService.cs create mode 100644 src/Services/Marketing/Marketing.API/Infrastructure/Services/IdentityService.cs diff --git a/src/Services/Marketing/Marketing.API/Infrastructure/Services/IIdentityService.cs b/src/Services/Marketing/Marketing.API/Infrastructure/Services/IIdentityService.cs new file mode 100644 index 000000000..d49abe111 --- /dev/null +++ b/src/Services/Marketing/Marketing.API/Infrastructure/Services/IIdentityService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services +{ + public interface IIdentityService + { + string GetUserIdentity(); + } +} diff --git a/src/Services/Marketing/Marketing.API/Infrastructure/Services/IdentityService.cs b/src/Services/Marketing/Marketing.API/Infrastructure/Services/IdentityService.cs new file mode 100644 index 000000000..bcb7a84f8 --- /dev/null +++ b/src/Services/Marketing/Marketing.API/Infrastructure/Services/IdentityService.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Http; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services +{ + public class IdentityService : IIdentityService + { + private IHttpContextAccessor _context; + + public IdentityService(IHttpContextAccessor context) + { + _context = context ?? throw new ArgumentNullException(nameof(context)); + } + + public string GetUserIdentity() + { + return _context.HttpContext.User.FindFirst("sub").Value; + } + } +} diff --git a/src/Services/Marketing/Marketing.API/Startup.cs b/src/Services/Marketing/Marketing.API/Startup.cs index a31055d39..f5f726c62 100644 --- a/src/Services/Marketing/Marketing.API/Startup.cs +++ b/src/Services/Marketing/Marketing.API/Startup.cs @@ -1,4 +1,7 @@ -namespace Microsoft.eShopOnContainers.Services.Marketing.API +using Microsoft.AspNetCore.Http; +using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services; + +namespace Microsoft.eShopOnContainers.Services.Marketing.API { using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -110,6 +113,8 @@ }); services.AddTransient(); + services.AddSingleton(); + services.AddTransient(); //configure autofac var container = new ContainerBuilder();