protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                CancellationToken cancellationToken)
        {
            //add email header
            if (!request.Headers.Contains(Configuration.HeaderSignatureName))
            {
                request.Headers.Add(Configuration.HeaderSignatureName, Email);
            }

            //set DateTime request header
            request.Headers.Date = new DateTimeOffset(DateTime.Now, DateTime.Now - DateTime.UtcNow);

            //create CanonicalRequest
            var canonicalRequest = _createCanonicalRequest.CreateCanonicalRequest(request);

            //Generate accessToken(password hash) with mail
            var accessToken = _userRepository.GenerateAccessTokenUser(Email);

            ///Calculate Signature HMACSHA256
            string signature = _calculSignature.Signature(accessToken, canonicalRequest);

            //create  AuthenticationHeaderValue with shema and signature Authorization = VPS-HMAC-SHA256 signature
            var header = new AuthenticationHeaderValue(Configuration.Schema, signature);

            //Authorization = VPS-HMAC-SHA256 signature
            request.Headers.Authorization = header;

            //send request
            return(base.SendAsync(request, cancellationToken));
        }
        public bool IsAuthenticated(HttpRequestMessage requestMessage)
        {
            if (!requestMessage.Headers.Contains(Configuration.HeaderSignatureName) ||
                !requestMessage.Headers.Date.HasValue ||
                requestMessage.Headers.Authorization == null ||
                requestMessage.Headers.Authorization.Scheme != Configuration.Schema
                )
            {
                return(false);
            }


            //AccessToken= mail passed in the header
            string mail = requestMessage.Headers.GetValues(Configuration.HeaderSignatureName)
                          .First();
            var accessToken = _userRepository.GenerateAccessTokenUser(mail);

            if (accessToken == null)
            {
                return(false);
            }

            //test if the date is valid
            if (!IsDateOk(requestMessage))
            {
                return(false);
            }

            //create CanonicalRequest
            var canonicalRequest = _createCanonicalRequest.CreateCanonicalRequest(requestMessage);

            if (canonicalRequest == null)
            {
                return(false);
            }


            var signature = _calculSignature.Signature(accessToken, canonicalRequest);

            //check if the signature is the same as signature calculated
            return(requestMessage.Headers.Authorization.Parameter == signature);
        }