예제 #1
0
        public async Task <ConfirmSubscriptionResponse> ConfirmSubscription(string token)
        {
            var req = new ConfirmSubscriptionRequest();

            req.TopicArn = arn;
            req.Token    = token;

            return(await snsClient.ConfirmSubscriptionAsync(req));
        }
        public async Task <IActionResult> Webhook()
        {
            string  payload        = await new StreamReader(Request.Body).ReadToEndAsync();
            Message confirmMessage = Message.ParseMessage(payload.ToString());

            if (Request.Headers.TryGetValue(_headerSection, out StringValues value))
            {
                switch (value.ToString())
                {
                case Message.MESSAGE_TYPE_SUBSCRIPTION_CONFIRMATION:
                {
                    _logger.LogInformation("****AWS SNS Webhook Confirmation****");
                    _logger.LogInformation($"Confirming subscription with Token: {confirmMessage.Token} and TopicArn: {confirmMessage.TopicArn}");
                    var result = await _snsClient.ConfirmSubscriptionAsync(new ConfirmSubscriptionRequest
                        {
                            Token    = confirmMessage.Token,
                            TopicArn = confirmMessage.TopicArn
                        });

                    _logger.LogInformation($"Confirmation result: {(int)result.HttpStatusCode}");
                    if (result.HttpStatusCode == HttpStatusCode.OK)
                    {
                        return(Ok());
                    }
                    return(BadRequest());
                }

                case Message.MESSAGE_TYPE_NOTIFICATION:
                {
                    _logger.LogInformation($"****Receiving webhook event from AWS SNS****");
                    _logger.LogInformation("\nFull request payload:");
                    _logger.LogInformation(JsonConvert.SerializeObject(confirmMessage, Formatting.Indented));
                    EventMessage eventMessage = JsonConvert.DeserializeObject <EventMessage>(confirmMessage.MessageText);
                    if (eventMessage != null)
                    {
                        Console.WriteLine("\nCore payload:");
                        Console.WriteLine($">>>      Event Id: {eventMessage.Id}");
                        Console.WriteLine($">>>       Message: {eventMessage.Message}");
                        Console.WriteLine($">>> Timestamp Utc: {eventMessage.TimestampUtc}");
                    }
                    return(Ok());
                }

                case Message.MESSAGE_TYPE_UNSUBSCRIPTION_CONFIRMATION:
                {
                    //to-be implemented!
                    break;
                }
                }
            }
            _logger.LogError($"Header `{_headerSection}` not found");
            return(BadRequest(new
            {
                message = $"Header `{_headerSection}` not found"
            }));
        }
예제 #3
0
 private Amazon.SimpleNotificationService.Model.ConfirmSubscriptionResponse CallAWSServiceOperation(IAmazonSimpleNotificationService client, Amazon.SimpleNotificationService.Model.ConfirmSubscriptionRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Notification Service (SNS)", "ConfirmSubscription");
     try
     {
         #if DESKTOP
         return(client.ConfirmSubscription(request));
         #elif CORECLR
         return(client.ConfirmSubscriptionAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
예제 #4
0
        private Task <ConfirmSubscriptionResponse[]> SubscribeToTopic(CreateTopicResponse topicResponse, string protocol,
                                                                      IEnumerable <string> endpoints)
        {
            var subscriptionConfirmationResponses = endpoints
                                                    .Select(endpoint => new SubscribeRequest(topicResponse.TopicArn, protocol, endpoint))
                                                    .Select(subscribeRequest => _snsClient.SubscribeAsync(subscribeRequest)
                                                            .ContinueWith(subscribeResponse => _snsClient.ConfirmSubscriptionAsync(topicResponse.TopicArn, subscribeResponse.Result.SubscriptionArn)).Result);

            return(Task.WhenAll(subscriptionConfirmationResponses.ToArray()));
        }