/// <summary> /// Ensures that the provided <paramref name="webHook"/> has a reachable Web Hook URI unless /// the WebHook URI has a <c>NoEcho</c> query parameter. /// </summary> private async Task VerifyWebHook(WebHook webHook) { if (webHook == null) { throw new ArgumentNullException(nameof(webHook)); } // If no secret is provided then we create one here. This allows for scenarios // where the caller may use a secret directly embedded in the WebHook URI, or // has some other way of enforcing security. if (string.IsNullOrEmpty(webHook.Secret)) { webHook.Secret = Guid.NewGuid().ToString("N"); } try { await _manager.VerifyWebHookAsync(webHook); } catch (Exception ex) { HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message, ex); throw new HttpResponseException(error); } }
/// <summary> /// Verifies the <see cref="WebHook.WebHookUri"/> by issuing an HTTP GET request to the provided /// <paramref name="webHook"/> to ensure that it is reachable and expects WebHooks. The WebHook /// validation response is expected to echo the contents of the <c>echo</c> query parameter unless /// the WebHook URI has a <c>NoEcho</c> query parameter. /// </summary> /// <param name="webHook">The <see cref="WebHook"/> to verify.</param> public virtual async Task VerifyAddressAsync(WebHook webHook) { if (webHook == null) { throw new ArgumentNullException(nameof(webHook)); } await _manager.VerifyWebHookAsync(webHook); }
public async Task <IActionResult> Post([FromBody] WebHook webHook) { if (webHook == null) { throw new ArgumentNullException("webHook"); } string userId = User.Identity.Name; await VerifyFilters(webHook); try { // Validate the WebHook is Active (using echo) await _manager.VerifyWebHookAsync(webHook); // Validate the provided WebHook ID (or force one to be created on server side) IWebHookIdValidator idValidator = (IWebHookIdValidator)HttpContext.RequestServices.GetService(typeof(IWebHookIdValidator)); if (idValidator == null) { idValidator = new DefaultWebHookIdValidator(); } await idValidator.ValidateIdAsync(Request, webHook); // Add WebHook for this user. StoreResult result = await _store.InsertWebHookAsync(userId, webHook); if (result == StoreResult.Success) { return(CreatedAtRoute(WebHookRouteNames.RegistrationLookupAction, new { id = webHook.Id }, webHook)); } return(CreateResultFromStoreResult(result)); } catch (Exception ex) { string msg = string.Format(CustomApiResource.RegistrationController_RegistrationFailure, ex.Message); _logger.LogError(msg); return(StatusCode(StatusCodes.Status500InternalServerError, msg)); } }
/// <summary> /// Ensures that the provided <paramref name="webHook"/> has a reachable Web Hook URI. /// </summary> protected virtual async Task VerifyWebHook(WebHook webHook) { if (webHook == null) { throw new ArgumentNullException("webHook"); } try { await _manager.VerifyWebHookAsync(webHook); } catch (Exception ex) { HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message, ex); throw new HttpResponseException(error); } }
static void Main(string[] args) { _whStore = new MemoryWebHookStore(); _whManager = new WebHookManager(_whStore, new MyWebHookSender(new TraceLogger()), new TraceLogger()); //Alloy site URL string receiverUrl = "http://localhost:50028"; //Subscribe alloy site in Memory of server var wh = SubscribeNewUser(receiverUrl); // Send Notification to all subscribers SendWebhookAsync("alloy-plan", "Alloy Plan").Wait(); //verify the webhook var verify = _whManager.VerifyWebHookAsync(wh); Console.ReadLine(); }
static void Main(string[] args) { _whStore = new MemoryWebHookStore(); _whManager = new WebHookManager(_whStore, new TraceLogger()); //Alloy site URL string receiverUrl = "http://localhost:51481"; //Subscribe alloy site in Memory of server var wh = SubscribeNewUser(receiverUrl); // Send Notification to all subscribers SendWebhookAsync("alloy-plan", "Alloy Plan").Wait(); //verify the webhook var verify = _whManager.VerifyWebHookAsync(wh); Console.ReadLine(); }
/// <summary> /// Ensures that the provided <paramref name="webHook"/> has a reachable Web Hook URI unless /// the WebHook URI has a <c>NoEcho</c> query parameter. /// </summary> private async Task VerifyWebHook(WebHook webHook) { if (webHook == null) { throw new ArgumentNullException(nameof(webHook)); } if (string.IsNullOrEmpty(webHook.Secret)) { webHook.Secret = Guid.NewGuid().ToString("N"); } try { await _manager.VerifyWebHookAsync(webHook); } catch (Exception ex) { throw new VerificationException(ex.Message); } }
public async Task <ActionResult <WebhookSendResponse> > Run([FromBody] Webhook webHook) { var result = await _webHookManager.VerifyWebHookAsync(webHook); return(Ok(result)); }