Example #1
0
        public async Task <bool> IsAuthenticated(HttpRequestMessage request)
        {
            if ((request.Headers.Authorization == null) || (!request.Headers.Contains(HeaderNames.UsernameHeader)))
            {
                return(false);
            }

            var secret = getSecretFromUsername.Secret(request.Headers.GetValues(HeaderNames.UsernameHeader).FirstOrDefault());

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

            if ((request.Content != null) && (request.Content.Headers.ContentMD5 != null))
            {
                var isValidHash = await hashCalculator.IsValidHash(request);

                if (!isValidHash)
                {
                    return(false);
                }
            }

            var signature = buildRequestSignature.Build(secret, request);

            if (signature != request.Headers.Authorization.Parameter)
            {
                return(false);
            }

            return(true);
        }
Example #2
0
 public static HttpClient Create(string username, IGetSecretFromUsername getSecretFromUsername)
 {
     return(Create(username, getSecretFromUsername.Secret(username)));
 }