-
Notifications
You must be signed in to change notification settings - Fork 177
/
ValidationHelper.cs
29 lines (24 loc) · 1.24 KB
/
ValidationHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System.Threading.Tasks;
using Alexa.NET.Request;
using Bot.Builder.Community.Adapters.Alexa.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Bot.Builder.Community.Adapters.Alexa
{
internal class ValidationHelper
{
public static async Task<bool> ValidateRequest(HttpRequest request, SkillRequest skillRequest, string body, string alexaSkillId, ILogger logger)
{
request.Headers.TryGetValue(AlexaAuthorizationHandler.SignatureCertChainUrlHeader, out var signatureChainUrls);
request.Headers.TryGetValue(AlexaAuthorizationHandler.SignatureHeader, out var signatureHeaders);
var validator = new AlexaAuthorizationHandler(logger);
if (!await validator.ValidateSkillRequest(skillRequest, body, signatureChainUrls, signatureHeaders).ConfigureAwait(false))
return false;
// Alexa recommends you verify the Skill Id. Some bot developers use the same bot to service multiple skills. In this case they do their own validation
// and set this value to null.
if (alexaSkillId == null)
return true;
return validator.ValidateSkillId(skillRequest, alexaSkillId);
}
}
}