private static async Task <string> FormatRequest(HttpRequest request, IClaims claims)
        {
            var body = request.Body;

            //This line allows us to set the reader for the request back at the beginning of its stream.
            request.EnableBuffering();

            //We now need to read the request stream.  First, we create a new byte[] with the same length as the request stream...
            var buffer = new byte[Convert.ToInt32(request.ContentLength)];

            //...Then we copy the entire request stream into the new buffer.
            await request.Body.ReadAsync(buffer.AsMemory(0, buffer.Length)).ConfigureAwait(false);

            //We convert the byte[] into a string using UTF8 encoding...
            var bodyAsText = Encoding.UTF8.GetString(buffer);

            //..and finally, assign the read body back to the request body, which is allowed because of EnableBuffering()
            request.Body = body;
            var user = string.Empty;

            if (claims.IsAuthenticated)
            {
                user = claims.Session.UserName;
            }

            return($"[{user}] - {request.Scheme} {request.Host}{request.Path} {request.QueryString} {bodyAsText}");
        }
Exemple #2
0
 public AppUserNotAuthorizedException(IClaims <AppUser> claims, AppRoleEnum requiredRole)
 {
     Claims        = claims;
     RequiredRoles = new List <AppRoleEnum> {
         requiredRole
     };
 }
        public YmsApiHttpHandler(HttpClient httpClient, IClaims claims)
        {
            if (claims.IsAuthenticated)
            {
                this.token = claims.Session.Extras[Constants.JwtTokenName].ToString();
            }

            this.httpClient = httpClient;
        }
Exemple #4
0
 public CreateIssuerChargeback(ITransactionRepository iTransactionData,
                               ITransactions iTransactions,
                               IClaims iClaims,
                               IChargebacks iChargebacks)
 {
     _iTransactionData = iTransactionData;
     _iTransactions    = iTransactions;
     _iClaims          = iClaims;
     _iChargebacks     = iChargebacks;
 }
 public async Task Invoke(HttpContext httpContext, IClaims claims)
 {
     if (httpContext.User.Identity.IsAuthenticated)
     {
         claims.IsAuthenticated = true;
         claims.Session         = new UserSessionData
         {
             Id          = Guid.Parse(httpContext.User.Claims.First(i => i.Type == ClaimTypes.NameIdentifier).Value),
             UserName    = httpContext.User.Claims.First(i => i.Type == ClaimTypes.Name).Value,
             DisplayName = httpContext.User.Claims.First(i => i.Type == ClaimTypes.GivenName).Value
         };
     }
     await next(httpContext);
 }
Exemple #6
0
        private async Task <object> ExecuteAsync(IMessage message)
        {
            using (var unitOfWork = unitOfWorkFactory.NewUnitOfWork())
            {
                unitOfWork.Resolve <IClaimsWriter>().SetClaims(claims);;
                var messagebus = unitOfWork.Resolve <IMessageBus>();
                var response   = await messagebus.ExecuteAsync(message);

                var newClaims = browserclaimsProvider.OnResponse(response);
                if (newClaims != null)
                {
                    this.claims = newClaims;
                }
                return(response);
            }
        }
 public async Task Invoke(HttpContext httpContext, IClaims claims)
 {
     if (httpContext.User.Identity.IsAuthenticated)
     {
         claims.IsAuthenticated = true;
         claims.Session         = new UserSessionData
         {
             Id          = Guid.Parse(httpContext.User.Claims.First(i => i.Type == ClaimTypes.NameIdentifier).Value),
             UserName    = httpContext.User.Claims.First(i => i.Type == ClaimTypes.Name).Value,
             DisplayName = httpContext.User.Claims.First(i => i.Type == ClaimTypes.GivenName).Value
         };
         claims.Session.Extras = new Dictionary <string, object>
         {
             { Constants.JwtTokenName, httpContext.User.Claims.First(i => i.Type == Constants.JwtTokenName).Value }
         };
     }
     await next(httpContext);
 }
        public async Task Invoke(HttpContext context, IClaims claims)
        {
            //First, get the incoming request
            var request = await FormatRequest(context.Request, claims);

            //Copy a pointer to the original response body stream
            var originalBodyStream = context.Response.Body;

            //Create a new memory stream...
            using var responseBody = new MemoryStream();
            //...and use that for the temporary response body
            context.Response.Body = responseBody;

            //Continue down the Middleware pipeline, eventually returning to this class
            await _next(context);

            //Format the response from the server
            var response = await FormatResponse(context.Response);

            //TODO: Save log to chosen datastore

            //Copy the contents of the new memory stream (which contains the response) to the original stream, which is then returned to the client.
            await responseBody.CopyToAsync(originalBodyStream);
        }
 /// <summary>
 /// Constructor   : EmployeeResignationBLL
 /// Author        : Khushboo Patel
 /// Creation Date : 17 October 2019
 /// Purpose       : To resolve the dependency
 /// <param name="employeeResignation"> EmployeeResignation</param>
 /// <param name="calculations"> Calculations</param>
 public EmployeeResignationBLL(IEmployeeResignationDAL employeeResignation, ICalculations calculations, IClaims claims)
 {
     _employeeResignation = employeeResignation;
     _calculations        = calculations;
     _claims = claims;
 }
 public static AppUserAuthorizeInput <T> Create(IClaims <AppUser> claims, T data)
 {
     return(new AppUserAuthorizeInput <T> {
         Claims = claims, Data = data
     });
 }
 public SubCategoryService(YmsDbContext context, IClaims claims, ICacheManager cacheManager)
 {
     this.context      = context;
     this.claims       = claims;
     this.cacheManager = cacheManager;
 }
 public Users_Connexion_Page_SeConnecter_Reponse(IClaims claims)
 {
     this.claims = claims;
 }
Exemple #13
0
 public ProxySecurity(IClaims user)
 {
     _user = user;
 }
 /// <summary>
 /// Constructor   : ApprovalResignationBLL
 /// Author        : Binal Patel
 /// Creation Date : 17 October 2019
 /// Purpose       : To resolve the dependency
 /// </summary>
 /// <param name="approvalResignationDAL">ApprovalResignationDAL</param>
 /// <param name="calculations">Calculations</param>
 /// <param name="claims">Claims</param>
 public ApprovalResignationBLL(IApprovalResignationDAL approvalResignationDAL, ICalculations calculations, IClaims claims)
 {
     _approvalResignationDAL = approvalResignationDAL;
     _calculations           = calculations;
     _claims = claims;
 }
Exemple #15
0
 public OrderController(IYmsApiHttpHandler httpHandler, IClaims claims, IConfiguration configuration)
 {
     this.httpHandler   = httpHandler;
     this.claims        = claims;
     this.configuration = configuration;
 }
 public ClaimsController(IClaims iClaims)
 {
     _iClaims = iClaims;
 }
Exemple #17
0
 public DocumentService(DbContext context, IClaims claims)
 {
     this.context = context;
     this.claims  = claims;
 }
Exemple #18
0
 public async Task <ClaimsPrincipal> SignInAsync(HttpContext context, string identityToken, IClaims claims)
 {
     return(await SignInAsync(context, identityToken, claims.Claims));
 }
Exemple #19
0
 public FormInscriptionResponse(IClaims claims)
 {
     this.claims = claims;
 }
Exemple #20
0
 public AppUserNotAuthorizedException(IClaims <AppUser> claims, IEnumerable <AppRoleEnum> requiredRoles)
 {
     Claims        = claims;
     RequiredRoles = requiredRoles;
 }
Exemple #21
0
 public CartController(ICartService service, IClaims claims)
 {
     this.service = service;
     this.claims  = claims;
 }
Exemple #22
0
 public void SetClaims(IClaims claims)
 {
     this.claims = claims;
 }
Exemple #23
0
 public ClaimUI(IClaims console)
 {
     _console = console;
 }