Create IdentityService in marketing API

This commit is contained in:
Christian Arenas 2017-06-26 18:31:04 +02:00
parent b28c650e06
commit 699ec0001d
3 changed files with 41 additions and 1 deletions

View File

@ -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();
}
}

View File

@ -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;
}
}
}

View File

@ -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<IMarketingDataRepository, MarketingDataRepository>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<IIdentityService, IdentityService>();
//configure autofac
var container = new ContainerBuilder();