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); }
public static HttpClient Create(string username, IGetSecretFromUsername getSecretFromUsername) { return(Create(username, getSecretFromUsername.Secret(username))); }