private async Task <byte[]> ReadAndValidateContentFromGitHubAsync(GitHubRule rule, HttpRequest request) { var payloadContent = await ReadAndValidateContentFromGenericAsync(rule, request); var secret = await GetSecretAsync(rule.WebhookSecret); var signature = request.Headers[GitHubWebhookSignatureValidator.GitHubWebhookSignatureHeader]; bool isValid = GitHubWebhookSignatureValidator.IsValid(payloadContent, signature, secret); return(payloadContent); }
private async Task <Payload> CreateAndValidatePayloadAsync(Rule rule, HttpRequest request) { var payloadContent = rule switch { GitHubRule gitHubRule => await ReadAndValidateContentFromGitHubAsync(gitHubRule, request), AzureDevOpsRule azureDevopsRule => await ReadAndValidateContentFromAzureDevOpsAsync(azureDevopsRule, request), _ => await ReadAndValidateContentFromGenericAsync(rule, request) }; var payload = new Payload(request.Headers, payloadContent); return(payload); }
private async Task <byte[]> ReadAndValidateContentFromGitHubAsync(GitHubRule rule, HttpRequest request) { var payloadContent = await ReadAndValidateContentFromGenericAsync(rule, request); var secret = await GetSecretAsync(rule.WebhookSecret); var signature = request.Headers[GitHubWebhookSignatureValidator.GitHubWebhookSignatureHeader]; bool isValid = GitHubWebhookSignatureValidator.IsValid(payloadContent, signature, secret); if (!isValid) { throw new RouterAuthorizationException("Signature validation failed."); } return(payloadContent); }